diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/test/lux/extension.lux | 11 | ||||
-rw-r--r-- | stdlib/source/test/lux/static.lux | 136 | ||||
-rw-r--r-- | stdlib/source/test/lux/target/ruby.lux | 38 | ||||
-rw-r--r-- | stdlib/source/test/lux/tool/compiler/language/lux/analysis.lux | 2 | ||||
-rw-r--r-- | stdlib/source/test/lux/tool/compiler/language/lux/analysis/type.lux | 119 | ||||
-rw-r--r-- | stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/simple.lux | 25 |
6 files changed, 244 insertions, 87 deletions
diff --git a/stdlib/source/test/lux/extension.lux b/stdlib/source/test/lux/extension.lux index 5537bc855..a7b2afa6f 100644 --- a/stdlib/source/test/lux/extension.lux +++ b/stdlib/source/test/lux/extension.lux @@ -47,13 +47,12 @@ ["[0]" artifact]]] [language [lux - ["[0]" analysis] ["[0]" synthesis] ["[0]" generation] ["[0]" directive] + ["[0]" analysis + ["[0]" type]] [phase - [analysis - ["[0]" type]] [generation (~~ (.for ["JVM" (~~ (.as_is ["[0]" jvm "_" ["[1]/[0]" runtime]]))] @@ -141,9 +140,9 @@ (directive: (..directive self phase archive [expression <code>.any]) (do [! phase.monad] [analysis_phase directive.analysis - expressionA (directive.lifted_analysis - (type.with_type .Any - (analysis_phase archive expression))) + expressionA (<| directive.lifted_analysis + (type.expecting .Any) + (analysis_phase archive expression)) synthesis_phase directive.synthesis expressionS (directive.lifted_synthesis diff --git a/stdlib/source/test/lux/static.lux b/stdlib/source/test/lux/static.lux index cec292c79..c8425f21d 100644 --- a/stdlib/source/test/lux/static.lux +++ b/stdlib/source/test/lux/static.lux @@ -1,78 +1,78 @@ (.using - [library - [lux "*" - ["_" test {"+" Test}] - ["@" target] - ["[0]" meta] - [data - ["[0]" text ("[1]#[0]" equivalence) - ["%" format {"+" format}]]] - [macro - ["[0]" code]] - [math - ["[0]" random] - [number - ["n" nat] - ["i" int] - ["r" rev] - ["f" frac]]]]] - [\\library - ["[0]" /]]) + [library + [lux "*" + ["_" test {"+" Test}] + ["@" target] + ["[0]" meta] + [data + ["[0]" text ("[1]#[0]" equivalence) + ["%" format {"+" format}]]] + [macro + ["[0]" code]] + [math + ["[0]" random] + [number + ["n" nat] + ["i" int] + ["r" rev] + ["f" frac]]]]] + [\\library + ["[0]" /]]) (def: .public test Test (<| (_.covering /._) - (for [@.old (_.test "PLACEHOLDER" true)] - (_.for [meta.eval] - (`` ($_ _.and - (~~ (template [<static> <random> <=> <+> <tag>] - [(_.cover [<static> <random>] - (with_expansions [<left> (<random>) - <right> (<random>) - <l+r> (<static> (<+> <left> <right>))] - (case (' <l+r>) - [_ {<tag> l+r}] - (<=> l+r (<+> <left> <right>)) + (for [@.old (_.test "PLACEHOLDER" true)]) + (_.for [meta.eval]) + (`` ($_ _.and + (~~ (template [<static> <random> <=> <+> <tag>] + [(_.cover [<static> <random>] + (with_expansions [<left> (<random>) + <right> (<random>) + <l+r> (<static> (<+> <left> <right>))] + (case (' <l+r>) + [_ {<tag> l+r}] + (<=> l+r (<+> <left> <right>)) - _ - false)))] + _ + false)))] - [/.nat /.random_nat n.= n.+ .#Nat] - [/.int /.random_int i.= i.+ .#Int] - [/.rev /.random_rev r.= r.+ .#Rev] - )) - (_.cover [/.frac /.random_frac] - (with_expansions [<left> (/.random_frac) - <right> (/.random_frac) - <l+r> (/.frac (f.+ <left> <right>))] - (case (' <l+r>) - [_ {.#Frac l+r}] - (or (f.= l+r (f.+ <left> <right>)) - (and (f.not_a_number? l+r) - (f.not_a_number? (f.+ <left> <right>)) - (or (f.not_a_number? <left>) - (f.not_a_number? <right>)))) + [/.nat /.random_nat n.= n.+ .#Nat] + [/.int /.random_int i.= i.+ .#Int] + [/.rev /.random_rev r.= r.+ .#Rev] + )) + (_.cover [/.frac /.random_frac] + (with_expansions [<left> (/.random_frac) + <right> (/.random_frac) + <l+r> (/.frac (f.+ <left> <right>))] + (case (' <l+r>) + [_ {.#Frac l+r}] + (or (f.= l+r (f.+ <left> <right>)) + (and (f.not_a_number? l+r) + (f.not_a_number? (f.+ <left> <right>)) + (or (f.not_a_number? <left>) + (f.not_a_number? <right>)))) - _ - false))) - (_.cover [/.text /.random] - (with_expansions [<left> (/.random code.text (random.ascii/alpha_num 1)) - <right> (/.random code.text (random.ascii/alpha_num 1)) - <l+r> (/.text (format <left> <right>))] - (case (' <l+r>) - [_ {.#Text l+r}] - (text#= l+r (format <left> <right>)) + _ + false))) + (_.cover [/.text /.random] + (with_expansions [<left> (/.random code.text (random.ascii/alpha_num 1)) + <right> (/.random code.text (random.ascii/alpha_num 1)) + <l+r> (/.text (format <left> <right>))] + (case (' <l+r>) + [_ {.#Text l+r}] + (text#= l+r (format <left> <right>)) - _ - false))) - (_.cover [/.literal] - (with_expansions [<left> (/.random code.text (random.ascii/alpha_num 1)) - <right> (/.random code.text (random.ascii/alpha_num 1)) - <l+r> (/.literal code.text (format <left> <right>))] - (case (' <l+r>) - [_ {.#Text l+r}] - (text#= l+r (format <left> <right>)) + _ + false))) + (_.cover [/.literal] + (with_expansions [<left> (/.random code.text (random.ascii/alpha_num 1)) + <right> (/.random code.text (random.ascii/alpha_num 1)) + <l+r> (/.literal code.text (format <left> <right>))] + (case (' <l+r>) + [_ {.#Text l+r}] + (text#= l+r (format <left> <right>)) - _ - false))) - )))))) + _ + false))) + )))) diff --git a/stdlib/source/test/lux/target/ruby.lux b/stdlib/source/test/lux/target/ruby.lux index 7ec415b16..5a52dc1b8 100644 --- a/stdlib/source/test/lux/target/ruby.lux +++ b/stdlib/source/test/lux/target/ruby.lux @@ -298,6 +298,43 @@ (/.apply_lambda/* (list))))) ))) +(def: test|io + Test + (<| (do [! random.monad] + [left (random.ascii/upper 5) + right (random.ascii/upper 5) + $old (# ! each /.local (random.ascii/upper 1)) + $new (# ! each /.local (random.ascii/upper 2)) + .let [expected (format left right)]]) + (_.for [/.stdout]) + ($_ _.and + (_.cover [/.print/1] + (expression (|>> (:as Text) (text#= expected)) + (|> ($_ /.then + (/.statement (/.require/1 (/.string "stringio"))) + (/.set (list $old) /.stdout) + (/.set (list $new) (/.new (list) {.#None} (/.manual "StringIO"))) + (/.set (list /.stdout) $new) + (/.statement (/.print/1 (/.string left))) + (/.statement (/.print/1 (/.string right))) + (/.set (list /.stdout) $old) + (/.return (/.the "string" $new))) + [(list)] (/.lambda {.#None}) + (/.apply_lambda/* (list))))) + (_.cover [/.print/2] + (expression (|>> (:as Text) (text#= expected)) + (|> ($_ /.then + (/.statement (/.require/1 (/.string "stringio"))) + (/.set (list $old) /.stdout) + (/.set (list $new) (/.new (list) {.#None} (/.manual "StringIO"))) + (/.set (list /.stdout) $new) + (/.statement (/.print/2 (/.string left) (/.string right))) + (/.set (list /.stdout) $old) + (/.return (/.the "string" $new))) + [(list)] (/.lambda {.#None}) + (/.apply_lambda/* (list))))) + ))) + (def: test|computation Test (do [! random.monad] @@ -317,6 +354,7 @@ ..test|array ..test|hash ..test|object + ..test|io (_.cover [/.?] (let [expected (if test then else)] (expression (|>> (:as Frac) (f.= expected)) diff --git a/stdlib/source/test/lux/tool/compiler/language/lux/analysis.lux b/stdlib/source/test/lux/tool/compiler/language/lux/analysis.lux index c1bc9d62e..f19111e2d 100644 --- a/stdlib/source/test/lux/tool/compiler/language/lux/analysis.lux +++ b/stdlib/source/test/lux/tool/compiler/language/lux/analysis.lux @@ -28,6 +28,7 @@ ["[1][0]" complex] ["[1][0]" pattern] ["[1][0]" macro] + ["[1][0]" type] [//// ["[1][0]" reference ["[2][0]" variable]] @@ -438,4 +439,5 @@ /complex.test /pattern.test /macro.test + /type.test )))) diff --git a/stdlib/source/test/lux/tool/compiler/language/lux/analysis/type.lux b/stdlib/source/test/lux/tool/compiler/language/lux/analysis/type.lux new file mode 100644 index 000000000..66876be3c --- /dev/null +++ b/stdlib/source/test/lux/tool/compiler/language/lux/analysis/type.lux @@ -0,0 +1,119 @@ +(.using + [library + [lux "*" + ["_" test {"+" Test}] + ["[0]" meta] + [abstract + [monad {"+" do}] + [\\specification + ["$[0]" equivalence]]] + [control + [pipe {"+" case>}] + ["[0]" maybe ("[1]#[0]" functor)] + ["[0]" try ("[1]#[0]" functor)] + ["[0]" exception]] + [data + ["[0]" product] + ["[0]" bit ("[1]#[0]" equivalence)] + ["[0]" text ("[1]#[0]" equivalence)] + [collection + ["[0]" list ("[1]#[0]" monad)]]] + [macro + ["[0]" code ("[1]#[0]" equivalence)]] + [math + ["[0]" random {"+" Random} ("[1]#[0]" monad)] + [number + ["n" nat]]] + ["[0]" type ("[1]#[0]" equivalence) + ["[0]" check]]]] + ["$" /////// "_" + [macro + ["[1][0]" code]] + [meta + ["[1][0]" symbol]]] + [\\library + ["[0]" / + ["/[1]" // + [// + [phase + ["[2][0]" extension]] + [/// + ["[2][0]" phase]]]]]]) + +(def: random_state + (Random Lux) + (do random.monad + [version random.nat + host (random.ascii/lower 1)] + (in (//.state (//.info version host))))) + +(def: primitive + (Random Type) + (do random.monad + [name (random.ascii/lower 1)] + (in {.#Primitive name (list)}))) + +(def: .public test + Test + (<| (_.covering /._) + (do [! random.monad] + [lux ..random_state + .let [state [/extension.#bundle /extension.empty + /extension.#state lux]] + expected ..primitive + dummy (random.only (|>> (type#= expected) not) + ..primitive)] + ($_ _.and + (_.cover [/.expecting /.inference] + (and (|> (/.inference expected) + (/.expecting expected) + (/phase.result state) + (case> {try.#Success _} true + {try.#Failure _} false)) + (|> (/.inference dummy) + (/.expecting expected) + (/phase.result state) + (case> {try.#Success _} false + {try.#Failure _} true)) + (|> (/.inference expected) + (/.expecting dummy) + (/phase.result state) + (case> {try.#Success _} false + {try.#Failure _} true)))) + (_.cover [/.inferring] + (|> (/.inference expected) + /.inferring + (/phase.result state) + (try#each (|>> product.left (type#= expected))) + (try.else false))) + (_.cover [/.check] + (|> (do /phase.monad + [exT (/.check (do check.monad + [[id type] check.existential] + (in type)))] + (|> (/.inference exT) + (/.expecting exT))) + (/phase.result state) + (case> {try.#Success _} true + {try.#Failure _} false))) + (_.cover [/.fresh] + (and (|> (do /phase.monad + [varT (/.check (do check.monad + [[id type] check.var] + (in type)))] + (|> (/.inference expected) + (/.expecting varT))) + (/phase.result state) + (case> {try.#Success _} true + {try.#Failure _} false)) + (|> (do /phase.monad + [varT (/.check (do check.monad + [[id type] check.var] + (in type)))] + (|> (/.inference expected) + (/.expecting varT) + /.fresh)) + (/phase.result state) + (case> {try.#Success _} false + {try.#Failure _} true)))) + )))) diff --git a/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/simple.lux b/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/simple.lux index 015c9d362..a93b4c3e1 100644 --- a/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/simple.lux +++ b/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/simple.lux @@ -12,19 +12,18 @@ ["[0]" random]]]] [\\library ["[0]" / - [// - ["[1][0]" type] + [/// + ["[1][0]" extension] [// - ["[1][0]" extension] - [// - ["[1][0]" analysis {"+" Analysis Operation}] - [/// - ["[1][0]" phase]]]]]]]) + ["[1][0]" analysis {"+" Analysis Operation} + ["[2][0]" type]] + [/// + ["[1][0]" phase]]]]]]) (def: (analysis state type it ?) (-> Lux Type (Operation Analysis) (-> Analysis Bit) Bit) - (and (|> (/type.with_type type - it) + (and (|> it + (/type.expecting type) (/phase.result [/extension.#bundle /extension.empty /extension.#state state]) (case> (^ {try.#Success analysis}) @@ -32,8 +31,8 @@ _ false)) - (|> (/type.with_type .Nothing - it) + (|> it + (/type.expecting .Nothing) (/phase.result [/extension.#bundle /extension.empty /extension.#state state]) (case> (^ {try.#Failure error}) @@ -41,8 +40,8 @@ _ false)) - (|> (/type.with_inference - it) + (|> it + /type.inferring (/phase.result [/extension.#bundle /extension.empty /extension.#state state]) (case> (^ {try.#Success [inferred analysis]}) |