aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
authorEduardo Julian2022-02-17 04:41:44 -0400
committerEduardo Julian2022-02-17 04:41:44 -0400
commit99361f07e4dd5724611e13a91ba8f14f039cdf0c (patch)
treeb822c71adbd08b8ab911ba262d54b84c4f2d5b25 /stdlib/source/test
parentde8af6044d590354563f4ea8849d98e8637c034a (diff)
Finishing the meta-compiler [Part 3]
Diffstat (limited to '')
-rw-r--r--stdlib/source/test/lux/target/python.lux107
-rw-r--r--stdlib/source/test/lux/tool.lux4
-rw-r--r--stdlib/source/test/lux/tool/compiler/meta/context.lux45
3 files changed, 140 insertions, 16 deletions
diff --git a/stdlib/source/test/lux/target/python.lux b/stdlib/source/test/lux/target/python.lux
index 45eae7e38..3908f9d3c 100644
--- a/stdlib/source/test/lux/target/python.lux
+++ b/stdlib/source/test/lux/target/python.lux
@@ -1,8 +1,9 @@
(.using
[library
- [lux "*"
+ [lux {"-" exec}
["_" test {"+" Test}]
["[0]" ffi]
+ ["[0]" static]
[abstract
[monad {"+" do}]
["[0]" predicate]
@@ -10,6 +11,7 @@
["$[0]" equivalence]
["$[0]" hash]]]
[control
+ [pipe {"+" case>}]
["[0]" function]
["[0]" maybe ("[1]#[0]" functor)]
["[0]" try {"+" Try} ("[1]#[0]" functor)]]
@@ -19,6 +21,8 @@
["%" format {"+" format}]]
[collection
["[0]" list ("[1]#[0]" functor)]]]
+ [macro
+ ["[0]" code]]
["[0]" math
["[0]" random {"+" Random} ("[1]#[0]" monad)]
[number
@@ -27,7 +31,7 @@
["f" frac]
["[0]" i64]]]]]
[\\library
- ["[0]" /]])
+ ["[0]" / ("[1]#[0]" equivalence)]])
(ffi.import: (eval [Text] "try" "?" Any))
@@ -46,7 +50,7 @@
[bool random.bit
float random.frac
int random.int
- string (random.ascii/upper 5)]
+ string (random.ascii/upper 1)]
($_ _.and
(_.cover [/.none]
(|> /.none
@@ -257,7 +261,9 @@
float (random.only (|>> f.not_a_number? not) random.frac)
string (random.ascii/upper 5)
- comment (random.ascii/upper 10)]
+ comment (random.ascii/upper 10)
+ $arg/0 (# ! each /.var (random.ascii/lower 10))
+ $arg/1 (# ! each /.var (random.ascii/lower 11))]
($_ _.and
..test|bool
..test|float
@@ -282,6 +288,16 @@
(expression (|>> (:as Frac) (f.= (math.ceil float)))
(|> (/.__import__/1 (/.string "math"))
(/.do "ceil" (list (/.float float))))))
+ (_.cover [/.is]
+ (and (expression (|>> (:as Bit))
+ (/.apply/* (/.lambda (list $arg/0)
+ (/.is $arg/0 $arg/0))
+ (list (/.string (format string string)))))
+ (expression (|>> (:as Bit) not)
+ (/.apply/* (/.lambda (list $arg/0 $arg/1)
+ (/.is $arg/0 (/.+ $arg/1 $arg/1)))
+ (list (/.string (format string string))
+ (/.string string))))))
)))
(def: test|function
@@ -344,13 +360,24 @@
(expression (|>> (:as Frac) (f.= expected/0))
(/.apply/* (/.lambda (list $var) $var)
(list (/.float expected/0)))))
- (_.cover [/.Poly /.PVar /.poly]
- (expression (|>> (:as Frac) (f.= expected/?))
- (/.apply/* (/.lambda (list $choice (/.poly $var))
- (/.item $choice $var))
- (list (/.int (.int poly_choice))
- (/.float expected/0)
- (/.float expected/1)))))
+ (_.for [/.Poly /.PVar]
+ ($_ _.and
+ (_.cover [/.poly]
+ (expression (|>> (:as Frac) (f.= expected/?))
+ (/.apply/* (/.lambda (list $choice (/.poly $var))
+ (/.item $choice $var))
+ (list (/.int (.int poly_choice))
+ (/.float expected/0)
+ (/.float expected/1)))))
+ (_.cover [/.splat_poly]
+ (expression (|>> (:as Frac) (f.= expected/?))
+ (/.apply/* (/.lambda (list $choice (/.poly $var))
+ (/.item $choice $var))
+ (list (/.int (.int poly_choice))
+ (/.splat_poly
+ (/.list (list (/.float expected/0)
+ (/.float expected/1))))))))
+ ))
(_.for [/.Keyword /.KVar]
($_ _.and
(_.cover [/.keyword]
@@ -387,18 +414,68 @@
..test|var)
))))
+(ffi.import: Dict
+ ["[1]::[0]"
+ (get [ffi.String] Any)])
+
+(ffi.import: (dict [] ..Dict))
+
+(def: (statement it)
+ (-> (-> /.SVar (/.Statement Any)) Any)
+ (let [$output (static.random (|>> %.nat (format "output_") code.text)
+ random.nat)
+ environment (..dict [])]
+ (.exec
+ ("python exec" (/.code (it (/.var $output))) (:expected environment))
+ (Dict::get [$output] environment))))
+
+(def: test|statement
+ Test
+ (do [! random.monad]
+ [prefix (# ! each (|>> %.nat (text.enclosed ["def_" "_"])) random.nat)
+ $input/0 (# ! each (|>> %.nat (format "input_") /.var) random.nat)
+ expected/0 random.safe_frac
+ .let [def (: (-> Nat /.SVar)
+ (|>> %.nat (format prefix) /.var))]]
+ ($_ _.and
+ (_.cover [/.def]
+ (|> (..statement
+ (function (_ $output)
+ ($_ /.then
+ (/.def (def 0) (list $input/0) (/.return $input/0))
+ (/.set (list $output)
+ (/.apply/* (def 0) (list (/.float expected/0)))))))
+ (:as Frac)
+ (f.= expected/0)))
+ )))
+
+(def: random_expression
+ (Random /.Literal)
+ ($_ random.either
+ (random#each /.bool random.bit)
+ (random#each /.float random.frac)
+ (random#each /.int random.int)
+ (random#each /.string (random.ascii/lower 1))
+ ))
+
(def: .public test
Test
(do [! random.monad]
- [.let [random (# ! each /.int random.int)]]
+ [expected ..random_expression]
(<| (_.covering /._)
- (_.for [/.Code /.code])
+ (_.for [/.Code])
($_ _.and
(_.for [/.equivalence]
- ($equivalence.spec /.equivalence random))
+ ($equivalence.spec /.equivalence ..random_expression))
(_.for [/.hash]
- ($hash.spec /.hash random))
+ ($hash.spec /.hash ..random_expression))
+ (_.cover [/.code /.manual]
+ (|> (/.manual (/.code expected))
+ (: /.Expression)
+ (/#= expected)))
(_.for [/.Expression]
..test|expression)
+ (_.for [/.Statement]
+ ..test|statement)
))))
diff --git a/stdlib/source/test/lux/tool.lux b/stdlib/source/test/lux/tool.lux
index 8c154b3a0..07824362b 100644
--- a/stdlib/source/test/lux/tool.lux
+++ b/stdlib/source/test/lux/tool.lux
@@ -25,7 +25,8 @@
["[1]/[0]" archive]
["[1]/[0]" cli]
["[1]/[0]" export]
- ["[1]/[0]" import]]
+ ["[1]/[0]" import]
+ ["[1]/[0]" context]]
]])
(def: .public test
@@ -40,6 +41,7 @@
/meta/cli.test
/meta/export.test
/meta/import.test
+ /meta/context.test
/phase/extension.test
/phase/analysis/simple.test
/phase/analysis/complex.test
diff --git a/stdlib/source/test/lux/tool/compiler/meta/context.lux b/stdlib/source/test/lux/tool/compiler/meta/context.lux
new file mode 100644
index 000000000..382bd12d6
--- /dev/null
+++ b/stdlib/source/test/lux/tool/compiler/meta/context.lux
@@ -0,0 +1,45 @@
+(.using
+ [library
+ [lux "*"
+ ["_" test {"+" Test}]
+ [abstract
+ [monad {"+" do}]]
+ [data
+ ["[0]" text]
+ [collection
+ ["[0]" set]
+ ["[0]" list ("[1]#[0]" functor)]]]
+ [math
+ ["[0]" random]
+ [number
+ ["n" nat]]]]]
+ [\\library
+ ["[0]" /]])
+
+(def: .public test
+ Test
+ (<| (_.covering /._)
+ (_.for [/.Context /.Extension])
+ (do [! random.monad]
+ [target (random.ascii/lower 1)]
+ ($_ _.and
+ (_.cover [/.js /.jvm /.lua /.python /.ruby]
+ (let [contexts (list (/.js target)
+ (/.jvm target)
+ (/.lua target)
+ (/.python target)
+ (/.ruby target))
+ maximum (list.size contexts)]
+ (`` (and (~~ (template [<amount> <slot>]
+ [(|> contexts
+ (list#each (value@ <slot>))
+ (set.of_list text.hash)
+ set.size
+ (n.= <amount>))]
+
+ [maximum /.#host]
+ [maximum /.#host_module_extension]
+ [maximum /.#artifact_extension]
+ [1 /.#target]
+ ))))))
+ ))))