aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test')
-rw-r--r--stdlib/source/test/lux/target/python.lux212
-rw-r--r--stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/complex.lux3
-rw-r--r--stdlib/source/test/lux/tool/compiler/meta/cache.lux8
-rw-r--r--stdlib/source/test/lux/tool/compiler/meta/cache/module.lux92
4 files changed, 259 insertions, 56 deletions
diff --git a/stdlib/source/test/lux/target/python.lux b/stdlib/source/test/lux/target/python.lux
index bb601a007..0d9fb493a 100644
--- a/stdlib/source/test/lux/target/python.lux
+++ b/stdlib/source/test/lux/target/python.lux
@@ -248,6 +248,11 @@
(_.cover [/.dict]
(expression (|>> (:as Frac) (f.= expected))
(/.item field (/.dict (list [field (/.float expected)])))))
+ (_.cover [/.in?]
+ (and (expression (|>> (:as Bit) not)
+ (/.in? (/.dict (list)) field))
+ (expression (|>> (:as Bit))
+ (/.in? (/.dict (list [field (/.float expected)])) field))))
)))
(def: test|computation
@@ -290,14 +295,14 @@
(/.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)))))
+ (/.apply/* (list (/.string (format string string)))
+ (/.lambda (list $arg/0)
+ (/.is $arg/0 $arg/0))))
(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))))))
+ (/.apply/* (list (/.string (format string string))
+ (/.string string))
+ (/.lambda (list $arg/0 $arg/1)
+ (/.is $arg/0 (/.+ $arg/1 $arg/1)))))))
)))
(def: test|function
@@ -312,32 +317,14 @@
($_ _.and
(_.cover [/.lambda]
(expression (|>> (:as Frac) (f.= float/0))
- (/.apply/* (/.lambda (list)
- (/.float float/0))
- (list))))
- (_.cover [/.apply/1]
- (expression (|>> (:as Frac) (f.= float/0))
- (/.apply/1 (/.lambda (list $arg/0)
- $arg/0)
- (/.float float/0))))
- (_.cover [/.apply/2]
- (expression (|>> (:as Frac) (f.= ($_ f.+ float/0 float/1)))
- (/.apply/2 (/.lambda (list $arg/0 $arg/1)
- ($_ /.+ $arg/0 $arg/1))
- (/.float float/0)
- (/.float float/1))))
- (_.cover [/.apply/3]
- (expression (|>> (:as Frac) (f.= ($_ f.+ float/0 float/1 float/2)))
- (/.apply/3 (/.lambda (list $arg/0 $arg/1 $arg/2)
- ($_ /.+ $arg/0 $arg/1 $arg/2))
- (/.float float/0)
- (/.float float/1)
- (/.float float/2))))
+ (/.apply/* (list)
+ (/.lambda (list)
+ (/.float float/0)))))
(_.cover [/.apply/*]
(expression (|>> (:as Frac) (f.= ($_ f.+ float/0 float/1 float/2)))
- (/.apply/* (/.lambda (list $arg/0 $arg/1 $arg/2)
- ($_ /.+ $arg/0 $arg/1 $arg/2))
- (list (/.float float/0) (/.float float/1) (/.float float/2)))))
+ (/.apply/* (list (/.float float/0) (/.float float/1) (/.float float/2))
+ (/.lambda (list $arg/0 $arg/1 $arg/2)
+ ($_ /.+ $arg/0 $arg/1 $arg/2)))))
)))
(def: test|var
@@ -358,44 +345,44 @@
($_ _.and
(_.cover [/.Single /.SVar /.var]
(expression (|>> (:as Frac) (f.= expected/0))
- (/.apply/* (/.lambda (list $var) $var)
- (list (/.float expected/0)))))
+ (/.apply/* (list (/.float expected/0))
+ (/.lambda (list $var) $var))))
(_.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))
+ (/.apply/* (list (/.int (.int poly_choice))
(/.float expected/0)
- (/.float expected/1)))))
+ (/.float expected/1))
+ (/.lambda (list $choice (/.poly $var))
+ (/.item $choice $var)))))
(_.cover [/.splat_poly]
(expression (|>> (:as Frac) (f.= expected/?))
- (/.apply/* (/.lambda (list $choice (/.poly $var))
- (/.item $choice $var))
- (list (/.int (.int poly_choice))
+ (/.apply/* (list (/.int (.int poly_choice))
(/.splat_poly
(/.list (list (/.float expected/0)
- (/.float expected/1))))))))
+ (/.float expected/1)))))
+ (/.lambda (list $choice (/.poly $var))
+ (/.item $choice $var)))))
))
(_.for [/.Keyword /.KVar]
($_ _.and
(_.cover [/.keyword]
(expression (|>> (:as Nat) (n.= 2))
- (/.apply/* (/.lambda (list $choice (/.keyword $var))
- (/.len/1 $var))
- (list keyword_choice
+ (/.apply/* (list keyword_choice
(/.splat_keyword
(/.dict (list [keyword/0 (/.float expected/0)]
- [keyword/1 (/.float expected/1)])))))))
+ [keyword/1 (/.float expected/1)]))))
+ (/.lambda (list $choice (/.keyword $var))
+ (/.len/1 $var)))))
(_.cover [/.splat_keyword]
(expression (|>> (:as Frac) (f.= expected/?))
- (/.apply/* (/.lambda (list $choice (/.keyword $var))
- (/.item $choice $var))
- (list keyword_choice
+ (/.apply/* (list keyword_choice
(/.splat_keyword
(/.dict (list [keyword/0 (/.float expected/0)]
- [keyword/1 (/.float expected/1)])))))))
+ [keyword/1 (/.float expected/1)]))))
+ (/.lambda (list $choice (/.keyword $var))
+ (/.item $choice $var)))))
))
)))
@@ -429,6 +416,123 @@
("python exec" (/.code (it (/.var $output))) (:expected environment))
(Dict::get [$output] environment))))
+(def: test|access
+ Test
+ (do [! random.monad]
+ [$var/0 (# ! each (|>> %.nat (format "v0_") /.var) random.nat)
+ expected/0 random.safe_frac
+ dummy/0 random.safe_frac
+ field (# ! each /.string (random.ascii/upper 1))]
+ ($_ _.and
+ (_.cover [/.item]
+ (`` (and (~~ (template [<seq>]
+ [(expression (|>> (:as Frac) (f.= expected/0))
+ (/.item (/.int +0)
+ (<seq> (list (/.float expected/0)))))]
+
+ [/.list]
+ [/.tuple]
+ ))
+ (|> (..statement
+ (function (_ $output)
+ ($_ /.then
+ (/.set (list $var/0) (/.list (list (/.float dummy/0))))
+ (/.set (list (/.item (/.int +0) $var/0)) (/.float expected/0))
+ (/.set (list $output) (/.item (/.int +0) $var/0)))))
+ (:as Frac)
+ (f.= expected/0))
+
+ (expression (|>> (:as Frac) (f.= expected/0))
+ (/.item field (/.dict (list [field (/.float expected/0)]))))
+ (|> (..statement
+ (function (_ $output)
+ ($_ /.then
+ (/.set (list $var/0) (/.dict (list [field (/.float dummy/0)])))
+ (/.set (list (/.item field $var/0)) (/.float expected/0))
+ (/.set (list $output) (/.item field $var/0)))))
+ (:as Frac)
+ (f.= expected/0)))))
+ )))
+
+(def: test|location
+ Test
+ (do [! random.monad]
+ [$var/0 (# ! each (|>> %.nat (format "v0_") /.var) random.nat)
+ $var/1 (# ! each (|>> %.nat (format "v1_") /.var) random.nat)
+ expected/0 random.safe_frac
+ expected/1 random.safe_frac
+ dummy/0 random.safe_frac
+ field/0 (# ! each /.string (random.ascii/upper 1))]
+ ($_ _.and
+ (_.cover [/.set]
+ (|> (..statement
+ (function (_ $output)
+ ($_ /.then
+ (/.set (list $var/0) (/.float expected/0))
+ (/.set (list $output) $var/0))))
+ (:as Frac)
+ (f.= expected/0)))
+ (_.cover [/.multi]
+ (`` (and (~~ (template [<var> <value>]
+ [(|> (..statement
+ (function (_ $output)
+ ($_ /.then
+ (/.set (list $var/0 $var/1) (/.multi (list (/.float expected/0) (/.float expected/1))))
+ (/.set (list $output) <var>))))
+ (:as Frac)
+ (f.= <value>))]
+
+ [$var/0 expected/0]
+ [$var/1 expected/1]
+ )))))
+ (_.cover [/.delete]
+ (and (|> (..statement
+ (function (_ $output)
+ ($_ /.then
+ (/.set (list $var/0) (/.list (list (/.float dummy/0) (/.float expected/0))))
+ (/.delete (/.item (/.int +0) $var/0))
+ (/.set (list $output) (/.item (/.int +0) $var/0)))))
+ (:as Frac)
+ (f.= expected/0))
+ (|> (..statement
+ (function (_ $output)
+ ($_ /.then
+ (/.set (list $var/0) (/.list (list (/.float dummy/0) (/.float expected/0))))
+ (/.delete (/.slice (/.int +0) (/.int +1) $var/0))
+ (/.set (list $output) (/.item (/.int +0) $var/0)))))
+ (:as Frac)
+ (f.= expected/0))
+ (|> (..statement
+ (function (_ $output)
+ ($_ /.then
+ (/.set (list $var/0) (/.list (list (/.float dummy/0) (/.float dummy/0))))
+ (/.delete (/.slice_from (/.int +0) $var/0))
+ (/.statement (/.do "append" (list (/.float expected/0)) $var/0))
+ (/.set (list $output) (/.item (/.int +0) $var/0)))))
+ (:as Frac)
+ (f.= expected/0))
+ (|> (..statement
+ (function (_ $output)
+ ($_ /.then
+ (/.set (list $var/0) (/.dict (list [field/0 (/.float dummy/0)])))
+ (/.delete (/.item field/0 $var/0))
+ (/.set (list $output) (/.in? $var/0 field/0)))))
+ (:as Bit)
+ not)
+ (|> (..statement
+ (function (_ $output)
+ ($_ /.then
+ (/.set (list $var/0) (/.float dummy/0))
+ (/.delete $var/0)
+ (/.set (list $output) (/.or (/.in? /.locals/0 (/.string (/.code $var/0)))
+ (/.in? /.globals/0 (/.string (/.code $var/0))))))))
+ (:as Bit)
+ not)
+ ))
+ (_.for [/.Access]
+ ..test|access)
+ )))
+
(def: test|statement
Test
(do [! random.monad]
@@ -446,7 +550,7 @@
($_ /.then
(/.def $def (list $input/0)
(/.return $input/0))
- (/.set (list $output) (/.apply/* $def (list (/.float expected/0)))))))
+ (/.set (list $output) (/.apply/* (list (/.float expected/0)) $def)))))
(:as Frac)
(f.= expected/0)))
(_.cover [/.if]
@@ -457,7 +561,7 @@
(/.if (/.bool test)
(/.return (/.float then))
(/.return (/.float else))))
- (/.set (list $output) (/.apply/* $def (list))))))
+ (/.set (list $output) (/.apply/* (list) $def)))))
(:as Frac)
(f.= expected/?)))
(_.cover [/.when /.then]
@@ -469,7 +573,7 @@
(/.when (/.bool test)
(/.return (/.float then)))
(/.return (/.float else))))
- (/.set (list $output) (/.apply/* $def (list))))))
+ (/.set (list $output) (/.apply/* (list) $def)))))
(:as Frac)
(f.= expected/?)))
(_.cover [/.statement]
@@ -480,9 +584,11 @@
($_ /.then
(/.statement (/.+ (/.float expected/0) (/.float expected/0)))
(/.return (/.float expected/0))))
- (/.set (list $output) (/.apply/* $def (list))))))
+ (/.set (list $output) (/.apply/* (list) $def)))))
(:as Frac)
(f.= expected/0)))
+ (_.for [/.Location]
+ ..test|location)
)))
(def: random_expression
diff --git a/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/complex.lux b/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/complex.lux
index e7f6a5093..546aa1c39 100644
--- a/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/complex.lux
+++ b/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/complex.lux
@@ -369,7 +369,8 @@
(do !
[_ (//type.inference (Tuple type/0 type/1 varT))]
(/.product ..analysis archive.empty
- (list term/0 term/1 term/2 term/2 term/2))))]
+ (list term/0 term/1 term/2 term/2 term/2))))
+ :inferred: (//type.check (check.clean (list @var) :inferred:))]
(in (case analysis
(^ (//analysis.tuple (list analysis/0 analysis/1 (//analysis.tuple (list analysis/2 analysis/3 analysis/4)))))
(and (type#= (Tuple type/0 type/1 type/2 type/2 type/2)
diff --git a/stdlib/source/test/lux/tool/compiler/meta/cache.lux b/stdlib/source/test/lux/tool/compiler/meta/cache.lux
index 9ffcd4ada..d1c3c9249 100644
--- a/stdlib/source/test/lux/tool/compiler/meta/cache.lux
+++ b/stdlib/source/test/lux/tool/compiler/meta/cache.lux
@@ -14,8 +14,10 @@
["[0]" file]]]]
[\\library
["[0]" /]]
- ["$[0]" // "_"
- ["[1][0]" context]])
+ ["[0]" / "_"
+ ["[1][0]" module]
+ ["$/[1]" // "_"
+ ["[1][0]" context]]])
(def: .public test
Test
@@ -41,4 +43,6 @@
post/0
post/1))))
+
+ /module.test
))))
diff --git a/stdlib/source/test/lux/tool/compiler/meta/cache/module.lux b/stdlib/source/test/lux/tool/compiler/meta/cache/module.lux
new file mode 100644
index 000000000..98415b367
--- /dev/null
+++ b/stdlib/source/test/lux/tool/compiler/meta/cache/module.lux
@@ -0,0 +1,92 @@
+(.using
+ [library
+ [lux "*"
+ ["_" test {"+" Test}]
+ [abstract
+ [monad {"+" do}]]
+ [control
+ ["[0]" try]
+ ["[0]" exception]
+ [concurrency
+ ["[0]" async {"+" Async} ("[1]#[0]" monad)]]]
+ [math
+ ["[0]" random]]
+ [world
+ ["[0]" file]]]]
+ [\\library
+ ["[0]" /]]
+ ["$[0]" /// "_"
+ ["[1][0]" context]])
+
+(`` (implementation: (bad it)
+ (-> (file.System Async) (file.System Async))
+
+ (~~ (template [<name>]
+ [(def: <name>
+ (# it <name>))]
+
+ [separator]
+ [file?]
+ [directory?]
+ [modify]
+ [write]
+ [append]
+ [move]
+ [directory_files]
+ [sub_directories]
+ [file_size]
+ [last_modified]
+ [can_execute?]
+ [read]
+ [delete]
+ ))
+
+ (def: (make_directory path)
+ (async#in {try.#Failure ""}))
+ ))
+
+(def: .public test
+ Test
+ (<| (_.covering /._)
+ (do [! random.monad]
+ [.let [/ "/"
+ fs (file.mock /)]
+ context $///context.random
+ @module random.nat]
+ ($_ _.and
+ (in (do async.monad
+ [pre/0 (# fs directory? (/.path fs context @module))
+ pre/1 (/.enabled? fs context @module)
+ outcome (/.enable! fs context @module)
+ post/0 (# fs directory? (/.path fs context @module))
+ post/1 (/.enabled? fs context @module)]
+ (_.cover' [/.path /.enabled? /.enable!]
+ (and (not pre/0)
+ (not pre/1)
+
+ (case outcome
+ {try.#Success _} true
+ {try.#Failure _} false)
+
+ post/0
+ post/1))))
+ (in (do async.monad
+ [pre/0 (# fs directory? (/.path fs context @module))
+ pre/1 (/.enabled? fs context @module)
+ outcome (/.enable! (..bad fs) context @module)
+ post/0 (# fs directory? (/.path fs context @module))
+ post/1 (/.enabled? fs context @module)]
+ (_.cover' [/.cannot_enable]
+ (and (not pre/0)
+ (not pre/1)
+
+ (case outcome
+ {try.#Success _}
+ false
+
+ {try.#Failure error}
+ (exception.match? /.cannot_enable error))
+
+ (not post/0)
+ (not post/1)))))
+ ))))