aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
authorEduardo Julian2019-02-06 09:34:55 -0400
committerEduardo Julian2019-02-06 09:34:55 -0400
commitee70d1af74a295b41f01770c269d72ee2d990c27 (patch)
tree6dc663344cad99081c2ed491e4fc35e4da9a1ac6 /stdlib/source/test
parent2d76b3e3c30e8c3e6073cd21d75d2461e58a0a4d (diff)
Updated test for "lux/control/pipe" to new format.
Diffstat (limited to 'stdlib/source/test')
-rw-r--r--stdlib/source/test/lux.lux1
-rw-r--r--stdlib/source/test/lux/control.lux7
-rw-r--r--stdlib/source/test/lux/control/pipe.lux165
3 files changed, 109 insertions, 64 deletions
diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux
index ef37237ba..08c77a303 100644
--- a/stdlib/source/test/lux.lux
+++ b/stdlib/source/test/lux.lux
@@ -96,7 +96,6 @@
["/." jvm]]
["/." control]]
## [control
- ## ## [pipe (#+)]
## ## [continuation (#+)]
## ## [reader (#+)]
## ## [writer (#+)]
diff --git a/stdlib/source/test/lux/control.lux b/stdlib/source/test/lux/control.lux
index 6c2204fbc..79dab5322 100644
--- a/stdlib/source/test/lux/control.lux
+++ b/stdlib/source/test/lux/control.lux
@@ -3,7 +3,8 @@
["_" test (#+ Test)]]
[/
["/." exception]
- ["/." interval]])
+ ["/." interval]
+ ["/." pipe]])
(def: #export test
Test
@@ -11,4 +12,6 @@
(<| (_.context "/exception Exception-handling.")
/exception.test)
(<| (_.context "/interval")
- /interval.test)))
+ /interval.test)
+ (<| (_.context "/pipe")
+ /pipe.test)))
diff --git a/stdlib/source/test/lux/control/pipe.lux b/stdlib/source/test/lux/control/pipe.lux
index aaaa18616..21d7b8b90 100644
--- a/stdlib/source/test/lux/control/pipe.lux
+++ b/stdlib/source/test/lux/control/pipe.lux
@@ -1,72 +1,115 @@
(.module:
[lux #*
+ ["_" test (#+ Test)]
[control
- [monad (#+ Monad do)]
- pipe]
+ [monad (#+ do)]]
[data
["." identity]
[text ("text/." equivalence)
format]]
[math
["r" random]]]
- lux/test)
+ {1
+ /})
-(context: "Pipes"
- ($_ seq
- (test "Can dismiss previous pipeline results and begin a new line."
- (|> +20
- (i/* +3)
- (i/+ +4)
- (new> +0 inc)
- (i/= +1)))
-
- (test "Can give names to piped values within a pipeline's scope."
- (|> +5
- (let> X [(i/+ X X)])
- (i/= +10)))
-
- (test "Can do branching in pipelines."
- (and (|> +5
- (cond> [i/even?] [(i/* +2)]
- [i/odd?] [(i/* +3)]
- [(new> -1)])
- (i/= +15))
- (|> +4
- (cond> [i/even?] [(i/* +2)]
- [i/odd?] [(i/* +3)]
- [])
- (i/= +8))
- (|> +5
- (cond> [i/even?] [(i/* +2)]
- [(new> -1)])
- (i/= -1))))
+(def: #export test
+ Test
+ (do r.monad
+ [sample r.nat]
+ ($_ _.and
+ (do @
+ [another r.nat]
+ (_.test "Can dismiss previous pipeline results and begin a new one."
+ (n/= (inc another)
+ (|> sample
+ (n/* 3)
+ (n/+ 4)
+ (new> another [inc])))))
+
+ (_.test "Let-binding"
+ (n/= (n/+ sample sample)
+ (|> sample
+ (let> x [(n/+ x x)]))))
+
+ (_.test "'Conditional' branching."
+ (text/= (cond (n/= 0 sample) "zero"
+ (n/even? sample) "even"
+ "odd")
+ (|> sample
+ (cond> [(n/= 0)] [(new> "zero" [])]
+ [n/even?] [(new> "even" [])]
+ [(new> "odd" [])]))))
- (test "Can loop within pipelines."
- (|> +1
- (loop> [(i/< +10)]
- [inc])
- (i/= +10)))
-
- (test "Can use monads within pipelines."
- (|> +5
- (do> identity.monad
- [(i/* +3)]
- [(i/+ +4)]
- [inc])
- (i/= +20)))
-
- (test "Can pattern-match against piped values."
- (|> +5
- (case> +0 "zero"
- +1 "one"
- +2 "two"
- +3 "three"
- +4 "four"
- +5 "five"
- +6 "six"
- +7 "seven"
- +8 "eight"
- +9 "nine"
- _ "???")
- (text/= "five")))
- ))
+ (_.test "'If' branching."
+ (text/= (if (n/even? sample)
+ "even"
+ "odd")
+ (|> sample
+ (if> [n/even?]
+ [(new> "even" [])]
+ [(new> "odd" [])]))))
+
+ (_.test "'When' branching."
+ (n/= (if (n/even? sample)
+ (n/* 2 sample)
+ sample)
+ (|> sample
+ (when> [n/even?]
+ [(n/* 2)]))))
+
+ (_.test "Can loop."
+ (n/= (n/* 10 sample)
+ (|> sample
+ (loop> [(n/= (n/* 10 sample)) not]
+ [(n/+ sample)]))))
+
+ (_.test "Monads."
+ (n/= (inc (n/+ 4 (n/* 3 sample)))
+ (|> sample
+ (do> identity.monad
+ [(n/* 3)]
+ [(n/+ 4)]
+ [inc]))))
+
+ (_.test "Execution."
+ (n/= (n/* 10 sample)
+ (|> sample
+ (exec> [%n (format "sample = ") log!])
+ (n/* 10))))
+
+ (_.test "Tuple."
+ (let [[left middle right] (|> sample
+ (tuple> [inc]
+ [dec]
+ [%n]))]
+ (and (n/= (inc sample) left)
+ (n/= (dec sample) middle)
+ (text/= (%n sample) right))))
+
+ (_.test "Pattern-matching."
+ (text/= (case (n/% 10 sample)
+ 0 "zero"
+ 1 "one"
+ 2 "two"
+ 3 "three"
+ 4 "four"
+ 5 "five"
+ 6 "six"
+ 7 "seven"
+ 8 "eight"
+ 9 "nine"
+ _ "???")
+ (|> sample
+ (n/% 10)
+ (case> 0 "zero"
+ 1 "one"
+ 2 "two"
+ 3 "three"
+ 4 "four"
+ 5 "five"
+ 6 "six"
+ 7 "seven"
+ 8 "eight"
+ 9 "nine"
+ _ "???"))))
+ )))