aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test')
-rw-r--r--stdlib/source/test/lux/abstract.lux12
-rw-r--r--stdlib/source/test/lux/abstract/monad.lux8
-rw-r--r--stdlib/source/test/lux/abstract/monad/indexed.lux47
-rw-r--r--stdlib/source/test/lux/debug.lux75
-rw-r--r--stdlib/source/test/lux/ffi.py.lux8
-rw-r--r--stdlib/source/test/lux/meta/compiler/language/lux/analysis/coverage.lux2
-rw-r--r--stdlib/source/test/lux/meta/target/js.lux58
7 files changed, 161 insertions, 49 deletions
diff --git a/stdlib/source/test/lux/abstract.lux b/stdlib/source/test/lux/abstract.lux
index 5a3d4363a..e05272386 100644
--- a/stdlib/source/test/lux/abstract.lux
+++ b/stdlib/source/test/lux/abstract.lux
@@ -15,8 +15,7 @@
["[1][0]" functor (.only)
["[1]/[0]" contravariant]]
["[1][0]" interval]
- ["[1][0]" monad (.only)
- ["[1]/[0]" free]]
+ ["[1][0]" monad]
["[1][0]" monoid]
["[1][0]" order]])
@@ -27,13 +26,6 @@
/functor/contravariant.test
))
-(def monad
- Test
- (all _.and
- /monad.test
- /monad/free.test
- ))
-
(def comonad
Test
(all _.and
@@ -54,6 +46,6 @@
/monoid.test
/order.test
..functor
- ..monad
+ /monad.test
..comonad
))
diff --git a/stdlib/source/test/lux/abstract/monad.lux b/stdlib/source/test/lux/abstract/monad.lux
index 67f039fd6..f0ff7096c 100644
--- a/stdlib/source/test/lux/abstract/monad.lux
+++ b/stdlib/source/test/lux/abstract/monad.lux
@@ -12,7 +12,10 @@
[test
["_" property (.only Test)]]]]
[\\library
- ["[0]" / (.only Monad do)]])
+ ["[0]" / (.only Monad do)]]
+ ["[0]" /
+ ["[1][0]" free]
+ ["[1][0]" indexed]])
(def .public test
Test
@@ -62,4 +65,7 @@
(n.+ part whole)))
0)
(is (Identity Nat)))))
+
+ /free.test
+ /indexed.test
))))
diff --git a/stdlib/source/test/lux/abstract/monad/indexed.lux b/stdlib/source/test/lux/abstract/monad/indexed.lux
new file mode 100644
index 000000000..62b09daa4
--- /dev/null
+++ b/stdlib/source/test/lux/abstract/monad/indexed.lux
@@ -0,0 +1,47 @@
+(.require
+ [library
+ [lux (.except)
+ [abstract
+ ["[0]" monad (.only do)]]
+ [math
+ ["[0]" random]
+ [number
+ ["n" nat]]]
+ [test
+ ["_" property (.only Test)]]]]
+ [\\library
+ ["[0]" /]])
+
+(type (Effect input output value)
+ (-> input [output value]))
+
+(def monad
+ (/.Monad Effect)
+ (implementation
+ (def (in it)
+ (function (_ input)
+ [input it]))
+
+ (def (then $ @)
+ (function (_ pre)
+ (let [[interim input] (@ pre)]
+ (($ input) interim))))))
+
+(def .public test
+ Test
+ (<| (_.covering /._)
+ (_.for [/.Monad])
+ (do random.monad
+ [left random.nat
+ right random.nat
+ .let [expected (n.+ left right)]])
+ (all _.and
+ (_.coverage [/.do]
+ (let [it (is (Effect [] [] Nat)
+ (/.do ..monad
+ [left' (in left)
+ right' (in right)]
+ (in (n.+ left right))))
+ [_ actual] (it [])]
+ (n.= expected actual)))
+ )))
diff --git a/stdlib/source/test/lux/debug.lux b/stdlib/source/test/lux/debug.lux
index 1612f17b4..a41f52a8d 100644
--- a/stdlib/source/test/lux/debug.lux
+++ b/stdlib/source/test/lux/debug.lux
@@ -1,11 +1,15 @@
(.require
[library
[lux (.except)
+ ["[0]" ffi]
[abstract
[monad (.only do)]]
[control
["[0]" try (.use "[1]#[0]" functor)]
- ["[0]" exception]]
+ ["[0]" exception]
+ ["[0]" io]
+ [concurrency
+ ["[0]" atom]]]
[data
["[0]" text (.use "[1]#[0]" equivalence)
["%" \\format (.only format)]]
@@ -231,11 +235,71 @@
(type My_Text
Text)
+(for @.jvm (these (ffi.import java/lang/String
+ "[1]::[0]")
+
+ (ffi.import java/io/ByteArrayOutputStream
+ "[1]::[0]"
+ (new [])
+ (toString [] java/lang/String))
+
+ (ffi.import java/io/OutputStream
+ "[1]::[0]")
+
+ (ffi.import java/io/PrintStream
+ "[1]::[0]"
+ (new [java/io/OutputStream]))
+
+ (ffi.import java/lang/System
+ "[1]::[0]"
+ ("static" out java/io/PrintStream)
+ ("static" setOut [java/io/PrintStream] void))
+
+ (def system_output
+ java/io/PrintStream
+ (io.run! (java/lang/System::out))))
+ @.js (these (ffi.import console
+ "[1]::[0]"
+ ("static" log (-> Text Any))))
+ @.python (these (ffi.import io/StringIO
+ "[1]::[0]"
+ (new [])
+ (getvalue [] Text))
+
+ (ffi.import sys
+ "[1]::[0]"
+ ("static" stdout io/StringIO))))
+
+(def with_out
+ (template (_ <body>)
+ [(for @.jvm (ffi.synchronized ..system_output
+ (let [buffer (java/io/ByteArrayOutputStream::new)
+ _ (java/lang/System::setOut (java/io/PrintStream::new buffer))
+ output <body>
+ _ (java/lang/System::setOut ..system_output)]
+ [(ffi.of_string (java/io/ByteArrayOutputStream::toString buffer))
+ output]))
+ @.js (let [old (io.run! (console::log))
+ buffer (atom.atom "")
+ _ (io.run! (console::log (function (_ it)
+ (io.run! (atom.write! (format it text.\n) buffer)))))
+ output <body>
+ _ (io.run! (console::log old))]
+ [(io.run! (atom.read! buffer))
+ output])
+ @.python (let [old (io.run! (sys::stdout))
+ buffer (io/StringIO::new [])
+ _ (io.run! (sys::stdout buffer))
+ output <body>
+ _ (io.run! (sys::stdout old))]
+ [(io/StringIO::getvalue buffer)
+ output]))]))
+
(def .public test
Test
(<| (_.covering /._)
(do random.monad
- [message (random.lower_case 5)]
+ [expected_message (random.lower_case 5)]
(all _.and
..inspection
..representation
@@ -264,8 +328,7 @@
/.inspection)
true))
(_.coverage [/.log!]
- (exec
- (/.log! (format (%.symbol (symbol /.log!))
- " works: " (%.text message)))
- true))
+ (let [[actual_message _] (with_out (/.log! expected_message))]
+ (text#= (format expected_message text.\n)
+ actual_message)))
))))
diff --git a/stdlib/source/test/lux/ffi.py.lux b/stdlib/source/test/lux/ffi.py.lux
index a61678e06..5e005f9ff 100644
--- a/stdlib/source/test/lux/ffi.py.lux
+++ b/stdlib/source/test/lux/ffi.py.lux
@@ -3,6 +3,8 @@
[lux (.except)
[abstract
[monad (.only do)]]
+ [control
+ ["[0]" io]]
[math
["[0]" random]
[number
@@ -61,8 +63,10 @@
(is (Ex (_ a) (/.Object a))))
true))
(_.coverage [/.import]
- (and (i.= (os::R_OK) (os::R_OK))
- (not (i.= (os::W_OK) (os::R_OK)))))
+ (and (i.= (io.run! (os::R_OK))
+ (io.run! (os::R_OK)))
+ (not (i.= (io.run! (os::W_OK))
+ (io.run! (os::R_OK))))))
$/export.test
)))))
diff --git a/stdlib/source/test/lux/meta/compiler/language/lux/analysis/coverage.lux b/stdlib/source/test/lux/meta/compiler/language/lux/analysis/coverage.lux
index 9aa2277d3..1a04f77e1 100644
--- a/stdlib/source/test/lux/meta/compiler/language/lux/analysis/coverage.lux
+++ b/stdlib/source/test/lux/meta/compiler/language/lux/analysis/coverage.lux
@@ -105,7 +105,7 @@
right? random.bit
.let [lefts (//complex.lefts right? tag)]
[sub_coverage sub_pattern] again]
- (in [{/.#Variant (if right? {.#Some tag} {.#None})
+ (in [{/.#Variant (if right? {.#Some (++ tag)} {.#None})
(dictionary.of_list n.hash (list [tag sub_coverage]))}
{//pattern.#Complex
{//complex.#Variant
diff --git a/stdlib/source/test/lux/meta/target/js.lux b/stdlib/source/test/lux/meta/target/js.lux
index 9867d5085..eda7a2f72 100644
--- a/stdlib/source/test/lux/meta/target/js.lux
+++ b/stdlib/source/test/lux/meta/target/js.lux
@@ -348,7 +348,7 @@
(/.apply (/.closure (list $foreign)
(all /.then
(/.declare $local)
- (/.set $local (/.number number/1))
+ (/.statement (/.set $local (/.number number/1)))
(/.return $local)))
(list (/.number number/0)))))
)))
@@ -365,30 +365,30 @@
(and (expression (|>> (as Frac) (f.= (f.+ number/0 number/0)))
(/.apply (/.closure (list $foreign)
(all /.then
- (/.set $foreign (/.+ $foreign $foreign))
+ (/.statement (/.set $foreign (/.+ $foreign $foreign)))
(/.return $foreign)))
(list (/.number number/0))))
(expression (|>> (as Frac) (f.= (f.+ number/0 number/0)))
(let [@ (/.at (/.int +0) $foreign)]
(/.apply (/.closure (list $foreign)
(all /.then
- (/.set $foreign (/.array (list $foreign)))
- (/.set @ (/.+ @ @))
+ (/.statement (/.set $foreign (/.array (list $foreign))))
+ (/.statement (/.set @ (/.+ @ @)))
(/.return @)))
(list (/.number number/0)))))
(expression (|>> (as Frac) (f.= (f.+ number/0 number/0)))
(let [@ (/.the field $foreign)]
(/.apply (/.closure (list $foreign)
(all /.then
- (/.set $foreign (/.object (list [field $foreign])))
- (/.set @ (/.+ @ @))
+ (/.statement (/.set $foreign (/.object (list [field $foreign]))))
+ (/.statement (/.set @ (/.+ @ @)))
(/.return @)))
(list (/.number number/0)))))))
(_.coverage [/.delete]
(and (and (expression (|>> (as Bit))
(/.apply (/.closure (list)
(all /.then
- (/.set $foreign (/.number number/0))
+ (/.statement (/.set $foreign (/.number number/0)))
(/.return (/.delete $foreign))))
(list)))
(expression (|>> (as Bit) not)
@@ -399,7 +399,7 @@
(let [@ (/.at (/.int +0) $foreign)]
(/.apply (/.closure (list $foreign)
(all /.then
- (/.set $foreign (/.array (list $foreign)))
+ (/.statement (/.set $foreign (/.array (list $foreign))))
(/.return (|> (/.= (/.boolean true) (/.delete @))
(/.and (/.= /.undefined @))))))
(list (/.number number/0)))))
@@ -407,7 +407,7 @@
(let [@ (/.the field $foreign)]
(/.apply (/.closure (list $foreign)
(all /.then
- (/.set $foreign (/.object (list [field $foreign])))
+ (/.statement (/.set $foreign (/.object (list [field $foreign]))))
(/.return (|> (/.= (/.boolean true) (/.delete @))
(/.and (/.= /.undefined @))))))
(list (/.number number/0)))))
@@ -424,7 +424,7 @@
(let [@ (/.at (/.int +0) $foreign)]
(/.apply (/.closure (list $foreign)
(all /.then
- (/.set $foreign (/.array (list $foreign)))
+ (/.statement (/.set $foreign (/.array (list $foreign))))
(/.statement (<js> @))
(/.return @)))
(list (/.int int/0)))))
@@ -432,7 +432,7 @@
(let [@ (/.the field $foreign)]
(/.apply (/.closure (list $foreign)
(all /.then
- (/.set $foreign (/.object (list [field $foreign])))
+ (/.statement (/.set $foreign (/.object (list [field $foreign]))))
(/.statement (<js> @))
(/.return @)))
(list (/.int int/0)))))]
@@ -472,8 +472,8 @@
(all /.then
(/.when (/.= (/.int (.int expected_inner_iterations)) $inner_index)
/.break)
- (/.set $output (/.+ $input $output))
- (/.set $inner_index (/.+ (/.int +1) $inner_index))
+ (/.statement (/.set $output (/.+ $input $output)))
+ (/.statement (/.set $inner_index (/.+ (/.int +1) $inner_index)))
))
(/.return $output)))
(list (/.int input))))))
@@ -486,10 +486,10 @@
(/.define $output (/.int +0))
(/.while (/.< (/.int (.int full_inner_iterations)) $inner_index)
(all /.then
- (/.set $inner_index (/.+ (/.int +1) $inner_index))
+ (/.statement (/.set $inner_index (/.+ (/.int +1) $inner_index)))
(/.when (/.<= (/.int (.int expected_inner_iterations)) $inner_index)
/.continue)
- (/.set $output (/.+ $input $output))
+ (/.statement (/.set $output (/.+ $input $output)))
))
(/.return $output)))
(list (/.int input))))))
@@ -514,10 +514,10 @@
(/.break_at @outer))
(/.when (/.= (/.int (.int expected_inner_iterations)) $inner_index)
/.break)
- (/.set $output (/.+ $input $output))
- (/.set $inner_index (/.+ (/.int +1) $inner_index))
+ (/.statement (/.set $output (/.+ $input $output)))
+ (/.statement (/.set $inner_index (/.+ (/.int +1) $inner_index)))
))
- (/.set $outer_index (/.+ (/.int +1) $outer_index))
+ (/.statement (/.set $outer_index (/.+ (/.int +1) $outer_index)))
)))
(/.return $output)))
(list (/.int input))))))
@@ -533,16 +533,16 @@
(/.with_label @outer
(/.while (/.< (/.int (.int full_outer_iterations)) $outer_index)
(all /.then
- (/.set $outer_index (/.+ (/.int +1) $outer_index))
+ (/.statement (/.set $outer_index (/.+ (/.int +1) $outer_index)))
(/.define $inner_index (/.int +0))
(/.while (/.< (/.int (.int full_inner_iterations)) $inner_index)
(all /.then
- (/.set $inner_index (/.+ (/.int +1) $inner_index))
+ (/.statement (/.set $inner_index (/.+ (/.int +1) $inner_index)))
(/.when (/.<= (/.int (.int expected_outer_iterations)) $outer_index)
(/.continue_at @outer))
(/.when (/.<= (/.int (.int expected_inner_iterations)) $inner_index)
/.continue)
- (/.set $output (/.+ $input $output))
+ (/.statement (/.set $output (/.+ $input $output)))
))
)
))
@@ -570,8 +570,8 @@
(/.define $output (/.int +0))
(/.while (/.< (/.int (.int iterations)) $index)
(all /.then
- (/.set $output (/.+ $input $output))
- (/.set $index (/.+ (/.int +1) $index))
+ (/.statement (/.set $output (/.+ $input $output)))
+ (/.statement (/.set $index (/.+ (/.int +1) $index)))
))
(/.return $output)))
(list (/.int input)))))
@@ -583,8 +583,8 @@
(/.define $output (/.int +0))
(/.do_while (/.< (/.int (.int iterations)) $index)
(all /.then
- (/.set $output (/.+ $input $output))
- (/.set $index (/.+ (/.int +1) $index))
+ (/.statement (/.set $output (/.+ $input $output)))
+ (/.statement (/.set $index (/.+ (/.int +1) $index)))
))
(/.return $output)))
(list (/.int input)))))
@@ -596,7 +596,7 @@
(/.for $index (/.int +0)
(/.< (/.int (.int iterations)) $index)
(/.++ $index)
- (/.set $output (/.+ $input $output)))
+ (/.statement (/.set $output (/.+ $input $output))))
(/.return $output)))
(list (/.int input)))))
(_.for [/.Label]
@@ -697,7 +697,7 @@
(/.apply_1 (/.closure (list $arg/0)
(all /.then
(/.function_definition $class (list)
- (/.set (/.the field $this) $arg/0))
+ (/.statement (/.set (/.the field $this) $arg/0)))
(/.return (/.the field (/.new $class (list))))))
(/.number number/0)))))
..test|apply
@@ -808,14 +808,14 @@
(all /.then
/.use_strict
(/.declare $arg/0)
- (/.set $arg/0 (/.number number/0))
+ (/.statement (/.set $arg/0 (/.number number/0)))
(/.return $arg/0)))
(list)))
(|> (/.apply (/.closure (list)
(all /.then
/.use_strict
... (/.declare $arg/0)
- (/.set $arg/0 (/.number number/0))
+ (/.statement (/.set $arg/0 (/.number number/0)))
(/.return $arg/0)))
(list))
..eval