aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux.lux
diff options
context:
space:
mode:
authorEduardo Julian2022-01-28 06:23:41 -0400
committerEduardo Julian2022-01-28 06:23:41 -0400
commit805309298575cef550749199374e853091f973b3 (patch)
treeaa6ab7e1f642a220b9bc1078018b98648452ea0d /stdlib/source/test/lux.lux
parentfe0d9fc74740f1b51e2f498d4516579d3e48ed02 (diff)
Better detection for "exec" optimization.
Diffstat (limited to 'stdlib/source/test/lux.lux')
-rw-r--r--stdlib/source/test/lux.lux293
1 files changed, 198 insertions, 95 deletions
diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux
index 631f754e4..2b72f6dad 100644
--- a/stdlib/source/test/lux.lux
+++ b/stdlib/source/test/lux.lux
@@ -4,6 +4,7 @@
[program {"+" program:}]
["_" test {"+" Test}]
["@" target]
+ ["[0]" static]
[abstract
[monad {"+" do}]]
[control
@@ -37,7 +38,7 @@
["r" rev]
["f" frac]
["[0]" i64]]]
- ["[0]" meta
+ ["[0]" meta ("[1]#[0]" monad)
["[0]" location ("[1]#[0]" equivalence)]]]]
... TODO: Must have 100% coverage on tests.
["[0]" / "_"
@@ -47,8 +48,7 @@
["[1][0]" debug]
["[1][0]" documentation]
["[1][0]" locale]
- ["[1][0]" macro
- ["[1]/[0]" code]]
+ ["[1][0]" macro]
["[1][0]" math]
["[1][0]" meta]
["[1][0]" program]
@@ -68,47 +68,7 @@
"Lua" (~~ (.as_is ["[1]/[0]" lua]))
"Python" (~~ (.as_is ["[1]/[0]" python]))
"Ruby" (~~ (.as_is ["[1]/[0]" ruby]))]
- (~~ (.as_is))))]
- ])))
-
-... TODO: Get rid of this ASAP
-(template: (!bundle body)
- [(: Test
- (do random.monad
- [_ (in [])]
- body))])
-
-(def: sub_tests
- Test
- (`` (`` (_.in_parallel (list /abstract.test
- /control.test
- /data.test
- /debug.test
- /documentation.test
- /locale.test
- /macro.test
- /math.test
- /meta.test
- /program.test
- /static.test
- /target.test
- /test.test
- /time.test
- /tool.test
- /type.test
- /world.test
- /ffi.test
- ... TODO: Update & expand tests for this
- (~~ (for [@.jvm (~~ (as_is /target/jvm.test))
- @.old (~~ (as_is /target/jvm.test))
- @.js (~~ (as_is /target/js.test))
- @.lua (~~ (as_is /target/lua.test))
- @.python (~~ (as_is /target/python.test))
- @.ruby (~~ (as_is /target/ruby.test))]
- (~~ (as_is))))
- (~~ (for [@.old (~~ (as_is))]
- (~~ (as_is /extension.test))))
- )))))
+ (~~ (.as_is))))]])))
(def: for_bit
Test
@@ -400,9 +360,8 @@
(def: for_code
Test
- (do random.monad
- [example_nat random.nat
- example /macro/code.random]
+ (do [! random.monad]
+ [example (# ! each code.nat random.nat)]
($_ _.and
(_.for [/.Code /.Code']
($_ _.and
@@ -426,6 +385,22 @@
(let [[_ _ source_code] (value@ .#source lux)]
{.#Right [lux (list (code.bit (text.contains? ..crosshair source_code)))]}))
+(/.macro: (sum tokens)
+ (loop [tokens tokens
+ output 0]
+ (case tokens
+ {.#End}
+ (meta#in (list (code.nat output)))
+
+ {.#Item [_ {.#Nat head}] tail}
+ (again tail (n.+ head output))
+
+ _
+ (meta.failure ""))))
+
+(/.macro: (sum' tokens lux)
+ ((/.macro ..sum) tokens lux))
+
(def: for_macro
Test
(let [macro (: /.Macro'
@@ -433,24 +408,118 @@
{.#Right [lux (list)]}))]
(do random.monad
[expected random.nat]
- (with_expansions [<found_crosshair?> (for [@.old (~~ (as_is))]
- (_.cover [/.Source]
- (..found_crosshair?)))]
- (`` ($_ _.and
- (_.cover [/.Macro']
- (|> macro
- (: /.Macro')
- (same? macro)))
- (_.cover [/.Macro]
- (|> macro
- "lux macro"
- (: /.Macro)
- (: Any)
- (same? (: Any macro))))
- (_.cover [/.macro:]
- (same? expected (..identity_macro expected)))
- <found_crosshair?>
- ))))))
+ (`` (`` ($_ _.and
+ (_.cover [/.Macro']
+ (|> macro
+ (: /.Macro')
+ (same? macro)))
+ (_.cover [/.Macro]
+ (|> macro
+ "lux macro"
+ (: /.Macro)
+ (: Any)
+ (same? (: Any macro))))
+ (_.cover [/.macro:]
+ (same? expected (..identity_macro expected)))
+ (~~ (for [@.old (~~ (as_is))]
+ (_.cover [/.Source]
+ (..found_crosshair?))))
+ (_.cover [/.macro]
+ (with_expansions [n/0 (static.random_nat)
+ n/1 (static.random_nat)
+ n/1 (static.random_nat)]
+ (n.= (..sum n/0 n/1 n/1)
+ (..sum' n/0 n/1 n/1))))
+ (_.cover [/.using]
+ (with_expansions [<referral> ("lux in-module" "library/lux" library/lux.refer)
+ <alias> (static.random code.text (random.ascii/lower 1))
+ <definition> (static.random code.local_symbol (random.ascii/lower 1))
+ <module/0> (static.random code.text (random.ascii/lower 2))
+ <module/0>' (template.symbol [<module/0>])
+ <module/1> (static.random code.text (random.ascii/lower 3))
+ <module/1>' (template.symbol [<module/1>])
+ <module/2> (static.random code.text (random.ascii/lower 4))
+ <module/2>' (template.symbol [<module/2>])
+ <m0/1> (template.text [<module/0> "/" <module/1>])
+ <//> (template.text [// <module/2>'])
+ <//>' (template.symbol [<//>])
+ <\\> (template.text [\\ <module/2>'])
+ <\\>' (template.symbol [<\\>])
+ <m0/2> (template.text [<module/0> "/" <module/2>])
+ <m2/1> (template.text [<module/2> "/" <module/1>])
+ <m0/1/2> (template.text [<module/0> "/" <module/1> "/" <module/2>])
+ <open/0> (template.text [<module/0> "#[0]"])]
+ (and (~~ (template [<input> <pattern>]
+ [(with_expansions [<input>' (macro.final <input>)]
+ (case (' [<input>'])
+ (^code <pattern>)
+ true
+
+ _
+ false))]
+
+ [(.using [<module/0>'])
+ [("lux def module" [])]]
+
+ [(.using [<alias> <module/0>' "*"])
+ [("lux def module" [[<module/0> <alias>]])
+ (<referral> <module/0> "*")]]
+
+ [(.using [<alias> <module/0>' {"+" <definition>}])
+ [("lux def module" [[<module/0> <alias>]])
+ (<referral> <module/0> {"+" <definition>})]]
+
+ [(.using [<alias> <module/0>' {"-" <definition>}])
+ [("lux def module" [[<module/0> <alias>]])
+ (<referral> <module/0> {"-" <definition>})]]
+
+ [(.using [<alias> <module/0>' "_"])
+ [("lux def module" [])]]
+
+ [(.using [<module/0>'
+ [<alias> <module/1>']])
+ [("lux def module" [[<m0/1> <alias>]])
+ (<referral> <m0/1>)]]
+
+ [(.using ["[0]" <module/0>'
+ ["[0]" <module/1>']])
+ [("lux def module" [[<module/0> <module/0>]
+ [<m0/1> <module/1>]])
+ (<referral> <module/0>)
+ (<referral> <m0/1>)]]
+
+ [(.using ["[0]" <module/0>' "_"
+ ["[1]" <module/1>']])
+ [("lux def module" [[<m0/1> <module/0>]])
+ (<referral> <m0/1>)]]
+
+ [(.using ["[0]" <module/0>' "_"
+ ["[1]" <module/1>' "_"
+ ["[2]" <module/2>']]])
+ [("lux def module" [[<m0/1/2> <module/0>]])
+ (<referral> <m0/1/2>)]]
+
+ [(.using [<module/0>'
+ ["[0]" <module/1>'
+ ["[0]" <//>']]])
+ [("lux def module" [[<m0/1> <module/1>]
+ [<m0/2> <//>]])
+ (<referral> <m0/1>)
+ (<referral> <m0/2>)]]
+
+ [(.using ["[0]" <module/0>'
+ [<module/1>'
+ ["[0]" <\\>']]])
+ [("lux def module" [[<module/0> <module/0>]
+ [<m2/1> <\\>]])
+ (<referral> <module/0>)
+ (<referral> <m2/1>)]]
+
+ [(.using ["[0]" <module/0>' ("[1]#[0]" <definition>)])
+ [("lux def module" [[<module/0> <module/0>]])
+ (<referral> <module/0> (<open/0> <definition>))]]
+ )))))
+ ))))))
(/.type: for_type/variant
(Variant
@@ -1175,39 +1244,73 @@
verdict)))
0 1 2))))
+(def: test|lux
+ Test
+ (`` (`` ($_ _.and
+ ..for_bit
+ ..for_try
+ ..for_list
+ ..for_interface
+ ..for_module
+ ..for_pipe
+ ..for_code
+ ..for_macro
+ ..for_type
+ ..for_i64
+ ..for_function
+ ..for_template
+ ..for_static
+ ..for_slot
+ ..for_associative
+ ..for_expansion
+ ..for_value
+ ..for_case
+ ..for_control_flow
+ ..for_def:
+ ..for_meta
+ ..for_export
+ (~~ (for [@.old (~~ (as_is))]
+ (~~ (as_is ..for_bindings))))
+ ))))
+
(def: test
Test
(<| (_.covering /._)
- (with_expansions
- [<for_bindings> (for [@.old (~~ (as_is))]
- (~~ (as_is ..for_bindings)))]
- (`` ($_ _.and
- ..for_bit
- ..for_try
- ..for_list
- ..for_interface
- ..for_module
- ..for_pipe
- ..for_code
- ..for_macro
- ..for_type
- ..for_i64
- ..for_function
- ..for_template
- ..for_static
- ..for_slot
- ..for_associative
- ..for_expansion
- ..for_value
- ..for_case
- ..for_control_flow
- ..for_def:
- ..for_meta
- ..for_export
- <for_bindings>
-
- ..sub_tests
- )))))
+ (`` (`` (_.in_parallel
+ (list ..test|lux
+
+ /abstract.test
+ /control.test
+ /data.test
+ /debug.test
+
+ /documentation.test
+ /locale.test
+ /macro.test
+ /math.test
+
+ /meta.test
+ /program.test
+ /static.test
+ /target.test
+
+ /test.test
+ /time.test
+ /tool.test
+ /type.test
+
+ /world.test
+ /ffi.test
+
+ (~~ (for [@.old (~~ (as_is))]
+ (~~ (as_is /extension.test))))
+ (~~ (for [@.jvm (~~ (as_is /target/jvm.test))
+ @.old (~~ (as_is /target/jvm.test))
+ @.js (~~ (as_is /target/js.test))
+ @.lua (~~ (as_is /target/lua.test))
+ @.python (~~ (as_is /target/python.test))
+ @.ruby (~~ (as_is /target/ruby.test))]))
+ ))))))
(program: args
(let [times (for [@.old 100