From 47b97c128bde837fa803a605f3e011a3e9ddd71c Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 5 Feb 2019 19:09:31 -0400 Subject: Integrated tests into normal source code. --- stdlib/source/test/lux/control/pipe.lux | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 stdlib/source/test/lux/control/pipe.lux (limited to 'stdlib/source/test/lux/control/pipe.lux') diff --git a/stdlib/source/test/lux/control/pipe.lux b/stdlib/source/test/lux/control/pipe.lux new file mode 100644 index 000000000..aaaa18616 --- /dev/null +++ b/stdlib/source/test/lux/control/pipe.lux @@ -0,0 +1,72 @@ +(.module: + [lux #* + [control + [monad (#+ Monad do)] + pipe] + [data + ["." identity] + [text ("text/." equivalence) + format]] + [math + ["r" random]]] + lux/test) + +(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)))) + + (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"))) + )) -- cgit v1.2.3