diff options
Diffstat (limited to 'stdlib/source/test/lux/tool/compiler/phase/synthesis/primitive.lux')
-rw-r--r-- | stdlib/source/test/lux/tool/compiler/phase/synthesis/primitive.lux | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/tool/compiler/phase/synthesis/primitive.lux b/stdlib/source/test/lux/tool/compiler/phase/synthesis/primitive.lux new file mode 100644 index 000000000..d5683b14f --- /dev/null +++ b/stdlib/source/test/lux/tool/compiler/phase/synthesis/primitive.lux @@ -0,0 +1,81 @@ +(.module: + [lux (#- primitive) + [abstract ["." monad (#+ do)]] + [data + text/format + ["." name]] + ["r" math/random (#+ Random) ("#@." monad)] + ["_" test (#+ Test)] + [control + pipe] + [data + ["." error]]] + {1 + ["." / #_ + ["/#" // + ["/#" // + [extension + ["#." bundle]] + ["/#" // + ["#." analysis (#+ Analysis)] + ["#." synthesis (#+ Synthesis)]]]]]}) + +(def: #export primitive + (Random Analysis) + (do r.monad + [primitive (: (Random ////analysis.Primitive) + ($_ r.or + (wrap []) + r.bit + r.nat + r.int + r.rev + r.frac + (r.unicode 5)))] + (wrap (#////analysis.Primitive primitive)))) + +(def: #export (corresponds? analysis synthesis) + (-> Analysis Synthesis Bit) + (`` (case [analysis synthesis] + (~~ (template [<analysis> <post-analysis> <synthesis> <post-synthesis>] + [[(#////analysis.Primitive (<analysis> expected)) + (#////synthesis.Primitive (<synthesis> actual))] + (is? (|> expected <post-analysis>) + (|> actual <post-synthesis>))] + + [#////analysis.Unit (:coerce Text) #////synthesis.Text (|>)] + [#////analysis.Bit (|>) #////synthesis.Bit (|>)] + [#////analysis.Nat .i64 #////synthesis.I64 .i64] + [#////analysis.Int .i64 #////synthesis.I64 .i64] + [#////analysis.Rev .i64 #////synthesis.I64 .i64] + [#////analysis.Frac (|>) #////synthesis.F64 (|>)] + [#////analysis.Text (|>) #////synthesis.Text (|>)] + )) + + _ + false))) + +(def: #export test + Test + (<| (_.context (%name (name-of #////synthesis.Primitive))) + (`` ($_ _.and + (~~ (template [<analysis> <synthesis> <generator>] + [(do r.monad + [expected <generator>] + (_.test (%name (name-of <synthesis>)) + (|> (#////analysis.Primitive (<analysis> expected)) + //.phase + (///.run [///bundle.empty ////synthesis.init]) + (case> (#error.Success (#////synthesis.Primitive (<synthesis> actual))) + (is? expected actual) + + _ + false))))] + + [#////analysis.Unit #////synthesis.Text (r@wrap ////synthesis.unit)] + [#////analysis.Bit #////synthesis.Bit r.bit] + [#////analysis.Nat #////synthesis.I64 (r@map .i64 r.nat)] + [#////analysis.Int #////synthesis.I64 (r@map .i64 r.int)] + [#////analysis.Rev #////synthesis.I64 (r@map .i64 r.rev)] + [#////analysis.Frac #////synthesis.F64 r.frac] + [#////analysis.Text #////synthesis.Text (r.unicode 5)])))))) |