diff options
author | Eduardo Julian | 2022-01-08 06:37:39 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-01-08 06:37:39 -0400 |
commit | 54e219ee24c1508713d07473cd8a3b04c7f8fe18 (patch) | |
tree | 704007cf63c49d54e4d642da028f12c59eea0047 /stdlib/source/test | |
parent | ef847d54cc6ac57bb2d470c1164ca7daeaa241b1 (diff) |
Fixes for the pure-Lux JVM compiler machinery. [Part 4]
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/lux/target/ruby.lux | 103 | ||||
-rw-r--r-- | stdlib/source/test/lux/tool.lux | 4 | ||||
-rw-r--r-- | stdlib/source/test/lux/tool/compiler/language/lux/analysis/composite.lux | 76 |
3 files changed, 147 insertions, 36 deletions
diff --git a/stdlib/source/test/lux/target/ruby.lux b/stdlib/source/test/lux/target/ruby.lux index 86a817703..7723cd776 100644 --- a/stdlib/source/test/lux/target/ruby.lux +++ b/stdlib/source/test/lux/target/ruby.lux @@ -5,7 +5,9 @@ ["[0]" ffi] [abstract [monad {"+" do}] - ["[0]" predicate]] + ["[0]" predicate] + [\\specification + ["$[0]" equivalence]]] [control ["[0]" maybe ("[1]#[0]" functor)] ["[0]" try {"+" Try} ("[1]#[0]" functor)]] @@ -306,7 +308,7 @@ (|> ($_ /.then (/.set (list $foreign) (/.+ $foreign $foreign)) (/.return $foreign)) - (/.lambda {.#None} (list $foreign)) + [(list $foreign)] (/.lambda {.#None}) (/.apply_lambda/* (list (/.float float/0)))))) )) (_.cover [/.Access] @@ -316,7 +318,7 @@ (/.set (list $foreign) (/.array (list $foreign))) (/.set (list @) (/.+ @ @)) (/.return @)) - (/.lambda {.#None} (list $foreign)) + [(list $foreign)] (/.lambda {.#None}) (/.apply_lambda/* (list (/.float float/0)))))) (expression (|>> (:as Frac) (f.= (f.+ float/0 float/0))) (let [@ (/.item field $foreign)] @@ -324,7 +326,7 @@ (/.set (list $foreign) (/.hash (list [field $foreign]))) (/.set (list @) (/.+ @ @)) (/.return @)) - (/.lambda {.#None} (list $foreign)) + [(list $foreign)] (/.lambda {.#None}) (/.apply_lambda/* (list (/.float float/0)))))) )) ))) @@ -359,7 +361,7 @@ (/.set (list $inner_index) (/.+ (/.int +1) $inner_index)) )) (/.return $output)) - (/.lambda {.#None} (list $input)) + [(list $input)] (/.lambda {.#None}) (/.apply_lambda/* (list (/.int input))))))) (_.cover [/.next] (let [expected (i.* (.int (n.- expected_inner_iterations full_inner_iterations)) input)] @@ -375,7 +377,7 @@ (/.set (list $output) (/.+ $input $output)) )) (/.return $output)) - (/.lambda {.#None} (list $input)) + [(list $input)] (/.lambda {.#None}) (/.apply_lambda/* (list (/.int input))))))) ))) @@ -400,7 +402,7 @@ (/.set (list $index) (/.+ (/.int +1) $index)) )) (/.return $output)) - (/.lambda {.#None} (list $input)) + [(list $input)] (/.lambda {.#None}) (/.apply_lambda/* (list (/.int input)))))) (_.cover [/.for_in] (expression (|>> (:as Int) (i.= expected)) @@ -409,7 +411,7 @@ (/.for_in $index (/.array (list.repeated iterations (/.int input))) (/.set (list $output) (/.+ $index $output))) (/.return $output)) - (/.lambda {.#None} (list $input)) + [(list $input)] (/.lambda {.#None}) (/.apply_lambda/* (list (/.int input)))))) ..test|label ))) @@ -420,13 +422,19 @@ [expected random.safe_frac dummy (random.only (|>> (f.= expected) not) random.safe_frac) - $ex (# ! each /.local (random.ascii/lower 10))] + $ex (# ! each /.local (random.ascii/lower 10)) + + expected_tag random.int + dummy_tag (random.only (|>> (i.= expected_tag) not) + random.int) + .let [expected_tag (/.int expected_tag) + dummy_tag (/.int dummy_tag)]] ($_ _.and (_.cover [/.begin] (expression (|>> (:as Frac) (f.= expected)) (|> (/.begin (/.return (/.float expected)) (list [(list) $ex (/.return (/.float dummy))])) - (/.lambda {.#None} (list)) + [(list)] (/.lambda {.#None}) (/.apply_lambda/* (list))))) (_.cover [/.Rescue /.throw/1] (expression (|>> (:as Frac) (f.= expected)) @@ -434,8 +442,37 @@ (/.throw/1 (/.string "")) (/.return (/.float dummy))) (list [(list) $ex (/.return (/.float expected))])) - (/.lambda {.#None} (list)) + [(list)] (/.lambda {.#None}) + (/.apply_lambda/* (list))))) + (_.cover [/.raise] + (expression (|>> (:as Frac) (f.= expected)) + (|> (/.begin ($_ /.then + (/.statement (/.raise (/.string ""))) + (/.return (/.float dummy))) + (list [(list) $ex (/.return (/.float expected))])) + [(list)] (/.lambda {.#None}) (/.apply_lambda/* (list))))) + (_.cover [/.catch /.throw/2] + (and (expression (|>> (:as Frac) (f.= expected)) + (<| (/.apply_lambda/* (list)) + (/.lambda {.#None}) [(list)] + /.return + (/.catch expected_tag) [(list)] + (/.throw/2 expected_tag (/.float expected)))) + (expression (|>> (:as Frac) (f.= expected)) + (<| (/.apply_lambda/* (list)) + (/.lambda {.#None}) [(list)] + /.return + (/.catch expected_tag) [(list)] + /.statement (/.catch dummy_tag) [(list)] + (/.throw/2 expected_tag (/.float expected)))) + (expression (|>> (:as Frac) (f.= expected)) + (<| (/.apply_lambda/* (list)) + (/.lambda {.#None}) [(list)] + /.return + (/.catch dummy_tag) [(list)] + /.statement (/.catch expected_tag) [(list)] + (/.throw/2 expected_tag (/.float expected)))))) ))) (def: test|function @@ -456,18 +493,18 @@ (_.cover [/.lambda /.return] (and (expression (|>> (:as Frac) (f.= float/0)) (|> (/.return (/.float float/0)) - (/.lambda {.#None} (list)) + [(list)] (/.lambda {.#None}) (/.apply_lambda/* (list)))) (expression (|>> (:as Frac) f.nat (n.= iterations)) - (|> (/.lambda {.#Some $self} (list $arg/0) - (/.return (/.? (/.< (/.int (.int iterations)) $arg/0) - (/.apply_lambda/* (list (/.+ (/.int +1) $arg/0)) $self) - $arg/0))) + (|> (/.return (/.? (/.< (/.int (.int iterations)) $arg/0) + (/.apply_lambda/* (list (/.+ (/.int +1) $arg/0)) $self) + $arg/0)) + [(list $arg/0)] (/.lambda {.#Some $self}) (/.apply_lambda/* (list (/.int +0))))))) (_.cover [/.apply_lambda/*] (expression (|>> (:as Frac) (f.= ($_ f.+ float/0 float/1 float/2))) (|> (/.return ($_ /.+ $arg/0 $arg/1 $arg/2)) - (/.lambda {.#None} (list $arg/0 $arg/1 $arg/2)) + [(list $arg/0 $arg/1 $arg/2)] (/.lambda {.#None}) (/.apply_lambda/* (list (/.float float/0) (/.float float/1) (/.float float/2)))))) (_.cover [/.function] (expression (|>> (:as Frac) f.nat (n.= iterations)) @@ -477,7 +514,7 @@ (/.apply/1 $self (/.+ (/.int +1) $arg/0)) $arg/0))) (/.return (/.apply/1 $self (/.int +0)))) - (/.lambda {.#None} (list)) + [(list)] (/.lambda {.#None}) (/.apply_lambda/* (list))))) (_.cover [/.apply/1] (expression (|>> (:as Frac) (f.= float/0)) @@ -485,7 +522,7 @@ (/.function $self (list $arg/0) (/.return $arg/0)) (/.return (/.apply/1 $self (/.float float/0)))) - (/.lambda {.#None} (list)) + [(list)] (/.lambda {.#None}) (/.apply_lambda/* (list))))) (_.cover [/.apply/2] (expression (|>> (:as Frac) (f.= ($_ f.+ float/0 float/1))) @@ -493,15 +530,7 @@ (/.function $self (list $arg/0 $arg/1) (/.return ($_ /.+ $arg/0 $arg/1))) (/.return (/.apply/2 $self (/.float float/0) (/.float float/1)))) - (/.lambda {.#None} (list)) - (/.apply_lambda/* (list))))) - (_.cover [/.apply/3] - (expression (|>> (:as Frac) (f.= ($_ f.+ float/0 float/1 float/2))) - (|> ($_ /.then - (/.function $self (list $arg/0 $arg/1 $arg/2) - (/.return ($_ /.+ $arg/0 $arg/1 $arg/2))) - (/.return (/.apply/3 $self (/.float float/0) (/.float float/1) (/.float float/2)))) - (/.lambda {.#None} (list)) + [(list)] (/.lambda {.#None}) (/.apply_lambda/* (list))))) (_.cover [/.apply/*] (expression (|>> (:as Frac) (f.= ($_ f.+ float/0 float/1 float/2))) @@ -509,7 +538,7 @@ (/.function $self (list $arg/0 $arg/1 $arg/2) (/.return ($_ /.+ $arg/0 $arg/1 $arg/2))) (/.return (/.apply/* (list (/.float float/0) (/.float float/1) (/.float float/2)) {.#None} $self))) - (/.lambda {.#None} (list)) + [(list)] (/.lambda {.#None}) (/.apply_lambda/* (list))))) ... (_.cover [/.new] ... (let [$this (/.local "this")] @@ -544,7 +573,7 @@ (|> (/.if (/.bool ???) (/.return (/.float float/0)) (/.return (/.float float/1))) - (/.lambda {.#None} (list)) + [(list)] (/.lambda {.#None}) (/.apply_lambda/* (list))))) (_.cover [/.when] (expression (|>> (:as Frac) (f.= (if ??? float/0 float/1))) @@ -552,7 +581,7 @@ (/.when (/.bool ???) (/.return (/.float float/0))) (/.return (/.float float/1))) - (/.lambda {.#None} (list)) + [(list)] (/.lambda {.#None}) (/.apply_lambda/* (list))))) ))) @@ -571,19 +600,20 @@ (|> ($_ /.then (/.statement (/.+ $arg/0 $arg/0)) (/.return $arg/0)) - (/.lambda {.#None} (list $arg/0)) + [(list $arg/0)] (/.lambda {.#None}) (/.apply_lambda/* (list (/.float float/0)))))) (_.cover [/.then] (expression (|>> (:as Frac) (f.= float/0)) (|> ($_ /.then (/.return $arg/0) (/.return $arg/1)) - (/.lambda {.#None} (list $arg/0 $arg/1)) + [(list $arg/0 $arg/1)] (/.lambda {.#None}) (/.apply_lambda/* (list (/.float float/0) (/.float float/1)))))) ..test|exception - ..test|function ..test|branching ..test|loop + (_.for [/.Block] + ..test|function) (_.for [/.Location] ..test/location) ))) @@ -632,10 +662,13 @@ (<| (_.covering /._) (_.for [/.Code]) ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random_expression)) + (_.cover [/.code /.manual] (|> (/.manual (/.code expected)) (: /.Expression) - (# /.code_equivalence = expected))) + (# /.equivalence = expected))) (_.for [/.Expression] ..test|expression) (_.for [/.Statement] diff --git a/stdlib/source/test/lux/tool.lux b/stdlib/source/test/lux/tool.lux index e2cbc50b6..4e3bad586 100644 --- a/stdlib/source/test/lux/tool.lux +++ b/stdlib/source/test/lux/tool.lux @@ -11,7 +11,8 @@ [lux ... ["[1][0]" syntax] ["[1][0]" analysis "_" - ["[1]/[0]" primitive]] + ["[1]/[0]" primitive] + ["[1]/[0]" composite]] ... [phase ... ["[1][0]" analysis] ... ["[1][0]" synthesis]] @@ -25,6 +26,7 @@ /version.test /reference.test /analysis/primitive.test + /analysis/composite.test ... /syntax.test ... /analysis.test ... /synthesis.test diff --git a/stdlib/source/test/lux/tool/compiler/language/lux/analysis/composite.lux b/stdlib/source/test/lux/tool/compiler/language/lux/analysis/composite.lux new file mode 100644 index 000000000..8c74718b8 --- /dev/null +++ b/stdlib/source/test/lux/tool/compiler/language/lux/analysis/composite.lux @@ -0,0 +1,76 @@ +(.using + [library + [lux "*" + ["_" test {"+" Test}] + [abstract + [monad {"+" do}] + [\\specification + ["$[0]" equivalence] + ["$[0]" hash]]] + [data + ["[0]" bit ("[1]#[0]" equivalence)] + ["[0]" text ("[1]#[0]" equivalence) + ["%" format {"+" format}]]] + [math + ["[0]" random {"+" Random} ("[1]#[0]" monad)] + [number + ["n" nat]]]]] + [\\library + ["[0]" /]]) + +(def: test|tag + Test + (do [! random.monad] + [multiplicity (# ! each (n.max 2) random.nat) + tag (# ! each (n.% multiplicity) random.nat) + lefts random.nat + right? random.bit] + ($_ _.and + (_.cover [/.tag /.lefts] + (and (|> lefts + (/.tag right?) + (/.lefts right?) + (n.= lefts)) + (|> tag + (/.lefts right?) + (/.tag right?) + (n.= tag)))) + (_.cover [/.choice] + (let [[lefts right?] (/.choice multiplicity tag)] + (if right? + (n.= (-- tag) lefts) + (n.= tag lefts)))) + ))) + +(def: .public (random multiplicity it) + (All (_ a) + (-> Nat (Random a) (Random (/.Composite a)))) + ($_ random.or + ($_ random.and + (random#each (n.% (-- multiplicity)) random.nat) + random.bit + it) + (random.list multiplicity it) + )) + +(def: .public test + Test + (let [random (..random 3 random.nat)] + (<| (_.covering /._) + (_.for [/.Composite /.Variant /.Tuple]) + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec (/.equivalence n.equivalence) random)) + (_.for [/.hash] + ($hash.spec (/.hash n.hash) random)) + + (_.for [/.Tag] + ..test|tag) + + (do random.monad + [left random + right random] + (_.cover [/.format] + (bit#= (# (/.equivalence n.equivalence) = left right) + (text#= (/.format %.nat left) (/.format %.nat right))))) + )))) |