aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/compiler/target/js.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test/lux/meta/compiler/target/js.lux')
-rw-r--r--stdlib/source/test/lux/meta/compiler/target/js.lux848
1 files changed, 848 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/meta/compiler/target/js.lux b/stdlib/source/test/lux/meta/compiler/target/js.lux
new file mode 100644
index 000000000..2ad2b03ad
--- /dev/null
+++ b/stdlib/source/test/lux/meta/compiler/target/js.lux
@@ -0,0 +1,848 @@
+(.require
+ [library
+ [lux (.except)
+ [abstract
+ [monad (.only do)]]
+ [control
+ ["[0]" pipe]
+ ["[0]" maybe (.use "[1]#[0]" functor)]
+ ["[0]" try (.only Try) (.use "[1]#[0]" functor)]
+ ["[0]" function (.only)
+ ["[0]" predicate]]]
+ [data
+ ["[0]" bit (.use "[1]#[0]" equivalence)]
+ ["[0]" text (.only \n) (.use "[1]#[0]" equivalence)
+ ["%" \\format (.only format)]]
+ [collection
+ ["[0]" list (.use "[1]#[0]" functor)]]]
+ [math
+ ["[0]" random (.only Random) (.use "[1]#[0]" monad)]
+ [number
+ ["n" nat]
+ ["i" int]
+ ["f" frac]
+ ["[0]" i64]]]
+ [meta
+ ["[0]" static]
+ [macro
+ ["[0]" template]]]
+ [test
+ ["_" property (.only Test)]]]]
+ [\\library
+ ["[0]" /]])
+
+(def (eval code)
+ (-> /.Expression (Try (Maybe Any)))
+ ... Note: I have to call "eval" this way
+ ... in order to avoid a quirk of calling eval in Node
+ ... when the code is running under "use strict";.
+ (try (let [return (.js_apply# (function.identity (.js_constant# "eval")) [(/.code code)])]
+ (if (.js_object_null?# return)
+ {.#None}
+ {.#Some return}))))
+
+(def (expression ??? it)
+ (-> (-> Any Bit) /.Expression Bit)
+ (|> it
+ ..eval
+ (try#each (|>> (maybe#each ???)
+ (maybe.else false)))
+ (try.else false)))
+
+(with_template [<range>]
+ [(`` (def (,, (template.symbol ["as_int_" <range>]))
+ (-> Int Int)
+ (|>> (i64.and (static.nat (-- (i64.left_shifted <range> 1)))))))
+ (`` (def (,, (template.symbol ["int_" <range>]))
+ (Random Int)
+ (do [! random.monad]
+ [negative? random.bit
+ mantissa (of ! each (|>> (i64.and (static.nat (-- (i64.left_shifted (-- <range>) 1))))
+ .int)
+ random.nat)]
+ (in (if negative?
+ (i.* -1 mantissa)
+ mantissa)))))]
+
+ [16]
+ [32]
+ )
+
+(def test|literal
+ Test
+ (do [! random.monad]
+ [boolean random.bit
+ number random.frac
+ int ..int_32
+ string (random.upper_cased 5)]
+ (all _.and
+ (_.coverage [/.null]
+ (|> /.null
+ ..eval
+ (try#each (function (_ it)
+ (when it
+ {.#None} true
+ {.#Some _} false)))
+ (try.else false)))
+ (_.coverage [/.boolean]
+ (expression (|>> (as Bit) (bit#= boolean))
+ (/.boolean boolean)))
+ (_.coverage [/.number]
+ (expression (|>> (as Frac) (f.= number))
+ (/.number number)))
+ (_.coverage [/.int]
+ (expression (|>> (as Frac) f.int (i.= int))
+ (/.int int)))
+ (_.coverage [/.string]
+ (expression (|>> (as Text) (text#= string))
+ (/.string string)))
+ )))
+
+(def test|boolean
+ Test
+ (do [! random.monad]
+ [left random.bit
+ right random.bit]
+ (`` (all _.and
+ (,, (with_template [<js> <lux>]
+ [(_.coverage [<js>]
+ (let [expected (<lux> left right)]
+ (expression (|>> (as Bit) (bit#= expected))
+ (<js> (/.boolean left) (/.boolean right)))))]
+
+ [/.or .or]
+ [/.and .and]
+ ))
+ (_.coverage [/.not]
+ (expression (|>> (as Bit) (bit#= (not left)))
+ (/.not (/.boolean left))))
+ ))))
+
+(def test|number
+ Test
+ (do [! random.monad]
+ [parameter (random.only (|>> (f.= +0.0) not)
+ random.safe_frac)
+ subject random.safe_frac]
+ (`` (all _.and
+ (,, (with_template [<js> <lux>]
+ [(_.coverage [<js>]
+ (let [expected (<lux> parameter subject)]
+ (expression (|>> (as Frac) (f.= expected))
+ (<js> (/.number parameter) (/.number subject)))))]
+
+ [/.+ f.+]
+ [/.- f.-]
+ [/.* f.*]
+ [/./ f./]
+ [/.% f.%]
+ ))
+ (,, (with_template [<js> <lux>]
+ [(_.coverage [<js>]
+ (let [expected (<lux> parameter subject)]
+ (expression (|>> (as Bit) (bit#= expected))
+ (<js> (/.number parameter) (/.number subject)))))]
+
+ [/.< f.<]
+ [/.<= f.<=]
+ [/.> f.>]
+ [/.>= f.>=]
+ [/.= f.=]
+ ))
+ ))))
+
+(def test|i32
+ Test
+ (do [! random.monad]
+ [left ..int_32
+ right ..int_32
+
+ i32 ..int_32
+ i16 ..int_16
+ shift (of ! each (n.% 16) random.nat)]
+ (`` (all _.and
+ (,, (with_template [<js> <lux>]
+ [(_.coverage [<js>]
+ (let [expected (<lux> left right)]
+ (expression (|>> (as Frac) f.int (i.= expected))
+ (<js> (/.int left) (/.int right)))))]
+
+ [/.bit_or i64.or]
+ [/.bit_xor i64.xor]
+ [/.bit_and i64.and]
+ ))
+ (_.coverage [/.opposite]
+ (expression (|>> (as Frac) f.int (i.= (i.* -1 i32)))
+ (/.opposite (/.i32 i32))))
+
+ (_.coverage [/.i32]
+ (expression (|>> (as Frac) f.int (i.= i32))
+ (/.i32 i32)))
+ (_.coverage [/.to_i32]
+ (expression (|>> (as Frac) f.int (i.= i32))
+ (/.to_i32 (/.int i32))))
+ (_.coverage [/.left_shift]
+ (let [expected (i64.left_shifted shift i16)]
+ (expression (|>> (as Frac) f.int (i.= expected))
+ (/.left_shift (/.int (.int shift))
+ (/.i32 i16)))))
+ (_.coverage [/.logic_right_shift]
+ (let [expected (i64.right_shifted shift (as_int_32 i16))]
+ (expression (|>> (as Frac) f.int (i.= expected))
+ (/.logic_right_shift (/.int (.int shift))
+ (/.i32 i16)))))
+ (_.coverage [/.arithmetic_right_shift]
+ (let [expected (i.right_shifted shift i16)]
+ (expression (|>> (as Frac) f.int (i.= expected))
+ (/.arithmetic_right_shift (/.int (.int shift))
+ (/.i32 i16)))))
+ (_.coverage [/.bit_not]
+ (let [expected (if (i.< +0 i32)
+ (as_int_32 (i64.not i32))
+ (i64.not (as_int_32 i32)))]
+ (expression (|>> (as Frac) f.int (i.= expected))
+ (/.bit_not (/.i32 i32)))))
+ ))))
+
+(def test|array
+ Test
+ (do [! random.monad]
+ [size (of ! each (|>> (n.% 10) ++) random.nat)
+ index (of ! each (n.% size) random.nat)
+ items (random.list size random.safe_frac)
+ .let [expected (|> items
+ (list.item index)
+ (maybe.else f.not_a_number))]]
+ (all _.and
+ (_.coverage [/.array /.at]
+ (and (expression (|>> (as Frac) (f.= expected))
+ (/.at (/.int (.int index))
+ (/.array (list#each /.number items))))
+ (expression (|>> (as Bit))
+ (|> (/.array (list#each /.number items))
+ (/.at (/.int (.int size)))
+ (/.= /.undefined)))))
+ )))
+
+(def test|object
+ Test
+ (do [! random.monad]
+ [expected random.safe_frac
+ field (random.upper_cased 5)
+ dummy (random.only (|>> (text#= field) not)
+ (random.upper_cased 5))
+
+ size (of ! each (|>> (n.% 10) ++) random.nat)
+ index (of ! each (n.% size) random.nat)
+ items (random.list size random.safe_frac)]
+ (all _.and
+ (_.coverage [/.object /.the]
+ (expression (|>> (as Frac) (f.= expected))
+ (/.the field (/.object (list [field (/.number expected)])))))
+ (let [expected (|> items
+ (list.item index)
+ (maybe.else f.not_a_number))]
+ (_.coverage [/.do]
+ (expression (|>> (as Frac) f.int (i.= (.int index)))
+ (|> (/.array (list#each /.number items))
+ (/.do "lastIndexOf" (list (/.number expected)))))))
+ (_.coverage [/.undefined]
+ (expression (|>> (as Bit))
+ (|> (/.object (list [field (/.number expected)]))
+ (/.the dummy)
+ (/.= /.undefined))))
+ )))
+
+(def test|computation
+ Test
+ (do [! random.monad]
+ [test random.bit
+ then random.safe_frac
+ else random.safe_frac
+
+ boolean random.bit
+ number random.frac
+ string (random.upper_cased 5)
+
+ comment (random.upper_cased 10)]
+ (all _.and
+ ..test|boolean
+ ..test|number
+ ..test|i32
+ ..test|array
+ ..test|object
+ (_.coverage [/.?]
+ (let [expected (if test then else)]
+ (expression (|>> (as Frac) (f.= expected))
+ (/.? (/.boolean test)
+ (/.number then)
+ (/.number else)))))
+ (_.coverage [/.not_a_number?]
+ (and (expression (|>> (as Bit))
+ (/.not_a_number? (/.number f.not_a_number)))
+ (expression (|>> (as Bit) not)
+ (/.not_a_number? (/.number then)))))
+ (_.coverage [/.type_of]
+ (and (expression (|>> (as Text) (text#= "boolean"))
+ (/.type_of (/.boolean boolean)))
+ (expression (|>> (as Text) (text#= "number"))
+ (/.type_of (/.number number)))
+ (expression (|>> (as Text) (text#= "string"))
+ (/.type_of (/.string string)))
+ (expression (|>> (as Text) (text#= "object"))
+ (/.type_of /.null))
+ (expression (|>> (as Text) (text#= "object"))
+ (/.type_of (/.object (list [string (/.number number)]))))
+ (expression (|>> (as Text) (text#= "object"))
+ (/.type_of (/.array (list (/.boolean boolean)
+ (/.number number)
+ (/.string string)))))
+ (expression (|>> (as Text) (text#= "undefined"))
+ (/.type_of /.undefined))))
+ (_.coverage [/.comment]
+ (expression (|>> (as Frac) (f.= then))
+ (/.comment comment
+ (/.number then))))
+ )))
+
+(def test|expression
+ Test
+ (do [! random.monad]
+ [dummy random.safe_frac
+ expected random.safe_frac]
+ (`` (all _.and
+ (_.for [/.Literal]
+ ..test|literal)
+ (_.for [/.Computation]
+ ..test|computation)
+ (_.coverage [/.,]
+ (expression (|>> (as Frac) (f.= expected))
+ (/., (/.number dummy) (/.number expected))))
+ ))))
+
+(def test/var
+ Test
+ (do [! random.monad]
+ [number/0 random.safe_frac
+ number/1 random.safe_frac
+ number/2 random.safe_frac
+ foreign (random.lower_cased 10)
+ local (random.only (|>> (text#= foreign) not)
+ (random.lower_cased 10))
+ .let [$foreign (/.var foreign)
+ $local (/.var local)]]
+ (all _.and
+ (_.coverage [/.var]
+ (expression (|>> (as Frac) (f.= number/0))
+ (/.apply (/.closure (list $foreign) (/.return $foreign))
+ (list (/.number number/0)))))
+ (_.coverage [/.define]
+ (expression (|>> (as Frac) (f.= number/1))
+ (/.apply (/.closure (list $foreign)
+ (all /.then
+ (/.define $local (/.number number/1))
+ (/.return $local)))
+ (list (/.number number/0)))))
+ (_.coverage [/.declare]
+ (expression (|>> (as Frac) (f.= number/1))
+ (/.apply (/.closure (list $foreign)
+ (all /.then
+ (/.declare $local)
+ (/.statement (/.set $local (/.number number/1)))
+ (/.return $local)))
+ (list (/.number number/0)))))
+ )))
+
+(def test/location
+ Test
+ (do [! random.monad]
+ [number/0 random.safe_frac
+ int/0 ..int_16
+ $foreign (of ! each /.var (random.lower_cased 10))
+ field (random.upper_cased 10)]
+ (all _.and
+ (_.coverage [/.set]
+ (and (expression (|>> (as Frac) (f.= (f.+ number/0 number/0)))
+ (/.apply (/.closure (list $foreign)
+ (all /.then
+ (/.statement (/.set $foreign (/.+ $foreign $foreign)))
+ (/.return $foreign)))
+ (list (/.number number/0))))
+ (expression (|>> (as Frac) (f.= (f.+ number/0 number/0)))
+ (let [@ (/.at (/.int +0) $foreign)]
+ (/.apply (/.closure (list $foreign)
+ (all /.then
+ (/.statement (/.set $foreign (/.array (list $foreign))))
+ (/.statement (/.set @ (/.+ @ @)))
+ (/.return @)))
+ (list (/.number number/0)))))
+ (expression (|>> (as Frac) (f.= (f.+ number/0 number/0)))
+ (let [@ (/.the field $foreign)]
+ (/.apply (/.closure (list $foreign)
+ (all /.then
+ (/.statement (/.set $foreign (/.object (list [field $foreign]))))
+ (/.statement (/.set @ (/.+ @ @)))
+ (/.return @)))
+ (list (/.number number/0)))))))
+ (_.coverage [/.delete]
+ (and (and (expression (|>> (as Bit))
+ (/.apply (/.closure (list)
+ (all /.then
+ (/.statement (/.set $foreign (/.number number/0)))
+ (/.return (/.delete $foreign))))
+ (list)))
+ (expression (|>> (as Bit) not)
+ (/.apply (/.closure (list $foreign)
+ (/.return (/.delete $foreign)))
+ (list (/.number number/0)))))
+ (expression (|>> (as Bit))
+ (let [@ (/.at (/.int +0) $foreign)]
+ (/.apply (/.closure (list $foreign)
+ (all /.then
+ (/.statement (/.set $foreign (/.array (list $foreign))))
+ (/.return (|> (/.= (/.boolean true) (/.delete @))
+ (/.and (/.= /.undefined @))))))
+ (list (/.number number/0)))))
+ (expression (|>> (as Bit))
+ (let [@ (/.the field $foreign)]
+ (/.apply (/.closure (list $foreign)
+ (all /.then
+ (/.statement (/.set $foreign (/.object (list [field $foreign]))))
+ (/.return (|> (/.= (/.boolean true) (/.delete @))
+ (/.and (/.= /.undefined @))))))
+ (list (/.number number/0)))))
+ ))
+ (_.coverage [/.Access]
+ (`` (and (,, (with_template [<js> <lux>]
+ [(expression (|>> (as Frac) f.int (i.= (<lux> int/0)))
+ (/.apply (/.closure (list $foreign)
+ (all /.then
+ (/.statement (<js> $foreign))
+ (/.return $foreign)))
+ (list (/.int int/0))))
+ (expression (|>> (as Frac) f.int (i.= (<lux> int/0)))
+ (let [@ (/.at (/.int +0) $foreign)]
+ (/.apply (/.closure (list $foreign)
+ (all /.then
+ (/.statement (/.set $foreign (/.array (list $foreign))))
+ (/.statement (<js> @))
+ (/.return @)))
+ (list (/.int int/0)))))
+ (expression (|>> (as Frac) f.int (i.= (<lux> int/0)))
+ (let [@ (/.the field $foreign)]
+ (/.apply (/.closure (list $foreign)
+ (all /.then
+ (/.statement (/.set $foreign (/.object (list [field $foreign]))))
+ (/.statement (<js> @))
+ (/.return @)))
+ (list (/.int int/0)))))]
+
+ [/.++ .++]
+ [/.-- .--]
+ )))))
+ (_.for [/.Var]
+ ..test/var)
+ )))
+
+(def test|label
+ Test
+ (do [! random.monad]
+ [input ..int_16
+
+ full_inner_iterations (of ! each (|>> (n.% 20) ++) random.nat)
+ expected_inner_iterations (of ! each (n.% full_inner_iterations) random.nat)
+
+ @outer (of ! each /.label (random.upper_cased 5))
+ full_outer_iterations (of ! each (|>> (n.% 10) ++) random.nat)
+ expected_outer_iterations (of ! each (n.% full_outer_iterations) random.nat)
+
+ .let [$input (/.var "input")
+ $output (/.var "output")
+ $inner_index (/.var "inner_index")
+ $outer_index (/.var "outer_index")]]
+ (all _.and
+ (_.coverage [/.break]
+ (let [expected (i.* (.int expected_inner_iterations) input)]
+ (expression (|>> (as Frac) f.int (i.= expected))
+ (/.apply (/.closure (list $input)
+ (all /.then
+ (/.define $inner_index (/.int +0))
+ (/.define $output (/.int +0))
+ (/.while (/.< (/.int (.int full_inner_iterations)) $inner_index)
+ (all /.then
+ (/.when (/.= (/.int (.int expected_inner_iterations)) $inner_index)
+ /.break)
+ (/.statement (/.set $output (/.+ $input $output)))
+ (/.statement (/.set $inner_index (/.+ (/.int +1) $inner_index)))
+ ))
+ (/.return $output)))
+ (list (/.int input))))))
+ (_.coverage [/.continue]
+ (let [expected (i.* (.int (n.- expected_inner_iterations full_inner_iterations)) input)]
+ (expression (|>> (as Frac) f.int (i.= expected))
+ (/.apply (/.closure (list $input)
+ (all /.then
+ (/.define $inner_index (/.int +0))
+ (/.define $output (/.int +0))
+ (/.while (/.< (/.int (.int full_inner_iterations)) $inner_index)
+ (all /.then
+ (/.statement (/.set $inner_index (/.+ (/.int +1) $inner_index)))
+ (/.when (/.<= (/.int (.int expected_inner_iterations)) $inner_index)
+ /.continue)
+ (/.statement (/.set $output (/.+ $input $output)))
+ ))
+ (/.return $output)))
+ (list (/.int input))))))
+ (_.for [/.label /.with_label]
+ (all _.and
+ (_.coverage [/.break_at]
+ (let [expected (i.* (.int (n.* expected_outer_iterations
+ expected_inner_iterations))
+ input)]
+ (expression (|>> (as Frac) f.int (i.= expected))
+ (/.apply (/.closure (list $input)
+ (all /.then
+ (/.define $output (/.int +0))
+ (/.define $outer_index (/.int +0))
+ (/.with_label @outer
+ (/.while (/.< (/.int (.int full_outer_iterations)) $outer_index)
+ (all /.then
+ (/.define $inner_index (/.int +0))
+ (/.while (/.< (/.int (.int full_inner_iterations)) $inner_index)
+ (all /.then
+ (/.when (/.= (/.int (.int expected_outer_iterations)) $outer_index)
+ (/.break_at @outer))
+ (/.when (/.= (/.int (.int expected_inner_iterations)) $inner_index)
+ /.break)
+ (/.statement (/.set $output (/.+ $input $output)))
+ (/.statement (/.set $inner_index (/.+ (/.int +1) $inner_index)))
+ ))
+ (/.statement (/.set $outer_index (/.+ (/.int +1) $outer_index)))
+ )))
+ (/.return $output)))
+ (list (/.int input))))))
+ (_.coverage [/.continue_at]
+ (let [expected (i.* (.int (n.* (n.- expected_outer_iterations full_outer_iterations)
+ (n.- expected_inner_iterations full_inner_iterations)))
+ input)]
+ (expression (|>> (as Frac) f.int (i.= expected))
+ (/.apply (/.closure (list $input)
+ (all /.then
+ (/.define $output (/.int +0))
+ (/.define $outer_index (/.int +0))
+ (/.with_label @outer
+ (/.while (/.< (/.int (.int full_outer_iterations)) $outer_index)
+ (all /.then
+ (/.statement (/.set $outer_index (/.+ (/.int +1) $outer_index)))
+ (/.define $inner_index (/.int +0))
+ (/.while (/.< (/.int (.int full_inner_iterations)) $inner_index)
+ (all /.then
+ (/.statement (/.set $inner_index (/.+ (/.int +1) $inner_index)))
+ (/.when (/.<= (/.int (.int expected_outer_iterations)) $outer_index)
+ (/.continue_at @outer))
+ (/.when (/.<= (/.int (.int expected_inner_iterations)) $inner_index)
+ /.continue)
+ (/.statement (/.set $output (/.+ $input $output)))
+ ))
+ )
+ ))
+ (/.return $output)))
+ (list (/.int input))))))
+ ))
+ )))
+
+(def test|loop
+ Test
+ (do [! random.monad]
+ [input ..int_16
+ iterations (of ! each (n.% 10) random.nat)
+ .let [$input (/.var "input")
+ $output (/.var "output")
+ $index (/.var "index")
+ expected|while (i.* (.int iterations) input)
+ expected|do_while (i.* (.int (n.max 1 iterations)) input)]]
+ (all _.and
+ (_.coverage [/.while]
+ (expression (|>> (as Frac) f.int (i.= expected|while))
+ (/.apply (/.closure (list $input)
+ (all /.then
+ (/.define $index (/.int +0))
+ (/.define $output (/.int +0))
+ (/.while (/.< (/.int (.int iterations)) $index)
+ (all /.then
+ (/.statement (/.set $output (/.+ $input $output)))
+ (/.statement (/.set $index (/.+ (/.int +1) $index)))
+ ))
+ (/.return $output)))
+ (list (/.int input)))))
+ (_.coverage [/.do_while]
+ (expression (|>> (as Frac) f.int (i.= expected|do_while))
+ (/.apply (/.closure (list $input)
+ (all /.then
+ (/.define $index (/.int +0))
+ (/.define $output (/.int +0))
+ (/.do_while (/.< (/.int (.int iterations)) $index)
+ (all /.then
+ (/.statement (/.set $output (/.+ $input $output)))
+ (/.statement (/.set $index (/.+ (/.int +1) $index)))
+ ))
+ (/.return $output)))
+ (list (/.int input)))))
+ (_.coverage [/.for]
+ (expression (|>> (as Frac) f.int (i.= expected|while))
+ (/.apply (/.closure (list $input)
+ (all /.then
+ (/.define $output (/.int +0))
+ (/.for $index (/.int +0)
+ (/.< (/.int (.int iterations)) $index)
+ (/.++ $index)
+ (/.statement (/.set $output (/.+ $input $output))))
+ (/.return $output)))
+ (list (/.int input)))))
+ (_.for [/.Label]
+ ..test|label)
+ )))
+
+(def test|exception
+ Test
+ (do [! random.monad]
+ [expected random.safe_frac
+ dummy (random.only (|>> (f.= expected) not)
+ random.safe_frac)
+ $ex (of ! each /.var (random.lower_cased 10))]
+ (all _.and
+ (_.coverage [/.try]
+ (expression (|>> (as Frac) (f.= expected))
+ (/.apply (/.closure (list)
+ (/.try (/.return (/.number expected))
+ [$ex (/.return (/.number dummy))]))
+ (list))))
+ (_.coverage [/.throw]
+ (expression (|>> (as Frac) (f.= expected))
+ (/.apply (/.closure (list)
+ (/.try (all /.then
+ (/.throw (/.number expected))
+ (/.return (/.number dummy)))
+ [$ex (/.return $ex)]))
+ (list))))
+ )))
+
+(def test|apply
+ Test
+ (do [! random.monad]
+ [number/0 random.safe_frac
+ number/1 random.safe_frac
+ number/2 random.safe_frac
+ $arg/0 (of ! each /.var (random.lower_cased 10))
+ $arg/1 (of ! each /.var (random.lower_cased 11))
+ $arg/2 (of ! each /.var (random.lower_cased 12))]
+ (`` (all _.and
+ (_.coverage [/.apply_1]
+ (expression (|>> (as Frac) (f.= number/0))
+ (/.apply_1 (/.closure (list $arg/0) (/.return $arg/0))
+ (/.number number/0))))
+ (_.coverage [/.apply_2]
+ (expression (|>> (as Frac) (f.= (all f.+ number/0 number/1)))
+ (/.apply_2 (/.closure (list $arg/0 $arg/1) (/.return (all /.+ $arg/0 $arg/1)))
+ (/.number number/0)
+ (/.number number/1))))
+ (_.coverage [/.apply_3]
+ (expression (|>> (as Frac) (f.= (all f.+ number/0 number/1 number/2)))
+ (/.apply_3 (/.closure (list $arg/0 $arg/1 $arg/2) (/.return (all /.+ $arg/0 $arg/1 $arg/2)))
+ (/.number number/0)
+ (/.number number/1)
+ (/.number number/2))))
+ (_.coverage [/.apply]
+ (expression (|>> (as Frac) (f.= (all f.+ number/0 number/1 number/2)))
+ (/.apply (/.closure (list $arg/0 $arg/1 $arg/2) (/.return (all /.+ $arg/0 $arg/1 $arg/2)))
+ (list (/.number number/0)
+ (/.number number/1)
+ (/.number number/2)))))
+ ))))
+
+(def test|function
+ Test
+ (do [! random.monad]
+ [number/0 random.safe_frac
+ iterations (of ! each (n.% 10) random.nat)
+ $self (of ! each /.var (random.lower_cased 1))
+ $arg/0 (of ! each /.var (random.lower_cased 2))
+ field (random.lower_cased 3)
+ $class (of ! each /.var (random.upper_cased 4))]
+ (all _.and
+ (_.coverage [/.closure /.return]
+ (expression (|>> (as Frac) (f.= number/0))
+ (/.apply (/.closure (list) (/.return (/.number number/0)))
+ (list))))
+ (_.coverage [/.function]
+ (expression (|>> (as Frac) f.nat (n.= iterations))
+ (/.apply_1 (/.function $self (list $arg/0)
+ (/.return (/.? (/.< (/.int (.int iterations)) $arg/0)
+ (/.apply_1 $self (/.+ (/.int +1) $arg/0))
+ $arg/0)))
+ (/.int +0))))
+ (_.coverage [/.function_definition]
+ (expression (|>> (as Frac) f.nat (n.= iterations))
+ (/.apply (/.closure (list)
+ (all /.then
+ (/.function_definition $self (list $arg/0)
+ (/.return (/.? (/.< (/.int (.int iterations)) $arg/0)
+ (/.apply_1 $self (/.+ (/.int +1) $arg/0))
+ $arg/0)))
+ (/.return (/.apply_1 $self (/.int +0)))))
+ (list))))
+ (_.coverage [/.new]
+ (let [$this (/.var "this")]
+ (expression (|>> (as Frac) (f.= number/0))
+ (/.apply_1 (/.closure (list $arg/0)
+ (all /.then
+ (/.function_definition $class (list)
+ (/.statement (/.set (/.the field $this) $arg/0)))
+ (/.return (/.the field (/.new $class (list))))))
+ (/.number number/0)))))
+ ..test|apply
+ )))
+
+(def test|branching
+ Test
+ (do [! random.monad]
+ [number/0 random.safe_frac
+ number/1 random.safe_frac
+ number/2 random.safe_frac
+ arg/0 (random.lower_cased 10)
+ arg/1 (random.only (|>> (text#= arg/0) not)
+ (random.lower_cased 10))
+ arg/2 (random.only (predicate.and (|>> (text#= arg/0) not)
+ (|>> (text#= arg/1) not))
+ (random.lower_cased 10))
+ .let [$arg/0 (/.var arg/0)
+ $arg/1 (/.var arg/1)
+ $arg/2 (/.var arg/2)]
+ ??? random.bit
+ int ..int_16]
+ (all _.and
+ (_.coverage [/.if]
+ (expression (|>> (as Frac) (f.= (if ??? number/0 number/1)))
+ (/.apply (/.closure (list)
+ (/.if (/.boolean ???)
+ (/.return (/.number number/0))
+ (/.return (/.number number/1))))
+ (list))))
+ (_.coverage [/.when]
+ (expression (|>> (as Frac) (f.= (if ??? number/0 number/1)))
+ (/.apply (/.closure (list)
+ (all /.then
+ (/.when (/.boolean ???)
+ (/.return (/.number number/0)))
+ (/.return (/.number number/1))))
+ (list))))
+ (_.coverage [/.switch]
+ (let [number/0' (%.frac number/0)
+ number/1' (%.frac number/1)
+ number/2' (%.frac number/2)]
+ (and (expression (|>> (as Text) (text#= number/0'))
+ (/.apply (/.closure (list)
+ (/.switch (/.number number/0)
+ (list [(list (/.number number/0)) (/.return (/.string number/0'))]
+ [(list (/.number number/1)) (/.return (/.string number/1'))])
+ {.#None}))
+ (list)))
+ (expression (|>> (as Text) (text#= number/1'))
+ (/.apply (/.closure (list)
+ (/.switch (/.number number/1)
+ (list [(list (/.number number/0)) (/.return (/.string number/0'))]
+ [(list (/.number number/1)) (/.return (/.string number/1'))])
+ {.#Some (/.return (/.string number/2'))}))
+ (list)))
+ (expression (|>> (as Text) (text#= number/2'))
+ (/.apply (/.closure (list)
+ (/.switch (/.number number/2)
+ (list [(list (/.number number/0)) (/.return (/.string number/0'))]
+ [(list (/.number number/1)) (/.return (/.string number/1'))])
+ {.#Some (/.return (/.string number/2'))}))
+ (list)))
+ )))
+ )))
+
+(def test|statement
+ Test
+ (do [! random.monad]
+ [number/0 random.safe_frac
+ number/1 random.safe_frac
+ number/2 random.safe_frac
+ $arg/0 (of ! each /.var (random.lower_cased 10))
+ $arg/1 (of ! each /.var (random.lower_cased 11))
+ $arg/2 (of ! each /.var (random.lower_cased 12))
+ ??? random.bit
+ int ..int_16]
+ (`` (all _.and
+ (_.coverage [/.statement]
+ (expression (|>> (as Frac) (f.= number/0))
+ (/.apply_1 (/.closure (list $arg/0)
+ (all /.then
+ (/.statement (/.+ $arg/0 $arg/0))
+ (/.return $arg/0)))
+ (/.number number/0))))
+ (,, (with_template [<js> <lux>]
+ [(_.coverage [<js>]
+ (expression (|>> (as Frac) f.int (i.= (<lux> int)))
+ (/.apply_1 (/.closure (list $arg/0)
+ (/.return (/., (<js> $arg/0)
+ $arg/0)))
+ (/.int int))))]
+
+ [/.++ .++]
+ [/.-- .--]
+ ))
+ (_.coverage [/.then]
+ (expression (|>> (as Frac) (f.= number/0))
+ (/.apply_2 (/.closure (list $arg/0 $arg/1)
+ (all /.then
+ (/.return $arg/0)
+ (/.return $arg/1)))
+ (/.number number/0)
+ (/.number number/1))))
+ (_.coverage [/.use_strict]
+ (and (expression (|>> (as Frac) (f.= number/0))
+ (/.apply (/.closure (list)
+ (all /.then
+ /.use_strict
+ (/.declare $arg/0)
+ (/.statement (/.set $arg/0 (/.number number/0)))
+ (/.return $arg/0)))
+ (list)))
+ (|> (/.apply (/.closure (list)
+ (all /.then
+ /.use_strict
+ ... (/.declare $arg/0)
+ (/.statement (/.set $arg/0 (/.number number/0)))
+ (/.return $arg/0)))
+ (list))
+ ..eval
+ (pipe.when
+ {try.#Success it}
+ false
+
+ {try.#Failure error}
+ true))))
+ ..test|exception
+ ..test|function
+ ..test|branching
+ (_.for [/.Location]
+ ..test/location)
+ (_.for [/.Loop]
+ ..test|loop)
+ ))))
+
+(def .public test
+ Test
+ (do [! random.monad]
+ []
+ (<| (_.covering /._)
+ (_.for [/.Code /.code])
+ (`` (all _.and
+ (_.for [/.Expression]
+ ..test|expression)
+ (_.for [/.Statement]
+ ..test|statement)
+ )))))