From 805309298575cef550749199374e853091f973b3 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 28 Jan 2022 06:23:41 -0400 Subject: Better detection for "exec" optimization. --- stdlib/source/test/lux.lux | 293 ++++++++++++++++++++++++++++++--------------- 1 file changed, 198 insertions(+), 95 deletions(-) (limited to 'stdlib/source/test/lux.lux') 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 [ (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))) - - )))))) + (`` (`` ($_ _.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 [ ("lux in-module" "library/lux" library/lux.refer) + (static.random code.text (random.ascii/lower 1)) + (static.random code.local_symbol (random.ascii/lower 1)) + (static.random code.text (random.ascii/lower 2)) + ' (template.symbol []) + (static.random code.text (random.ascii/lower 3)) + ' (template.symbol []) + (static.random code.text (random.ascii/lower 4)) + ' (template.symbol []) + (template.text [ "/" ]) + (template.text [// ']) + ' (template.symbol []) + <\\> (template.text [\\ ']) + <\\>' (template.symbol [<\\>]) + (template.text [ "/" ]) + (template.text [ "/" ]) + (template.text [ "/" "/" ]) + (template.text [ "#[0]"])] + (and (~~ (template [ ] + [(with_expansions [' (macro.final )] + (case (' [']) + (^code ) + true + + _ + false))] + + [(.using [']) + [("lux def module" [])]] + + [(.using [ ' "*"]) + [("lux def module" [[ ]]) + ( "*")]] + + [(.using [ ' {"+" }]) + [("lux def module" [[ ]]) + ( {"+" })]] + + [(.using [ ' {"-" }]) + [("lux def module" [[ ]]) + ( {"-" })]] + + [(.using [ ' "_"]) + [("lux def module" [])]] + + [(.using [' + [ ']]) + [("lux def module" [[ ]]) + ( )]] + + [(.using ["[0]" ' + ["[0]" ']]) + [("lux def module" [[ ] + [ ]]) + ( ) + ( )]] + + [(.using ["[0]" ' "_" + ["[1]" ']]) + [("lux def module" [[ ]]) + ( )]] + + [(.using ["[0]" ' "_" + ["[1]" ' "_" + ["[2]" ']]]) + [("lux def module" [[ ]]) + ( )]] + + [(.using [' + ["[0]" ' + ["[0]" ']]]) + [("lux def module" [[ ] + [ ]]) + ( ) + ( )]] + + [(.using ["[0]" ' + [' + ["[0]" <\\>']]]) + [("lux def module" [[ ] + [ <\\>]]) + ( ) + ( )]] + + [(.using ["[0]" ' ("[1]#[0]" )]) + [("lux def module" [[ ]]) + ( ( ))]] + ))))) + )))))) (/.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 [@.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 - - - ..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 -- cgit v1.2.3