diff options
Diffstat (limited to 'stdlib/source/test/lux/type/poly/json.lux')
-rw-r--r-- | stdlib/source/test/lux/type/poly/json.lux | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/type/poly/json.lux b/stdlib/source/test/lux/type/poly/json.lux new file mode 100644 index 000000000..16a466ed5 --- /dev/null +++ b/stdlib/source/test/lux/type/poly/json.lux @@ -0,0 +1,117 @@ +(.module: + [library + [lux (#- Variant) + ["_" test (#+ Test)] + ["." debug] + [abstract + codec + [monad (#+ do)] + ["." equivalence (#+ Equivalence) + ["poly/#" \\poly]] + [\\specification + ["$." equivalence] + ["$." codec]]] + [control + pipe + ["." try] + ["p" parser + ... TODO: Get rid of this import ASAP + [json (#+)]]] + [data + ["." bit] + ["." text] + [format + [json (#+) + [\\poly + ["." /]]]] + [collection + [row (#+ row)] + ["d" dictionary] + ["." list]]] + [type + [poly (#+ derived:)] + ["." unit]] + [math + ["." random (#+ Random)] + [number + ["n" nat] + ["." frac]]] + [time + ["ti" instant] + ["tda" date] + ... ["tdu" duration] + ]]] + [test + [lux + [time + ["_." instant] + ... ["_." duration] + ]]]) + +(type: Variant + (#Bit Bit) + (#Text Text) + (#Frac Frac)) + +(type: #rec Recursive + (#Number Frac) + (#Addition Frac Recursive)) + +(type: Record + {#bit Bit + #frac Frac + #text Text + #maybe (Maybe Frac) + #list (List Frac) + #dictionary (d.Dictionary Text Frac) + #variant Variant + #tuple [Bit Text Frac] + #recursive Recursive + ... #instant ti.Instant + ... #duration tdu.Duration + #date tda.Date + #grams (unit.Qty unit.Gram)}) + +(def: gen_recursive + (Random Recursive) + (random.rec + (function (_ gen_recursive) + (random.or random.safe_frac + (random.and random.safe_frac + gen_recursive))))) + +(def: qty + (All [unit] (Random (unit.Qty unit))) + (\ random.monad map (debug.private unit.in) random.int)) + +(def: gen_record + (Random Record) + (do {! random.monad} + [size (\ ! map (n.% 2) random.nat)] + ($_ random.and + random.bit + random.safe_frac + (random.unicode size) + (random.maybe random.safe_frac) + (random.list size random.safe_frac) + (random.dictionary text.hash size (random.unicode size) random.safe_frac) + ($_ random.or random.bit (random.unicode size) random.safe_frac) + ($_ random.and random.bit (random.unicode size) random.safe_frac) + ..gen_recursive + ... _instant.instant + ... _duration.duration + random.date + ..qty + ))) + +(derived: equivalence + (poly/equivalence.equivalence Record)) + +(derived: codec + (/.codec Record)) + +(def: .public test + Test + (<| (_.covering /._) + (_.for [/.codec] + ($codec.spec ..equivalence ..codec ..gen_record)))) |