From fc854233d2af07ed44a063a75a6900cc02616c74 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 18 Jan 2022 00:20:50 -0400 Subject: Fixes for the pure-Lux JVM compiler machinery. [Part 7] --- stdlib/source/test/lux/math/number.lux | 18 +- stdlib/source/test/lux/target/ruby.lux | 120 +++++++--- stdlib/source/test/lux/tool.lux | 10 +- .../tool/compiler/language/lux/phase/extension.lux | 265 +++++++++++++++++++++ 4 files changed, 360 insertions(+), 53 deletions(-) create mode 100644 stdlib/source/test/lux/tool/compiler/language/lux/phase/extension.lux (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/lux/math/number.lux b/stdlib/source/test/lux/math/number.lux index 94849f0c0..beaa84aa6 100644 --- a/stdlib/source/test/lux/math/number.lux +++ b/stdlib/source/test/lux/math/number.lux @@ -41,16 +41,14 @@ {try.#Failure error} false)] - [n.= n.binary "11001001"] [n.= n.binary "11,00,10,01"] - [i.= i.binary "+11001001"] + [i.= i.binary "+11,00,10,01"] [i.= i.binary "-11,00,10,01"] - [r.= r.binary ".11001001"] [r.= r.binary ".11,00,10,01"] - [f.= f.binary "+1100.1001"] + [f.= f.binary "+11,00.10,01"] [f.= f.binary "-11,00.10,01"] ))))) (_.cover [/.oct] @@ -62,16 +60,14 @@ {try.#Failure error} false)] - [n.= n.octal "615243"] [n.= n.octal "615,243"] - [i.= i.octal "+615243"] + [i.= i.octal "+615,243"] [i.= i.octal "-615,243"] - [r.= r.octal ".615243"] [r.= r.octal ".615,243"] - [f.= f.octal "+6152.43"] + [f.= f.octal "+61,52.43"] [f.= f.octal "-61,52.43"] ))))) (_.cover [/.hex] @@ -83,16 +79,14 @@ {try.#Failure error} false)] - [n.= n.hex "deadBEEF"] [n.= n.hex "dead,BEEF"] - [i.= i.hex "+deadBEEF"] + [i.= i.hex "+dead,BEEF"] [i.= i.hex "-dead,BEEF"] - [r.= r.hex ".deadBEEF"] [r.= r.hex ".dead,BEEF"] - [f.= f.hex "+dead.BEEF"] + [f.= f.hex "+dead,BE.EF"] [f.= f.hex "-dead,BE.EF"] ))))) diff --git a/stdlib/source/test/lux/target/ruby.lux b/stdlib/source/test/lux/target/ruby.lux index d48e16ecb..5e2cecbde 100644 --- a/stdlib/source/test/lux/target/ruby.lux +++ b/stdlib/source/test/lux/target/ruby.lux @@ -9,6 +9,7 @@ [\\specification ["$[0]" equivalence]]] [control + [pipe {"+" case>}] ["[0]" maybe ("[1]#[0]" functor)] ["[0]" try {"+" Try} ("[1]#[0]" functor)]] [data @@ -20,7 +21,7 @@ ["[0]" set]]] ["[0]" math ["[0]" random {"+" Random} ("[1]#[0]" monad)] - [number + [number {"+" hex} ["n" nat] ["i" int] ["f" frac] @@ -46,6 +47,14 @@ (maybe.else false))) (try.else false))) +(def: nil + (-> /.Expression Bit) + (|>> /.code + ..eval + (try#each (|>> (case> {.#None} true + {.#Some _} false))) + (try.else false))) + (def: test|literal Test (do [! random.monad] @@ -55,14 +64,7 @@ string (random.ascii/upper 5)] ($_ _.and (_.cover [/.nil] - (|> /.nil - /.code - ..eval - (try#each (function (_ it) - (case it - {.#None} true - {.#Some _} false))) - (try.else false))) + (..nil /.nil)) (_.cover [/.bool] (expression (|>> (:as Bit) (bit#= bool)) (/.bool bool))) @@ -398,6 +400,22 @@ (/.return $output)) [(list $input)] (/.lambda {.#None}) (/.apply_lambda/* (list (/.int input))))))) + (_.cover [/.redo] + (let [expected (i.* (.int (n.- expected_inner_iterations full_inner_iterations)) input)] + (expression (|>> (:as Frac) f.int (i.= expected)) + (|> ($_ /.then + (/.set (list $inner_index) (/.int +0)) + (/.set (list $output) (/.int +0)) + (/.while (/.< (/.int (.int full_inner_iterations)) $inner_index) + ($_ /.then + (/.set (list $inner_index) (/.+ (/.int +1) $inner_index)) + (/.when (/.<= (/.int (.int expected_inner_iterations)) $inner_index) + /.redo) + (/.set (list $output) (/.+ $input $output)) + )) + (/.return $output)) + [(list $input)] (/.lambda {.#None}) + (/.apply_lambda/* (list (/.int input))))))) ))) (def: test|loop @@ -435,17 +453,23 @@ ..test|label ))) +(def: random_tag + (Random Int) + (random#each (i64.and (hex "FF,FF,FF,FF")) + random.int)) + (def: test|exception Test (do [! random.monad] [expected random.safe_frac dummy (random.only (|>> (f.= expected) not) random.safe_frac) + error (random.ascii/lower 10) $ex (# ! each /.local (random.ascii/lower 10)) - expected_tag random.int + expected_tag ..random_tag dummy_tag (random.only (|>> (i.= expected_tag) not) - random.int) + ..random_tag) .let [expected_tag (/.int expected_tag) dummy_tag (/.int dummy_tag)]] ($_ _.and @@ -458,7 +482,7 @@ (_.cover [/.Rescue /.throw/1] (expression (|>> (:as Frac) (f.= expected)) (|> (/.begin ($_ /.then - (/.throw/1 (/.string "")) + (/.throw/1 (/.string error)) (/.return (/.float dummy))) (list [(list) $ex (/.return (/.float expected))])) [(list)] (/.lambda {.#None}) @@ -466,7 +490,7 @@ (_.cover [/.raise] (expression (|>> (:as Frac) (f.= expected)) (|> (/.begin ($_ /.then - (/.statement (/.raise (/.string ""))) + (/.statement (/.raise (/.string error))) (/.return (/.float dummy))) (list [(list) $ex (/.return (/.float expected))])) [(list)] (/.lambda {.#None}) @@ -492,6 +516,28 @@ (/.catch dummy_tag) [(list)] /.statement (/.catch expected_tag) [(list)] (/.throw/2 expected_tag (/.float expected)))))) + (_.cover [/.latest_error_message] + (expression (|>> (:as Text) (text#= error)) + (|> (/.begin ($_ /.then + (/.statement (/.raise (/.string error))) + (/.return (/.float dummy))) + (list [(list) $ex (/.return (/.the "message" /.latest_error_message))])) + [(list)] (/.lambda {.#None}) + (/.apply_lambda/* (list))))) + (_.cover [/.latest_error_location] + (and (|> (/.return /.latest_error_location) + [(list)] (/.lambda {.#None}) + (/.apply_lambda/* (list)) + ..nil) + (expression (|>> (:as Bit) (bit#= true)) + (|> (/.begin ($_ /.then + (/.statement (/.raise (/.string error))) + (/.return (/.float dummy))) + (list [(list) $ex (/.return ($_ /.and + (/.do "kind_of?" (list (/.local "Array")) {.#None} /.latest_error_location) + (/.> (/.int +0) (/.the "length" /.latest_error_location))))])) + [(list)] (/.lambda {.#None}) + (/.apply_lambda/* (list)))))) ))) (def: test|function @@ -625,30 +671,30 @@ (def: test|global Test - ($_ _.and - (_.cover [/.script_name] - (expression (let [file (format (# file.default separator) packager.main_file)] - (|>> (:as Text) - (predicate.or (text.ends_with? file) - (text#= "