diff options
author | Eduardo Julian | 2020-03-04 00:38:54 -0400 |
---|---|---|
committer | Eduardo Julian | 2020-03-04 00:38:54 -0400 |
commit | 21777826feb4affa53bf150588b70fc11bb92512 (patch) | |
tree | 837f1a0b496b03c099994a0a0c96ee6c49e57733 /stdlib/source/test | |
parent | a7b921974b5318c4344d28092519566424675f02 (diff) |
Test for codec composition + adjustments to JS-generation code.
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/lux/abstract.lux | 2 | ||||
-rw-r--r-- | stdlib/source/test/lux/abstract/codec.lux | 36 | ||||
-rw-r--r-- | stdlib/source/test/lux/extension.lux | 14 |
3 files changed, 45 insertions, 7 deletions
diff --git a/stdlib/source/test/lux/abstract.lux b/stdlib/source/test/lux/abstract.lux index 4d37ed458..cbc89fce9 100644 --- a/stdlib/source/test/lux/abstract.lux +++ b/stdlib/source/test/lux/abstract.lux @@ -2,10 +2,12 @@ [lux #* ["_" test (#+ Test)]] ["." / #_ + ["#." codec] ["#." interval]]) (def: #export test Test ($_ _.and + /codec.test /interval.test )) diff --git a/stdlib/source/test/lux/abstract/codec.lux b/stdlib/source/test/lux/abstract/codec.lux index b6bbdd91e..84a3997b3 100644 --- a/stdlib/source/test/lux/abstract/codec.lux +++ b/stdlib/source/test/lux/abstract/codec.lux @@ -5,7 +5,12 @@ [control ["." try]] [data - ["%" text/format (#+ format)]] + ["." bit ("#@." equivalence)] + ["%" text/format (#+ format)] + [format + ["." json (#+ JSON)]] + [collection + [dictionary]]] [math ["r" random (#+ Random)]]] {1 @@ -13,6 +18,35 @@ [// [equivalence (#+ Equivalence)]]]}) +(def: json + (Codec JSON Bit) + (let [field "value"] + (structure + (def: encode + (|>> #json.Boolean + [field] + list + (json.object))) + (def: decode + (json.get-boolean field))))) + +(def: codec + (Codec Text Bit) + (/.compose json.codec ..json)) + +(def: #export test + Test + (do r.monad + [expected r.bit] + (<| (_.context (%.name (name-of /.Codec))) + (_.test "Composition." + (case (|> expected (:: ..codec encode) (:: ..codec decode)) + (#try.Success actual) + (bit@= expected actual) + + (#try.Failure error) + false))))) + (def: #export (spec (^open "/@.") (^open "/@.") generator) (All [m a] (-> (Equivalence a) (Codec m a) (Random a) Test)) (do r.monad diff --git a/stdlib/source/test/lux/extension.lux b/stdlib/source/test/lux/extension.lux index 23c33c620..6160294c4 100644 --- a/stdlib/source/test/lux/extension.lux +++ b/stdlib/source/test/lux/extension.lux @@ -14,12 +14,14 @@ ["%" format (#+ format)]]] [tool [compiler - ["." analysis] - ["." synthesis] - ["." directive] - [phase - [analysis - ["." type]]]]] + [language + [lux + ["." analysis] + ["." synthesis] + ["." directive] + [phase + [analysis + ["." type]]]]]]] ["_" test (#+ Test)]] {1 ["." / (#+ analysis: synthesis: generation: directive:)]}) |