From 4242e4d3b18eb532ae18e8b38e85ad1ee1988e02 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 15 May 2018 19:52:04 -0400 Subject: - Migrated primitive analysis to stdlib. --- stdlib/test/test/lux/lang/analysis/primitive.lux | 63 ++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 stdlib/test/test/lux/lang/analysis/primitive.lux (limited to 'stdlib/test') diff --git a/stdlib/test/test/lux/lang/analysis/primitive.lux b/stdlib/test/test/lux/lang/analysis/primitive.lux new file mode 100644 index 000000000..2e7c2057a --- /dev/null +++ b/stdlib/test/test/lux/lang/analysis/primitive.lux @@ -0,0 +1,63 @@ +(.module: + lux + (lux [io] + (control [monad #+ do] + pipe + ["ex" exception #+ exception:]) + (data (text format) + ["e" error]) + ["r" math/random] + [macro] + (macro [code]) + (lang [".L" type "type/" Eq] + [".L" init] + [analysis #+ Analysis] + (analysis [".A" type] + ["/" primitive])) + test)) + +(exception: (wrong-inference {expected Type} {inferred Type}) + (format "Expected: " (%type expected) "\n" + "Inferred: " (%type inferred) "\n")) + +(def: (infer-primitive expected-type analysis) + (-> Type (Meta Analysis) (e.Error Analysis)) + (|> (typeA.with-inference + analysis) + (macro.run (initL.compiler [])) + (case> (#e.Success [inferred-type output]) + (if (is? expected-type inferred-type) + (#e.Success output) + (ex.throw wrong-inference [expected-type inferred-type])) + + (#e.Error error) + (#e.Error error)))) + +(context: "Primitives" + (<| (times +100) + (`` ($_ seq + (test "Can analyse unit." + (|> (infer-primitive Top /.unit) + (case> (^ (#e.Success (#analysis.Primitive (#analysis.Unit output)))) + (is? [] output) + + _ + false))) + (~~ (do-template [ ] + [(do @ + [sample ] + (test (format "Can analyse " ".") + (|> (infer-primitive ( sample)) + (case> (#e.Success (#analysis.Primitive ( output))) + (is? sample output) + + _ + false))))] + + ["bool" Bool #analysis.Bool r.bool /.bool] + ["nat" Nat #analysis.Nat r.nat /.nat] + ["int" Int #analysis.Int r.int /.int] + ["deg" Deg #analysis.Deg r.deg /.deg] + ["frac" Frac #analysis.Frac r.frac /.frac] + ["text" Text #analysis.Text (r.unicode +5) /.text] + )))))) -- cgit v1.2.3