From adf8aeaa2a52760e294e08618e7aca5fc371fc0f Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 5 Apr 2017 18:05:23 -0400 Subject: - Moved lux/lexer and lux/lexer/regex to lux/data/text/lexer and lux/data/text/regex. - Moved lux/pipe to lux/control/pipe. - Moved the @pre and @post macros to lux/control/contract. - Improved error reporting for lux/type/auto. - Added a test for third-order type-checking for lux/type/auto. - Fixed a bug in the tests for lux/data/coll/vector. --- stdlib/test/test/lux/cli.lux | 6 +- stdlib/test/test/lux/concurrency/atom.lux | 3 +- stdlib/test/test/lux/concurrency/promise.lux | 6 +- stdlib/test/test/lux/concurrency/stm.lux | 3 +- stdlib/test/test/lux/control/effect.lux | 3 +- stdlib/test/test/lux/control/interval.lux | 4 +- stdlib/test/test/lux/control/pipe.lux | 74 +++++ stdlib/test/test/lux/data/char.lux | 6 +- stdlib/test/test/lux/data/coll/array.lux | 6 +- stdlib/test/test/lux/data/coll/dict.lux | 3 +- stdlib/test/test/lux/data/coll/list.lux | 6 +- stdlib/test/test/lux/data/coll/ordered.lux | 3 +- stdlib/test/test/lux/data/coll/priority-queue.lux | 3 +- stdlib/test/test/lux/data/coll/queue.lux | 3 +- stdlib/test/test/lux/data/coll/seq.lux | 6 +- stdlib/test/test/lux/data/coll/set.lux | 3 +- stdlib/test/test/lux/data/coll/stack.lux | 3 +- stdlib/test/test/lux/data/coll/stream.lux | 3 +- stdlib/test/test/lux/data/coll/tree/rose.lux | 3 +- stdlib/test/test/lux/data/coll/tree/zipper.lux | 6 +- stdlib/test/test/lux/data/coll/vector.lux | 5 +- stdlib/test/test/lux/data/error.lux | 6 +- stdlib/test/test/lux/data/error/exception.lux | 3 +- stdlib/test/test/lux/data/format/json.lux | 4 +- stdlib/test/test/lux/data/ident.lux | 6 +- stdlib/test/test/lux/data/log.lux | 6 +- stdlib/test/test/lux/data/maybe.lux | 6 +- stdlib/test/test/lux/data/number.lux | 6 +- stdlib/test/test/lux/data/number/complex.lux | 6 +- stdlib/test/test/lux/data/number/ratio.lux | 6 +- stdlib/test/test/lux/data/sum.lux | 6 +- stdlib/test/test/lux/data/text.lux | 6 +- stdlib/test/test/lux/data/text/lexer.lux | 315 ++++++++++++++++++++++ stdlib/test/test/lux/data/text/regex.lux | 285 ++++++++++++++++++++ stdlib/test/test/lux/function/cont.lux | 3 +- stdlib/test/test/lux/function/reader.lux | 6 +- stdlib/test/test/lux/function/state.lux | 6 +- stdlib/test/test/lux/function/thunk.lux | 1 - stdlib/test/test/lux/host.js.lux | 3 +- stdlib/test/test/lux/host.jvm.lux | 6 +- stdlib/test/test/lux/lexer.lux | 315 ---------------------- stdlib/test/test/lux/lexer/regex.lux | 285 -------------------- stdlib/test/test/lux/macro/ast.lux | 1 - stdlib/test/test/lux/macro/poly/eq.lux | 1 - stdlib/test/test/lux/macro/poly/functor.lux | 1 - stdlib/test/test/lux/macro/poly/text-encoder.lux | 1 - stdlib/test/test/lux/macro/syntax.lux | 1 - stdlib/test/test/lux/math.lux | 1 - stdlib/test/test/lux/math/logic/continuous.lux | 1 - stdlib/test/test/lux/math/logic/fuzzy.lux | 1 - stdlib/test/test/lux/math/simple.lux | 1 - stdlib/test/test/lux/pipe.lux | 74 ----- stdlib/test/test/lux/type.lux | 4 +- stdlib/test/test/lux/type/auto.lux | 6 +- stdlib/test/test/lux/type/check.lux | 1 - stdlib/test/tests.lux | 72 ++--- 56 files changed, 795 insertions(+), 815 deletions(-) create mode 100644 stdlib/test/test/lux/control/pipe.lux create mode 100644 stdlib/test/test/lux/data/text/lexer.lux create mode 100644 stdlib/test/test/lux/data/text/regex.lux delete mode 100644 stdlib/test/test/lux/lexer.lux delete mode 100644 stdlib/test/test/lux/lexer/regex.lux delete mode 100644 stdlib/test/test/lux/pipe.lux (limited to 'stdlib/test') diff --git a/stdlib/test/test/lux/cli.lux b/stdlib/test/test/lux/cli.lux index 8393d459b..b8ed6ca0c 100644 --- a/stdlib/test/test/lux/cli.lux +++ b/stdlib/test/test/lux/cli.lux @@ -1,7 +1,8 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data text/format [text "Text/" Eq] [number] @@ -9,8 +10,7 @@ [sum] (coll [list])) ["&" cli] - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (test: "CLI" diff --git a/stdlib/test/test/lux/concurrency/atom.lux b/stdlib/test/test/lux/concurrency/atom.lux index 9b6248ec8..84deafa07 100644 --- a/stdlib/test/test/lux/concurrency/atom.lux +++ b/stdlib/test/test/lux/concurrency/atom.lux @@ -6,8 +6,7 @@ (coll [list "" Functor]) text/format) (concurrency ["&" atom]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (test: "Atoms" diff --git a/stdlib/test/test/lux/concurrency/promise.lux b/stdlib/test/test/lux/concurrency/promise.lux index a054e5a96..7ad25fc46 100644 --- a/stdlib/test/test/lux/concurrency/promise.lux +++ b/stdlib/test/test/lux/concurrency/promise.lux @@ -1,13 +1,13 @@ (;module: lux (lux [io #- run] - (control monad) + (control monad + pipe) (data [number] text/format [error #- fail]) (concurrency ["&" promise]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (test: "Promises" diff --git a/stdlib/test/test/lux/concurrency/stm.lux b/stdlib/test/test/lux/concurrency/stm.lux index d48d20a9d..d6b6c1d43 100644 --- a/stdlib/test/test/lux/concurrency/stm.lux +++ b/stdlib/test/test/lux/concurrency/stm.lux @@ -7,8 +7,7 @@ text/format) (concurrency ["&" stm] [promise]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (def: iterations/processes Int 100) diff --git a/stdlib/test/test/lux/control/effect.lux b/stdlib/test/test/lux/control/effect.lux index 59fc116dc..39e5afa5d 100644 --- a/stdlib/test/test/lux/control/effect.lux +++ b/stdlib/test/test/lux/control/effect.lux @@ -7,8 +7,7 @@ (data [text] text/format) [macro] - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (do-template [ ] diff --git a/stdlib/test/test/lux/control/interval.lux b/stdlib/test/test/lux/control/interval.lux index 2127ff6df..b4c48a541 100644 --- a/stdlib/test/test/lux/control/interval.lux +++ b/stdlib/test/test/lux/control/interval.lux @@ -2,14 +2,14 @@ lux lux/test (lux (control monad + pipe ["&" interval]) [io] ["R" math/random] (data text/format [number] ["S" coll/set] - ["L" coll/list]) - pipe)) + ["L" coll/list]))) (test: "Equality." [bottom R;int diff --git a/stdlib/test/test/lux/control/pipe.lux b/stdlib/test/test/lux/control/pipe.lux new file mode 100644 index 000000000..4687a5635 --- /dev/null +++ b/stdlib/test/test/lux/control/pipe.lux @@ -0,0 +1,74 @@ +(;module: + lux + (lux [io] + (control monad + pipe) + (data text/format + [number] + [product] + identity + [text "T/" Eq]) + ["R" math/random]) + lux/test) + +(test: "Pipes" + ($_ seq + (assert "Can dismiss previous pipeline results and begin a new line." + (|> 20 + (i.* 3) + (i.+ 4) + (_> 0 i.inc) + (i.= 1))) + + (assert "Can give names to piped values within a pipeline's scope." + (and (|> 5 + (@> [(i.+ @ @)]) + (i.= 10)) + (|> 5 + (@> X [(i.+ X X)]) + (i.= 10)))) + + (assert "Can do branching in pipelines." + (and (|> 5 + (?> [i.even?] [(i.* 2)] + [i.odd?] [(i.* 3)] + [(_> -1)]) + (i.= 15)) + (|> 4 + (?> [i.even?] [(i.* 2)] + [i.odd?] [(i.* 3)]) + (i.= 8)) + (|> 5 + (?> [i.even?] [(i.* 2)] + [(_> -1)]) + (i.= -1)))) + + (assert "Can loop within pipelines." + (|> 1 + (!> [(i.< 10)] + [i.inc]) + (i.= 10))) + + (assert "Can use monads within pipelines." + (|> 5 + (%> Monad + [(i.* 3)] + [(i.+ 4)] + [i.inc]) + (i.= 20))) + + (assert "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" + _ "???") + (T/= "five"))) + )) diff --git a/stdlib/test/test/lux/data/char.lux b/stdlib/test/test/lux/data/char.lux index 5025a1283..dd3c0c2da 100644 --- a/stdlib/test/test/lux/data/char.lux +++ b/stdlib/test/test/lux/data/char.lux @@ -1,12 +1,12 @@ (;module: lux - (lux (control [monad]) + (lux (control [monad] + pipe) [io] (data char [text] text/format) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (test: "Char operations" diff --git a/stdlib/test/test/lux/data/coll/array.lux b/stdlib/test/test/lux/data/coll/array.lux index b5003f703..f7d09ae9a 100644 --- a/stdlib/test/test/lux/data/coll/array.lux +++ b/stdlib/test/test/lux/data/coll/array.lux @@ -1,12 +1,12 @@ (;module: lux - (lux (control [monad]) + (lux (control [monad] + pipe) [io] (data (coll ["&" array] [list]) [number]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (def: bounded-size diff --git a/stdlib/test/test/lux/data/coll/dict.lux b/stdlib/test/test/lux/data/coll/dict.lux index 3df06abcf..34e99cf58 100644 --- a/stdlib/test/test/lux/data/coll/dict.lux +++ b/stdlib/test/test/lux/data/coll/dict.lux @@ -9,8 +9,7 @@ [char] (coll ["&" dict] [list "List/" Fold Functor])) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (test: "Dictionaries." diff --git a/stdlib/test/test/lux/data/coll/list.lux b/stdlib/test/test/lux/data/coll/list.lux index fe381340d..bd6f78015 100644 --- a/stdlib/test/test/lux/data/coll/list.lux +++ b/stdlib/test/test/lux/data/coll/list.lux @@ -1,14 +1,14 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data (coll ["&" list]) [text "Text/" Monoid] [number] [bool] [product]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (def: bounded-size diff --git a/stdlib/test/test/lux/data/coll/ordered.lux b/stdlib/test/test/lux/data/coll/ordered.lux index ffc2bf309..c1f5c9944 100644 --- a/stdlib/test/test/lux/data/coll/ordered.lux +++ b/stdlib/test/test/lux/data/coll/ordered.lux @@ -7,8 +7,7 @@ [list "" Fold]) [number] text/format) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (def: gen-nat diff --git a/stdlib/test/test/lux/data/coll/priority-queue.lux b/stdlib/test/test/lux/data/coll/priority-queue.lux index de885f1ee..3e28334db 100644 --- a/stdlib/test/test/lux/data/coll/priority-queue.lux +++ b/stdlib/test/test/lux/data/coll/priority-queue.lux @@ -4,8 +4,7 @@ (control monad) (data (coll ["&" priority-queue]) [number]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (def: (gen-queue size) diff --git a/stdlib/test/test/lux/data/coll/queue.lux b/stdlib/test/test/lux/data/coll/queue.lux index fac5cef12..44123f8e3 100644 --- a/stdlib/test/test/lux/data/coll/queue.lux +++ b/stdlib/test/test/lux/data/coll/queue.lux @@ -4,8 +4,7 @@ (control monad) (data (coll ["&" queue]) [number]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (test: "Queues" diff --git a/stdlib/test/test/lux/data/coll/seq.lux b/stdlib/test/test/lux/data/coll/seq.lux index 5fe3a5af1..a111ecb0e 100644 --- a/stdlib/test/test/lux/data/coll/seq.lux +++ b/stdlib/test/test/lux/data/coll/seq.lux @@ -1,7 +1,8 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data (coll ["&" seq] ["F" tree/finger] ["L" list]) @@ -10,8 +11,7 @@ [bool] [product] maybe) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (def: bounded-size diff --git a/stdlib/test/test/lux/data/coll/set.lux b/stdlib/test/test/lux/data/coll/set.lux index 2a4f05bb1..a91813675 100644 --- a/stdlib/test/test/lux/data/coll/set.lux +++ b/stdlib/test/test/lux/data/coll/set.lux @@ -5,8 +5,7 @@ (data (coll ["&" set] [list "" Fold]) [number]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (def: gen-nat diff --git a/stdlib/test/test/lux/data/coll/stack.lux b/stdlib/test/test/lux/data/coll/stack.lux index 4c44cbf06..6d26c569d 100644 --- a/stdlib/test/test/lux/data/coll/stack.lux +++ b/stdlib/test/test/lux/data/coll/stack.lux @@ -5,8 +5,7 @@ (data (coll ["&" stack] [list "" Fold]) [number]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (def: gen-nat diff --git a/stdlib/test/test/lux/data/coll/stream.lux b/stdlib/test/test/lux/data/coll/stream.lux index 2be6aa054..2ee3013e2 100644 --- a/stdlib/test/test/lux/data/coll/stream.lux +++ b/stdlib/test/test/lux/data/coll/stream.lux @@ -9,8 +9,7 @@ ["&" stream]) [number "Nat/" Codec]) (function [cont]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (test: "Streams" diff --git a/stdlib/test/test/lux/data/coll/tree/rose.lux b/stdlib/test/test/lux/data/coll/tree/rose.lux index ef43fae44..a4839c2a5 100644 --- a/stdlib/test/test/lux/data/coll/tree/rose.lux +++ b/stdlib/test/test/lux/data/coll/tree/rose.lux @@ -5,8 +5,7 @@ (data (coll (tree ["&" rose]) [list "List/" Monad]) [number]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (def: gen-nat diff --git a/stdlib/test/test/lux/data/coll/tree/zipper.lux b/stdlib/test/test/lux/data/coll/tree/zipper.lux index ed0318cfe..143229dc5 100644 --- a/stdlib/test/test/lux/data/coll/tree/zipper.lux +++ b/stdlib/test/test/lux/data/coll/tree/zipper.lux @@ -1,15 +1,15 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data (coll [list "List/" Fold Functor] (tree ["&" zipper] [rose])) [text "Text/" Monoid] text/format [number]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (def: gen-tree diff --git a/stdlib/test/test/lux/data/coll/vector.lux b/stdlib/test/test/lux/data/coll/vector.lux index 735374c5c..6ad6934db 100644 --- a/stdlib/test/test/lux/data/coll/vector.lux +++ b/stdlib/test/test/lux/data/coll/vector.lux @@ -7,12 +7,11 @@ [text "Text/" Monoid] text/format [number]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (test: "Vectors" - [size (|> R;nat (:: @ map (n.% +100))) + [size (|> R;nat (:: @ map (|>. (n.% +100) (n.max +1)))) idx (|> R;nat (:: @ map (n.% size))) sample (R;vector size R;nat) other-sample (R;vector size R;nat) diff --git a/stdlib/test/test/lux/data/error.lux b/stdlib/test/test/lux/data/error.lux index 34f505142..d90387c89 100644 --- a/stdlib/test/test/lux/data/error.lux +++ b/stdlib/test/test/lux/data/error.lux @@ -1,10 +1,10 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data text/format - ["&" error]) - pipe) + ["&" error])) lux/test) (test: "Errors" diff --git a/stdlib/test/test/lux/data/error/exception.lux b/stdlib/test/test/lux/data/error/exception.lux index 41d01077e..bc84df7f5 100644 --- a/stdlib/test/test/lux/data/error/exception.lux +++ b/stdlib/test/test/lux/data/error/exception.lux @@ -7,8 +7,7 @@ [text] text/format [number]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (exception: Some-Exception) diff --git a/stdlib/test/test/lux/data/format/json.lux b/stdlib/test/test/lux/data/format/json.lux index ad70d5c0e..37fe49786 100644 --- a/stdlib/test/test/lux/data/format/json.lux +++ b/stdlib/test/test/lux/data/format/json.lux @@ -3,7 +3,8 @@ (lux [io] (control monad codec - eq) + eq + pipe) (data [text "Text/" Monoid] text/format [error #- fail] @@ -21,7 +22,6 @@ [syntax #+ syntax:] [poly #+ derived:]) ["R" math/random] - pipe test) ) diff --git a/stdlib/test/test/lux/data/ident.lux b/stdlib/test/test/lux/data/ident.lux index f88693003..07aaf8d0a 100644 --- a/stdlib/test/test/lux/data/ident.lux +++ b/stdlib/test/test/lux/data/ident.lux @@ -1,12 +1,12 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data ["&" ident] [text "Text/" Eq] text/format) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (def: (gen-part size) diff --git a/stdlib/test/test/lux/data/log.lux b/stdlib/test/test/lux/data/log.lux index 40a124490..ea174fc6b 100644 --- a/stdlib/test/test/lux/data/log.lux +++ b/stdlib/test/test/lux/data/log.lux @@ -1,12 +1,12 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data ["&" log] [text "Text/" Monoid Eq] [number] - [product]) - pipe) + [product])) lux/test) (test: "Logs" diff --git a/stdlib/test/test/lux/data/maybe.lux b/stdlib/test/test/lux/data/maybe.lux index 07961a6d0..8cfb4c38f 100644 --- a/stdlib/test/test/lux/data/maybe.lux +++ b/stdlib/test/test/lux/data/maybe.lux @@ -1,11 +1,11 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data ["&" maybe] [text "Text/" Monoid] - [number]) - pipe) + [number])) lux/test) (test: "Maybe" diff --git a/stdlib/test/test/lux/data/number.lux b/stdlib/test/test/lux/data/number.lux index ad89649ba..eefbd584b 100644 --- a/stdlib/test/test/lux/data/number.lux +++ b/stdlib/test/test/lux/data/number.lux @@ -1,12 +1,12 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data number [text "Text/" Monoid Eq] text/format) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (do-template [category rand-gen ] diff --git a/stdlib/test/test/lux/data/number/complex.lux b/stdlib/test/test/lux/data/number/complex.lux index 8ed27680c..9555c031e 100644 --- a/stdlib/test/test/lux/data/number/complex.lux +++ b/stdlib/test/test/lux/data/number/complex.lux @@ -1,7 +1,8 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data [text "Text/" Monoid] text/format [bool "b/" Eq] @@ -10,8 +11,7 @@ (coll [list "List/" Fold Functor]) [product]) [math] - ["R" math/random] - pipe) + ["R" math/random]) lux/test) ## Based on org.apache.commons.math4.complex.Complex diff --git a/stdlib/test/test/lux/data/number/ratio.lux b/stdlib/test/test/lux/data/number/ratio.lux index c1f7e104f..7ae36e573 100644 --- a/stdlib/test/test/lux/data/number/ratio.lux +++ b/stdlib/test/test/lux/data/number/ratio.lux @@ -1,7 +1,8 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data [text "Text/" Monoid] text/format [bool "b/" Eq] @@ -9,8 +10,7 @@ ["&" number/ratio "&/" Number] (coll [list "List/" Fold Functor]) [product]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (def: gen-part diff --git a/stdlib/test/test/lux/data/sum.lux b/stdlib/test/test/lux/data/sum.lux index 8ab124c1b..389ff1b9e 100644 --- a/stdlib/test/test/lux/data/sum.lux +++ b/stdlib/test/test/lux/data/sum.lux @@ -1,12 +1,12 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data sum [text "Text/" Monoid] [number] - (coll [list])) - pipe) + (coll [list]))) lux/test) (test: "Sum operations" diff --git a/stdlib/test/test/lux/data/text.lux b/stdlib/test/test/lux/data/text.lux index 4563d9b12..f306778ba 100644 --- a/stdlib/test/test/lux/data/text.lux +++ b/stdlib/test/test/lux/data/text.lux @@ -1,14 +1,14 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data ["&" text] [char] text/format [number] (coll [list])) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (test: "Size" diff --git a/stdlib/test/test/lux/data/text/lexer.lux b/stdlib/test/test/lux/data/text/lexer.lux new file mode 100644 index 000000000..92aeca0d8 --- /dev/null +++ b/stdlib/test/test/lux/data/text/lexer.lux @@ -0,0 +1,315 @@ +(;module: + lux + (lux (control monad + pipe) + [io] + (data [error #- fail] + [text "T/" Eq] + text/format + ["&" text/lexer] + [char "C/" Eq] + (coll [list])) + ["R" math/random]) + lux/test) + +## [Utils] +(def: (should-fail input) + (All [a] (-> (Error a) Bool)) + (case input + (#;Left _) true + _ false)) + +(def: (should-passC test input) + (-> Char (Error Char) Bool) + (case input + (#;Right output) + (C/= test output) + + _ + false)) + +(def: (should-passT test input) + (-> Text (Error Text) Bool) + (case input + (#;Right output) + (T/= test output) + + _ + false)) + +(def: (should-passL test input) + (-> (List Char) (Error (List Char)) Bool) + (let [(^open "L/") (list;Eq char;Eq)] + (case input + (#;Right output) + (L/= test output) + + _ + false))) + +(def: (should-passE test input) + (-> (Either Char Char) (Error (Either Char Char)) Bool) + (case input + (#;Right output) + (case [test output] + [(#;Left test) (#;Left output)] + (C/= test output) + + [(#;Right test) (#;Right output)] + (C/= test output) + + _ + false) + + _ + false)) + +## [Tests] +(test: "End" + ($_ seq + (assert "Can detect the end of the input." + (|> (&;run "" + &;end) + (case> (#;Right _) true _ false))) + + (assert "Won't mistake non-empty text for no more input." + (|> (&;run "YOLO" + &;end) + (case> (#;Left _) true _ false))) + )) + +(test: "Literals" + [size (|> R;nat (:: @ map (|>. (n.% +100) (n.max +10)))) + pre (R;text size) + post (|> (R;text size) + (R;filter (|>. (text;starts-with? pre) not)))] + ($_ seq + (assert "Can find literal text fragments." + (and (|> (&;run (format pre post) + (&;text pre)) + (case> (#;Right found) (T/= pre found) _ false)) + (|> (&;run post + (&;text pre)) + (case> (#;Left _) true _ false)))) + )) + +(test: "Char lexers" + ($_ seq + (assert "Can lex characters." + (and (|> (&;run "YOLO" + (&;char #"Y")) + (case> (#;Right #"Y") true _ false)) + (|> (&;run "MEME" + (&;char #"Y")) + (case> (#;Left _) true _ false)))) + + (assert "Can lex characters ranges." + (and (should-passC #"Y" (&;run "YOLO" + (&;char-range #"X" #"Z"))) + (should-fail (&;run "MEME" + (&;char-range #"X" #"Z"))))) + )) + +(test: "Custom lexers" + ($_ seq + (assert "Can lex anything" + (and (should-passC #"A" (&;run "A" + &;any)) + (should-fail (&;run "" + &;any)))) + + (assert "Can lex upper-case and &;lower-case letters." + (and (should-passC #"Y" (&;run "YOLO" + &;upper)) + (should-fail (&;run "meme" + &;upper)) + + (should-passC #"y" (&;run "yolo" + &;lower)) + (should-fail (&;run "MEME" + &;lower)))) + + (assert "Can lex numbers." + (and (should-passC #"1" (&;run "1" + &;digit)) + (should-fail (&;run " " + &;digit)) + + (should-passC #"7" (&;run "7" + &;oct-digit)) + (should-fail (&;run "8" + &;oct-digit)) + + (should-passC #"1" (&;run "1" + &;hex-digit)) + (should-passC #"a" (&;run "a" + &;hex-digit)) + (should-passC #"A" (&;run "A" + &;hex-digit)) + (should-fail (&;run " " + &;hex-digit)) + )) + + (assert "Can lex alphabetic characters." + (and (should-passC #"A" (&;run "A" + &;alpha)) + (should-passC #"a" (&;run "a" + &;alpha)) + (should-fail (&;run "1" + &;alpha)))) + + (assert "Can lex alphanumeric characters." + (and (should-passC #"A" (&;run "A" + &;alpha-num)) + (should-passC #"a" (&;run "a" + &;alpha-num)) + (should-passC #"1" (&;run "1" + &;alpha-num)) + (should-fail (&;run " " + &;alpha-num)))) + + (assert "Can lex white-space." + (and (should-passC #" " (&;run " " + &;space)) + (should-fail (&;run "8" + &;space)))) + )) + +(test: "Combinators" + ($_ seq + (assert "Can combine lexers sequentially." + (and (|> (&;run "YOLO" + (&;seq &;any &;any)) + (case> (#;Right [#"Y" #"O"]) true + _ false)) + (should-fail (&;run "Y" + (&;seq &;any &;any))))) + + (assert "Can combine lexers alternatively." + (and (should-passE (#;Left #"0") (&;run "0" + (&;alt &;digit &;upper))) + (should-passE (#;Right #"A") (&;run "A" + (&;alt &;digit &;upper))) + (should-fail (&;run "a" + (&;alt &;digit &;upper))))) + + (assert "Can create the opposite of a lexer." + (and (should-passC #"a" (&;run "a" + (&;not (&;alt &;digit &;upper)))) + (should-fail (&;run "A" + (&;not (&;alt &;digit &;upper)))))) + + (assert "Can use either lexer." + (and (should-passC #"0" (&;run "0" + (&;either &;digit &;upper))) + (should-passC #"A" (&;run "A" + (&;either &;digit &;upper))) + (should-fail (&;run "a" + (&;either &;digit &;upper))))) + + (assert "Can select from among a set of characters." + (and (should-passC #"C" (&;run "C" + (&;one-of "ABC"))) + (should-fail (&;run "D" + (&;one-of "ABC"))))) + + (assert "Can avoid a set of characters." + (and (should-passC #"D" (&;run "D" + (&;none-of "ABC"))) + (should-fail (&;run "C" + (&;none-of "ABC"))))) + + (assert "Can lex using arbitrary predicates." + (and (should-passC #"D" (&;run "D" + (&;satisfies (lambda [c] true)))) + (should-fail (&;run "C" + (&;satisfies (lambda [c] false)))))) + + (assert "Can apply a lexer multiple times." + (and (should-passT "0123456789ABCDEF" (&;run "0123456789ABCDEF yolo" + (&;many' &;hex-digit))) + (should-fail (&;run "yolo" + (&;many' &;hex-digit))) + + (should-passT "" (&;run "yolo" + (&;some' &;hex-digit))))) + )) + +(test: "Yet more combinators..." + ($_ seq + (assert "Can fail at will." + (should-fail (&;run "yolo" + (&;fail "Well, it really SHOULD fail...")))) + + (assert "Can make assertions." + (and (should-fail (&;run "yolo" + (&;assert "Well, it really SHOULD fail..." false))) + (|> (&;run "yolo" + (&;assert "GO, GO, GO!" true)) + (case> (#;Right []) true + _ false)))) + + (assert "Can apply a lexer multiple times." + (and (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F") + (&;run "0123456789ABCDEF yolo" + (&;many &;hex-digit))) + (should-fail (&;run "yolo" + (&;many &;hex-digit))) + + (should-passL (list) + (&;run "yolo" + (&;some &;hex-digit))))) + + (assert "Can lex exactly N elements." + (and (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F") + (&;run "0123456789ABCDEF yolo" + (&;exactly +16 &;hex-digit))) + (should-passL (list #"0" #"1" #"2") + (&;run "0123456789ABCDEF yolo" + (&;exactly +3 &;hex-digit))) + (should-fail (&;run "0123456789ABCDEF yolo" + (&;exactly +17 &;hex-digit))))) + + (assert "Can lex at-most N elements." + (and (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F") + (&;run "0123456789ABCDEF yolo" + (&;at-most +16 &;hex-digit))) + (should-passL (list #"0" #"1" #"2") + (&;run "0123456789ABCDEF yolo" + (&;at-most +3 &;hex-digit))) + (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F") + (&;run "0123456789ABCDEF yolo" + (&;at-most +17 &;hex-digit))))) + + (assert "Can lex tokens between lower and upper boundaries of quantity." + (and (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F") + (&;run "0123456789ABCDEF yolo" + (&;between +0 +16 &;hex-digit))) + (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F") + (&;run "0123456789ABCDEF yolo" + (&;between +3 +16 &;hex-digit))) + (should-fail (&;run "0123456789ABCDEF yolo" + (&;between +17 +100 &;hex-digit))) + (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F") + (&;run "0123456789ABCDEF yolo" + (&;between +15 +20 &;hex-digit))))) + + (assert "Can optionally lex a token." + (and (|> (&;run "123abc" + (&;opt &;hex-digit)) + (case> (#;Right (#;Some #"1")) true + _ false)) + (|> (&;run "yolo" + (&;opt &;hex-digit)) + (case> (#;Right #;None) true + _ false)))) + + (assert "Can take into account separators during lexing." + (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"a" #"b" #"c" #"d" #"e" #"f") + (&;run "0 1 2 3 4 5 6 7 8 9 a b c d e f YOLO" + (&;sep-by &;space &;hex-digit)))) + + (assert "Can obtain the whole of the remaining input." + (should-passT "yolo" (&;run "yolo" + &;get-input))) + )) diff --git a/stdlib/test/test/lux/data/text/regex.lux b/stdlib/test/test/lux/data/text/regex.lux new file mode 100644 index 000000000..e737d5ee4 --- /dev/null +++ b/stdlib/test/test/lux/data/text/regex.lux @@ -0,0 +1,285 @@ +(;module: + lux + (lux [io] + (control monad + pipe) + (data [error #- fail] + [product] + [text "T/" Eq] + text/format + (text [lexer] + ["&" regex])) + [compiler] + (macro [ast] + ["s" syntax #+ syntax:]) + ["R" math/random]) + lux/test) + +## [Utils] +(def: (should-pass regex input) + (-> (lexer;Lexer Text) Text Bool) + (|> (lexer;run input regex) + (case> (#;Right parsed) + (T/= parsed input) + + _ + false))) + +(def: (should-passT test regex input) + (-> Text (lexer;Lexer Text) Text Bool) + (|> (lexer;run input regex) + (case> (#;Right parsed) + (T/= test parsed) + + _ + false))) + +(def: (should-fail regex input) + (All [a] (-> (lexer;Lexer a) Text Bool)) + (|> (lexer;run input regex) + (case> (#;Left _) true _ false))) + +(syntax: (should-check pattern regex input) + (wrap (list (` (|> (lexer;run (~ input) (~ regex)) + (case> (^ (#;Right (~ pattern))) + true + + (~' _) + false)))))) + +## [Tests] +(test: "Regular Expressions [Basics]" + (assert "Can parse character literals." + (and (should-pass (&;regex "a") "a") + (should-fail (&;regex "a") ".") + (should-pass (&;regex "\\.") ".") + (should-fail (&;regex "\\.") "a")))) + +(test: "Regular Expressions [System character classes]" + ($_ seq + (assert "Can parse anything." + (should-pass (&;regex ".") "a")) + + (assert "Can parse digits." + (and (should-pass (&;regex "\\d") "0") + (should-fail (&;regex "\\d") "m"))) + + (assert "Can parse non digits." + (and (should-pass (&;regex "\\D") "m") + (should-fail (&;regex "\\D") "0"))) + + (assert "Can parse white-space." + (and (should-pass (&;regex "\\s") " ") + (should-fail (&;regex "\\s") "m"))) + + (assert "Can parse non white-space." + (and (should-pass (&;regex "\\S") "m") + (should-fail (&;regex "\\S") " "))) + + (assert "Can parse word characters." + (and (should-pass (&;regex "\\w") "_") + (should-fail (&;regex "\\w") "^"))) + + (assert "Can parse non word characters." + (and (should-pass (&;regex "\\W") ".") + (should-fail (&;regex "\\W") "a"))) + )) + +(test: "Regular Expressions [Special system character classes : Part 1]" + ($_ seq + (assert "Can parse using special character classes." + (and (and (should-pass (&;regex "\\p{Lower}") "m") + (should-fail (&;regex "\\p{Lower}") "M")) + + (and (should-pass (&;regex "\\p{Upper}") "M") + (should-fail (&;regex "\\p{Upper}") "m")) + + (and (should-pass (&;regex "\\p{Alpha}") "M") + (should-fail (&;regex "\\p{Alpha}") "0")) + + (and (should-pass (&;regex "\\p{Digit}") "1") + (should-fail (&;regex "\\p{Digit}") "n")) + + (and (should-pass (&;regex "\\p{Alnum}") "1") + (should-fail (&;regex "\\p{Alnum}") ".")) + + (and (should-pass (&;regex "\\p{Space}") " ") + (should-fail (&;regex "\\p{Space}") ".")) + )) + )) + +(test: "Regular Expressions [Special system character classes : Part 2]" + ($_ seq + (assert "Can parse using special character classes." + (and (and (should-pass (&;regex "\\p{HexDigit}") "a") + (should-fail (&;regex "\\p{HexDigit}") ".")) + + (and (should-pass (&;regex "\\p{OctDigit}") "6") + (should-fail (&;regex "\\p{OctDigit}") ".")) + + (and (should-pass (&;regex "\\p{Blank}") "\t") + (should-fail (&;regex "\\p{Blank}") ".")) + + (and (should-pass (&;regex "\\p{ASCII}") "\t") + (should-fail (&;regex "\\p{ASCII}") "\u1234")) + + (and (should-pass (&;regex "\\p{Contrl}") "\u0012") + (should-fail (&;regex "\\p{Contrl}") "a")) + + (and (should-pass (&;regex "\\p{Punct}") "@") + (should-fail (&;regex "\\p{Punct}") "a")) + + (and (should-pass (&;regex "\\p{Graph}") "@") + (should-fail (&;regex "\\p{Graph}") " ")) + + (and (should-pass (&;regex "\\p{Print}") "\u0020") + (should-fail (&;regex "\\p{Print}") "\u1234")) + )) + )) + +(test: "Regular Expressions [Custom character classes : Part 1]" + ($_ seq + (assert "Can parse using custom character classes." + (and (should-pass (&;regex "[abc]") "a") + (should-fail (&;regex "[abc]") "m"))) + + (assert "Can parse using character ranges." + (and (should-pass (&;regex "[a-z]") "a") + (should-pass (&;regex "[a-z]") "m") + (should-pass (&;regex "[a-z]") "z"))) + + (assert "Can combine character ranges." + (and (should-pass (&;regex "[a-zA-Z]") "a") + (should-pass (&;regex "[a-zA-Z]") "m") + (should-pass (&;regex "[a-zA-Z]") "z") + (should-pass (&;regex "[a-zA-Z]") "A") + (should-pass (&;regex "[a-zA-Z]") "M") + (should-pass (&;regex "[a-zA-Z]") "Z"))) + )) + +(test: "Regular Expressions [Custom character classes : Part 2]" + ($_ seq + (assert "Can negate custom character classes." + (and (should-fail (&;regex "[^abc]") "a") + (should-pass (&;regex "[^abc]") "m"))) + + (assert "Can negate character ranges.." + (and (should-fail (&;regex "[^a-z]") "a") + (should-pass (&;regex "[^a-z]") "0"))) + + (assert "Can parse negate combinations of character ranges." + (and (should-fail (&;regex "[^a-zA-Z]") "a") + (should-pass (&;regex "[^a-zA-Z]") "0"))) + )) + +(test: "Regular Expressions [Custom character classes : Part 3]" + ($_ seq + (assert "Can make custom character classes more specific." + (and (let [RE (&;regex "[a-z&&[def]]")] + (and (should-fail RE "a") + (should-pass RE "d"))) + + (let [RE (&;regex "[a-z&&[^bc]]")] + (and (should-pass RE "a") + (should-fail RE "b"))) + + (let [RE (&;regex "[a-z&&[^m-p]]")] + (and (should-pass RE "a") + (should-fail RE "m") + (should-fail RE "p"))))) + )) + +(test: "Regular Expressions [Reference]" + (let [number (&;regex "\\d+")] + (assert "Can build complex regexs by combining simpler ones." + (should-check ["809-345-6789" "809" "345" "6789"] (&;regex "(\\@)-(\\@)-(\\@)") "809-345-6789")))) + +(test: "Regular Expressions [Fuzzy Quantifiers]" + ($_ seq + (assert "Can sequentially combine patterns." + (should-passT "aa" (&;regex "aa") "aa")) + + (assert "Can match patterns optionally." + (and (should-passT "a" (&;regex "a?") "a") + (should-passT "" (&;regex "a?") ""))) + + (assert "Can match a pattern 0 or more times." + (and (should-passT "aaa" (&;regex "a*") "aaa") + (should-passT "" (&;regex "a*") ""))) + + (assert "Can match a pattern 1 or more times." + (and (should-passT "aaa" (&;regex "a+") "aaa") + (should-passT "a" (&;regex "a+") "a") + (should-fail (&;regex "a+") ""))) + )) + +(test: "Regular Expressions [Crisp Quantifiers]" + ($_ seq + (assert "Can match a pattern N times." + (and (should-passT "aa" (&;regex "a{2}") "aa") + (should-passT "a" (&;regex "a{1}") "aa") + (should-fail (&;regex "a{3}") "aa"))) + + (assert "Can match a pattern at-least N times." + (and (should-passT "aa" (&;regex "a{1,}") "aa") + (should-passT "aa" (&;regex "a{2,}") "aa") + (should-fail (&;regex "a{3,}") "aa"))) + + (assert "Can match a pattern at-most N times." + (and (should-passT "a" (&;regex "a{,1}") "aa") + (should-passT "aa" (&;regex "a{,2}") "aa") + (should-passT "aa" (&;regex "a{,3}") "aa"))) + + (assert "Can match a pattern between N and M times." + (and (should-passT "a" (&;regex "a{1,2}") "a") + (should-passT "aa" (&;regex "a{1,2}") "aa") + (should-passT "aa" (&;regex "a{1,2}") "aaa"))) + )) + +(test: "Regular Expressions [Groups]" + ($_ seq + (assert "Can extract groups of sub-matches specified in a pattern." + (and (should-check ["abc" "b"] (&;regex "a(.)c") "abc") + (should-check ["abbbbbc" "bbbbb"] (&;regex "a(b+)c") "abbbbbc") + (should-check ["809-345-6789" "809" "345" "6789"] (&;regex "(\\d{3})-(\\d{3})-(\\d{4})") "809-345-6789") + (should-check ["809-345-6789" "809" "6789"] (&;regex "(\\d{3})-(?:\\d{3})-(\\d{4})") "809-345-6789") + (should-check ["809-809-6789" "809" "6789"] (&;regex "(\\d{3})-\\0-(\\d{4})") "809-809-6789") + (should-check ["809-809-6789" "809" "6789"] (&;regex "(?\\d{3})-\\k-(\\d{4})") "809-809-6789") + (should-check ["809-809-6789-6789" "809" "6789"] (&;regex "(?\\d{3})-\\k-(\\d{4})-\\0") "809-809-6789-6789"))) + + (assert "Can specify groups within groups." + (should-check ["809-345-6789" "809" ["345-6789" "345" "6789"]] (&;regex "(\\d{3})-((\\d{3})-(\\d{4}))") "809-345-6789")) + )) + +(test: "Regular Expressions [Alternation]" + ($_ seq + (assert "Can specify alternative patterns." + (and (should-check ["a" (+0 [])] (&;regex "a|b") "a") + (should-check ["b" (+1 [])] (&;regex "a|b") "b") + (should-fail (&;regex "a|b") "c"))) + + (assert "Can have groups within alternations." + (and (should-check ["abc" (+0 ["b" "c"])] (&;regex "a(.)(.)|b(.)(.)") "abc") + (should-check ["bcd" (+1 ["c" "d"])] (&;regex "a(.)(.)|b(.)(.)") "bcd") + (should-fail (&;regex "a(.)(.)|b(.)(.)") "cde") + + (should-check ["809-345-6789" (+0 ["809" "345-6789" "345" "6789"])] + (&;regex "(\\d{3})-((\\d{3})-(\\d{4}))|b(.)d") + "809-345-6789"))) + )) + +(test: "Pattern-matching" + [sample1 (R;text +3) + sample2 (R;text +3) + sample3 (R;text +4)] + (case (format sample1 "-" sample2 "-" sample3) + (&;^regex "(.{3})-(.{3})-(.{4})" + [_ match1 match2 match3]) + (assert "Can pattern-match using regular-expressions." + (and (T/= sample1 match1) + (T/= sample2 match2) + (T/= sample3 match3))) + + _ + (assert "Cannot pattern-match using regular-expressions." + false))) diff --git a/stdlib/test/test/lux/function/cont.lux b/stdlib/test/test/lux/function/cont.lux index ba1224bb8..c2e36a06b 100644 --- a/stdlib/test/test/lux/function/cont.lux +++ b/stdlib/test/test/lux/function/cont.lux @@ -7,8 +7,7 @@ [number] [product]) (function ["&" cont]) - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (test: "Continuations" diff --git a/stdlib/test/test/lux/function/reader.lux b/stdlib/test/test/lux/function/reader.lux index 14b95af94..602efc603 100644 --- a/stdlib/test/test/lux/function/reader.lux +++ b/stdlib/test/test/lux/function/reader.lux @@ -1,12 +1,12 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data [text "Text/" Monoid] text/format [number]) - (function ["&" reader]) - pipe) + (function ["&" reader])) lux/test) (test: "Readers" diff --git a/stdlib/test/test/lux/function/state.lux b/stdlib/test/test/lux/function/state.lux index 186b786e0..9ef61e4d3 100644 --- a/stdlib/test/test/lux/function/state.lux +++ b/stdlib/test/test/lux/function/state.lux @@ -1,13 +1,13 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data [text "Text/" Monoid] text/format [number] [product]) - (function ["&" state]) - pipe) + (function ["&" state])) lux/test) (test: "State" diff --git a/stdlib/test/test/lux/function/thunk.lux b/stdlib/test/test/lux/function/thunk.lux index e3e9aca1b..753398f77 100644 --- a/stdlib/test/test/lux/function/thunk.lux +++ b/stdlib/test/test/lux/function/thunk.lux @@ -3,7 +3,6 @@ (lux [io] (control monad) (function ["&" thunk]) - pipe ["R" math/random]) lux/test) diff --git a/stdlib/test/test/lux/host.js.lux b/stdlib/test/test/lux/host.js.lux index 7d79b2b87..b7dbe043f 100644 --- a/stdlib/test/test/lux/host.js.lux +++ b/stdlib/test/test/lux/host.js.lux @@ -4,8 +4,7 @@ (control monad) (data text/format) ["&" host] - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (test: "JavaScript operations" diff --git a/stdlib/test/test/lux/host.jvm.lux b/stdlib/test/test/lux/host.jvm.lux index f58b706d5..4bd96ad62 100644 --- a/stdlib/test/test/lux/host.jvm.lux +++ b/stdlib/test/test/lux/host.jvm.lux @@ -1,14 +1,14 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data text/format [number] [product] [text "Text/" Eq]) ["&" host #+ jvm-import class: interface: object] - ["R" math/random] - pipe) + ["R" math/random]) lux/test) (jvm-import java.lang.Exception diff --git a/stdlib/test/test/lux/lexer.lux b/stdlib/test/test/lux/lexer.lux deleted file mode 100644 index 0bfd8dec7..000000000 --- a/stdlib/test/test/lux/lexer.lux +++ /dev/null @@ -1,315 +0,0 @@ -(;module: - lux - (lux (control monad) - [io] - (data [error #- fail] - [text "T/" Eq] - text/format - [char "C/" Eq] - (coll [list])) - ["R" math/random] - pipe - ["&" lexer]) - lux/test) - -## [Utils] -(def: (should-fail input) - (All [a] (-> (Error a) Bool)) - (case input - (#;Left _) true - _ false)) - -(def: (should-passC test input) - (-> Char (Error Char) Bool) - (case input - (#;Right output) - (C/= test output) - - _ - false)) - -(def: (should-passT test input) - (-> Text (Error Text) Bool) - (case input - (#;Right output) - (T/= test output) - - _ - false)) - -(def: (should-passL test input) - (-> (List Char) (Error (List Char)) Bool) - (let [(^open "L/") (list;Eq char;Eq)] - (case input - (#;Right output) - (L/= test output) - - _ - false))) - -(def: (should-passE test input) - (-> (Either Char Char) (Error (Either Char Char)) Bool) - (case input - (#;Right output) - (case [test output] - [(#;Left test) (#;Left output)] - (C/= test output) - - [(#;Right test) (#;Right output)] - (C/= test output) - - _ - false) - - _ - false)) - -## [Tests] -(test: "End" - ($_ seq - (assert "Can detect the end of the input." - (|> (&;run "" - &;end) - (case> (#;Right _) true _ false))) - - (assert "Won't mistake non-empty text for no more input." - (|> (&;run "YOLO" - &;end) - (case> (#;Left _) true _ false))) - )) - -(test: "Literals" - [size (|> R;nat (:: @ map (|>. (n.% +100) (n.max +10)))) - pre (R;text size) - post (|> (R;text size) - (R;filter (|>. (text;starts-with? pre) not)))] - ($_ seq - (assert "Can find literal text fragments." - (and (|> (&;run (format pre post) - (&;text pre)) - (case> (#;Right found) (T/= pre found) _ false)) - (|> (&;run post - (&;text pre)) - (case> (#;Left _) true _ false)))) - )) - -(test: "Char lexers" - ($_ seq - (assert "Can lex characters." - (and (|> (&;run "YOLO" - (&;char #"Y")) - (case> (#;Right #"Y") true _ false)) - (|> (&;run "MEME" - (&;char #"Y")) - (case> (#;Left _) true _ false)))) - - (assert "Can lex characters ranges." - (and (should-passC #"Y" (&;run "YOLO" - (&;char-range #"X" #"Z"))) - (should-fail (&;run "MEME" - (&;char-range #"X" #"Z"))))) - )) - -(test: "Custom lexers" - ($_ seq - (assert "Can lex anything" - (and (should-passC #"A" (&;run "A" - &;any)) - (should-fail (&;run "" - &;any)))) - - (assert "Can lex upper-case and &;lower-case letters." - (and (should-passC #"Y" (&;run "YOLO" - &;upper)) - (should-fail (&;run "meme" - &;upper)) - - (should-passC #"y" (&;run "yolo" - &;lower)) - (should-fail (&;run "MEME" - &;lower)))) - - (assert "Can lex numbers." - (and (should-passC #"1" (&;run "1" - &;digit)) - (should-fail (&;run " " - &;digit)) - - (should-passC #"7" (&;run "7" - &;oct-digit)) - (should-fail (&;run "8" - &;oct-digit)) - - (should-passC #"1" (&;run "1" - &;hex-digit)) - (should-passC #"a" (&;run "a" - &;hex-digit)) - (should-passC #"A" (&;run "A" - &;hex-digit)) - (should-fail (&;run " " - &;hex-digit)) - )) - - (assert "Can lex alphabetic characters." - (and (should-passC #"A" (&;run "A" - &;alpha)) - (should-passC #"a" (&;run "a" - &;alpha)) - (should-fail (&;run "1" - &;alpha)))) - - (assert "Can lex alphanumeric characters." - (and (should-passC #"A" (&;run "A" - &;alpha-num)) - (should-passC #"a" (&;run "a" - &;alpha-num)) - (should-passC #"1" (&;run "1" - &;alpha-num)) - (should-fail (&;run " " - &;alpha-num)))) - - (assert "Can lex white-space." - (and (should-passC #" " (&;run " " - &;space)) - (should-fail (&;run "8" - &;space)))) - )) - -(test: "Combinators" - ($_ seq - (assert "Can combine lexers sequentially." - (and (|> (&;run "YOLO" - (&;seq &;any &;any)) - (case> (#;Right [#"Y" #"O"]) true - _ false)) - (should-fail (&;run "Y" - (&;seq &;any &;any))))) - - (assert "Can combine lexers alternatively." - (and (should-passE (#;Left #"0") (&;run "0" - (&;alt &;digit &;upper))) - (should-passE (#;Right #"A") (&;run "A" - (&;alt &;digit &;upper))) - (should-fail (&;run "a" - (&;alt &;digit &;upper))))) - - (assert "Can create the opposite of a lexer." - (and (should-passC #"a" (&;run "a" - (&;not (&;alt &;digit &;upper)))) - (should-fail (&;run "A" - (&;not (&;alt &;digit &;upper)))))) - - (assert "Can use either lexer." - (and (should-passC #"0" (&;run "0" - (&;either &;digit &;upper))) - (should-passC #"A" (&;run "A" - (&;either &;digit &;upper))) - (should-fail (&;run "a" - (&;either &;digit &;upper))))) - - (assert "Can select from among a set of characters." - (and (should-passC #"C" (&;run "C" - (&;one-of "ABC"))) - (should-fail (&;run "D" - (&;one-of "ABC"))))) - - (assert "Can avoid a set of characters." - (and (should-passC #"D" (&;run "D" - (&;none-of "ABC"))) - (should-fail (&;run "C" - (&;none-of "ABC"))))) - - (assert "Can lex using arbitrary predicates." - (and (should-passC #"D" (&;run "D" - (&;satisfies (lambda [c] true)))) - (should-fail (&;run "C" - (&;satisfies (lambda [c] false)))))) - - (assert "Can apply a lexer multiple times." - (and (should-passT "0123456789ABCDEF" (&;run "0123456789ABCDEF yolo" - (&;many' &;hex-digit))) - (should-fail (&;run "yolo" - (&;many' &;hex-digit))) - - (should-passT "" (&;run "yolo" - (&;some' &;hex-digit))))) - )) - -(test: "Yet more combinators..." - ($_ seq - (assert "Can fail at will." - (should-fail (&;run "yolo" - (&;fail "Well, it really SHOULD fail...")))) - - (assert "Can make assertions." - (and (should-fail (&;run "yolo" - (&;assert "Well, it really SHOULD fail..." false))) - (|> (&;run "yolo" - (&;assert "GO, GO, GO!" true)) - (case> (#;Right []) true - _ false)))) - - (assert "Can apply a lexer multiple times." - (and (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F") - (&;run "0123456789ABCDEF yolo" - (&;many &;hex-digit))) - (should-fail (&;run "yolo" - (&;many &;hex-digit))) - - (should-passL (list) - (&;run "yolo" - (&;some &;hex-digit))))) - - (assert "Can lex exactly N elements." - (and (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F") - (&;run "0123456789ABCDEF yolo" - (&;exactly +16 &;hex-digit))) - (should-passL (list #"0" #"1" #"2") - (&;run "0123456789ABCDEF yolo" - (&;exactly +3 &;hex-digit))) - (should-fail (&;run "0123456789ABCDEF yolo" - (&;exactly +17 &;hex-digit))))) - - (assert "Can lex at-most N elements." - (and (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F") - (&;run "0123456789ABCDEF yolo" - (&;at-most +16 &;hex-digit))) - (should-passL (list #"0" #"1" #"2") - (&;run "0123456789ABCDEF yolo" - (&;at-most +3 &;hex-digit))) - (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F") - (&;run "0123456789ABCDEF yolo" - (&;at-most +17 &;hex-digit))))) - - (assert "Can lex tokens between lower and upper boundaries of quantity." - (and (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F") - (&;run "0123456789ABCDEF yolo" - (&;between +0 +16 &;hex-digit))) - (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F") - (&;run "0123456789ABCDEF yolo" - (&;between +3 +16 &;hex-digit))) - (should-fail (&;run "0123456789ABCDEF yolo" - (&;between +17 +100 &;hex-digit))) - (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F") - (&;run "0123456789ABCDEF yolo" - (&;between +15 +20 &;hex-digit))))) - - (assert "Can optionally lex a token." - (and (|> (&;run "123abc" - (&;opt &;hex-digit)) - (case> (#;Right (#;Some #"1")) true - _ false)) - (|> (&;run "yolo" - (&;opt &;hex-digit)) - (case> (#;Right #;None) true - _ false)))) - - (assert "Can take into account separators during lexing." - (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"a" #"b" #"c" #"d" #"e" #"f") - (&;run "0 1 2 3 4 5 6 7 8 9 a b c d e f YOLO" - (&;sep-by &;space &;hex-digit)))) - - (assert "Can obtain the whole of the remaining input." - (should-passT "yolo" (&;run "yolo" - &;get-input))) - )) diff --git a/stdlib/test/test/lux/lexer/regex.lux b/stdlib/test/test/lux/lexer/regex.lux deleted file mode 100644 index 1a21111f8..000000000 --- a/stdlib/test/test/lux/lexer/regex.lux +++ /dev/null @@ -1,285 +0,0 @@ -(;module: - lux - (lux [io] - (control monad) - (data [error #- fail] - [product] - [text "T/" Eq] - text/format) - [compiler] - (macro [ast] - ["s" syntax #+ syntax:]) - ["R" math/random] - pipe - [lexer] - (lexer ["&" regex])) - lux/test) - -## [Utils] -(def: (should-pass regex input) - (-> (lexer;Lexer Text) Text Bool) - (|> (lexer;run input regex) - (case> (#;Right parsed) - (T/= parsed input) - - _ - false))) - -(def: (should-passT test regex input) - (-> Text (lexer;Lexer Text) Text Bool) - (|> (lexer;run input regex) - (case> (#;Right parsed) - (T/= test parsed) - - _ - false))) - -(def: (should-fail regex input) - (All [a] (-> (lexer;Lexer a) Text Bool)) - (|> (lexer;run input regex) - (case> (#;Left _) true _ false))) - -(syntax: (should-check pattern regex input) - (wrap (list (` (|> (lexer;run (~ input) (~ regex)) - (case> (^ (#;Right (~ pattern))) - true - - (~' _) - false)))))) - -## [Tests] -(test: "Regular Expressions [Basics]" - (assert "Can parse character literals." - (and (should-pass (&;regex "a") "a") - (should-fail (&;regex "a") ".") - (should-pass (&;regex "\\.") ".") - (should-fail (&;regex "\\.") "a")))) - -(test: "Regular Expressions [System character classes]" - ($_ seq - (assert "Can parse anything." - (should-pass (&;regex ".") "a")) - - (assert "Can parse digits." - (and (should-pass (&;regex "\\d") "0") - (should-fail (&;regex "\\d") "m"))) - - (assert "Can parse non digits." - (and (should-pass (&;regex "\\D") "m") - (should-fail (&;regex "\\D") "0"))) - - (assert "Can parse white-space." - (and (should-pass (&;regex "\\s") " ") - (should-fail (&;regex "\\s") "m"))) - - (assert "Can parse non white-space." - (and (should-pass (&;regex "\\S") "m") - (should-fail (&;regex "\\S") " "))) - - (assert "Can parse word characters." - (and (should-pass (&;regex "\\w") "_") - (should-fail (&;regex "\\w") "^"))) - - (assert "Can parse non word characters." - (and (should-pass (&;regex "\\W") ".") - (should-fail (&;regex "\\W") "a"))) - )) - -(test: "Regular Expressions [Special system character classes : Part 1]" - ($_ seq - (assert "Can parse using special character classes." - (and (and (should-pass (&;regex "\\p{Lower}") "m") - (should-fail (&;regex "\\p{Lower}") "M")) - - (and (should-pass (&;regex "\\p{Upper}") "M") - (should-fail (&;regex "\\p{Upper}") "m")) - - (and (should-pass (&;regex "\\p{Alpha}") "M") - (should-fail (&;regex "\\p{Alpha}") "0")) - - (and (should-pass (&;regex "\\p{Digit}") "1") - (should-fail (&;regex "\\p{Digit}") "n")) - - (and (should-pass (&;regex "\\p{Alnum}") "1") - (should-fail (&;regex "\\p{Alnum}") ".")) - - (and (should-pass (&;regex "\\p{Space}") " ") - (should-fail (&;regex "\\p{Space}") ".")) - )) - )) - -(test: "Regular Expressions [Special system character classes : Part 2]" - ($_ seq - (assert "Can parse using special character classes." - (and (and (should-pass (&;regex "\\p{HexDigit}") "a") - (should-fail (&;regex "\\p{HexDigit}") ".")) - - (and (should-pass (&;regex "\\p{OctDigit}") "6") - (should-fail (&;regex "\\p{OctDigit}") ".")) - - (and (should-pass (&;regex "\\p{Blank}") "\t") - (should-fail (&;regex "\\p{Blank}") ".")) - - (and (should-pass (&;regex "\\p{ASCII}") "\t") - (should-fail (&;regex "\\p{ASCII}") "\u1234")) - - (and (should-pass (&;regex "\\p{Contrl}") "\u0012") - (should-fail (&;regex "\\p{Contrl}") "a")) - - (and (should-pass (&;regex "\\p{Punct}") "@") - (should-fail (&;regex "\\p{Punct}") "a")) - - (and (should-pass (&;regex "\\p{Graph}") "@") - (should-fail (&;regex "\\p{Graph}") " ")) - - (and (should-pass (&;regex "\\p{Print}") "\u0020") - (should-fail (&;regex "\\p{Print}") "\u1234")) - )) - )) - -(test: "Regular Expressions [Custom character classes : Part 1]" - ($_ seq - (assert "Can parse using custom character classes." - (and (should-pass (&;regex "[abc]") "a") - (should-fail (&;regex "[abc]") "m"))) - - (assert "Can parse using character ranges." - (and (should-pass (&;regex "[a-z]") "a") - (should-pass (&;regex "[a-z]") "m") - (should-pass (&;regex "[a-z]") "z"))) - - (assert "Can combine character ranges." - (and (should-pass (&;regex "[a-zA-Z]") "a") - (should-pass (&;regex "[a-zA-Z]") "m") - (should-pass (&;regex "[a-zA-Z]") "z") - (should-pass (&;regex "[a-zA-Z]") "A") - (should-pass (&;regex "[a-zA-Z]") "M") - (should-pass (&;regex "[a-zA-Z]") "Z"))) - )) - -(test: "Regular Expressions [Custom character classes : Part 2]" - ($_ seq - (assert "Can negate custom character classes." - (and (should-fail (&;regex "[^abc]") "a") - (should-pass (&;regex "[^abc]") "m"))) - - (assert "Can negate character ranges.." - (and (should-fail (&;regex "[^a-z]") "a") - (should-pass (&;regex "[^a-z]") "0"))) - - (assert "Can parse negate combinations of character ranges." - (and (should-fail (&;regex "[^a-zA-Z]") "a") - (should-pass (&;regex "[^a-zA-Z]") "0"))) - )) - -(test: "Regular Expressions [Custom character classes : Part 3]" - ($_ seq - (assert "Can make custom character classes more specific." - (and (let [RE (&;regex "[a-z&&[def]]")] - (and (should-fail RE "a") - (should-pass RE "d"))) - - (let [RE (&;regex "[a-z&&[^bc]]")] - (and (should-pass RE "a") - (should-fail RE "b"))) - - (let [RE (&;regex "[a-z&&[^m-p]]")] - (and (should-pass RE "a") - (should-fail RE "m") - (should-fail RE "p"))))) - )) - -(test: "Regular Expressions [Reference]" - (let [number (&;regex "\\d+")] - (assert "Can build complex regexs by combining simpler ones." - (should-check ["809-345-6789" "809" "345" "6789"] (&;regex "(\\@)-(\\@)-(\\@)") "809-345-6789")))) - -(test: "Regular Expressions [Fuzzy Quantifiers]" - ($_ seq - (assert "Can sequentially combine patterns." - (should-passT "aa" (&;regex "aa") "aa")) - - (assert "Can match patterns optionally." - (and (should-passT "a" (&;regex "a?") "a") - (should-passT "" (&;regex "a?") ""))) - - (assert "Can match a pattern 0 or more times." - (and (should-passT "aaa" (&;regex "a*") "aaa") - (should-passT "" (&;regex "a*") ""))) - - (assert "Can match a pattern 1 or more times." - (and (should-passT "aaa" (&;regex "a+") "aaa") - (should-passT "a" (&;regex "a+") "a") - (should-fail (&;regex "a+") ""))) - )) - -(test: "Regular Expressions [Crisp Quantifiers]" - ($_ seq - (assert "Can match a pattern N times." - (and (should-passT "aa" (&;regex "a{2}") "aa") - (should-passT "a" (&;regex "a{1}") "aa") - (should-fail (&;regex "a{3}") "aa"))) - - (assert "Can match a pattern at-least N times." - (and (should-passT "aa" (&;regex "a{1,}") "aa") - (should-passT "aa" (&;regex "a{2,}") "aa") - (should-fail (&;regex "a{3,}") "aa"))) - - (assert "Can match a pattern at-most N times." - (and (should-passT "a" (&;regex "a{,1}") "aa") - (should-passT "aa" (&;regex "a{,2}") "aa") - (should-passT "aa" (&;regex "a{,3}") "aa"))) - - (assert "Can match a pattern between N and M times." - (and (should-passT "a" (&;regex "a{1,2}") "a") - (should-passT "aa" (&;regex "a{1,2}") "aa") - (should-passT "aa" (&;regex "a{1,2}") "aaa"))) - )) - -(test: "Regular Expressions [Groups]" - ($_ seq - (assert "Can extract groups of sub-matches specified in a pattern." - (and (should-check ["abc" "b"] (&;regex "a(.)c") "abc") - (should-check ["abbbbbc" "bbbbb"] (&;regex "a(b+)c") "abbbbbc") - (should-check ["809-345-6789" "809" "345" "6789"] (&;regex "(\\d{3})-(\\d{3})-(\\d{4})") "809-345-6789") - (should-check ["809-345-6789" "809" "6789"] (&;regex "(\\d{3})-(?:\\d{3})-(\\d{4})") "809-345-6789") - (should-check ["809-809-6789" "809" "6789"] (&;regex "(\\d{3})-\\0-(\\d{4})") "809-809-6789") - (should-check ["809-809-6789" "809" "6789"] (&;regex "(?\\d{3})-\\k-(\\d{4})") "809-809-6789") - (should-check ["809-809-6789-6789" "809" "6789"] (&;regex "(?\\d{3})-\\k-(\\d{4})-\\0") "809-809-6789-6789"))) - - (assert "Can specify groups within groups." - (should-check ["809-345-6789" "809" ["345-6789" "345" "6789"]] (&;regex "(\\d{3})-((\\d{3})-(\\d{4}))") "809-345-6789")) - )) - -(test: "Regular Expressions [Alternation]" - ($_ seq - (assert "Can specify alternative patterns." - (and (should-check ["a" (+0 [])] (&;regex "a|b") "a") - (should-check ["b" (+1 [])] (&;regex "a|b") "b") - (should-fail (&;regex "a|b") "c"))) - - (assert "Can have groups within alternations." - (and (should-check ["abc" (+0 ["b" "c"])] (&;regex "a(.)(.)|b(.)(.)") "abc") - (should-check ["bcd" (+1 ["c" "d"])] (&;regex "a(.)(.)|b(.)(.)") "bcd") - (should-fail (&;regex "a(.)(.)|b(.)(.)") "cde") - - (should-check ["809-345-6789" (+0 ["809" "345-6789" "345" "6789"])] - (&;regex "(\\d{3})-((\\d{3})-(\\d{4}))|b(.)d") - "809-345-6789"))) - )) - -(test: "Pattern-matching" - [sample1 (R;text +3) - sample2 (R;text +3) - sample3 (R;text +4)] - (case (format sample1 "-" sample2 "-" sample3) - (&;^regex "(.{3})-(.{3})-(.{4})" - [_ match1 match2 match3]) - (assert "Can pattern-match using regular-expressions." - (and (T/= sample1 match1) - (T/= sample2 match2) - (T/= sample3 match3))) - - _ - (assert "Cannot pattern-match using regular-expressions." - false))) diff --git a/stdlib/test/test/lux/macro/ast.lux b/stdlib/test/test/lux/macro/ast.lux index 768dafbf8..95ac999a0 100644 --- a/stdlib/test/test/lux/macro/ast.lux +++ b/stdlib/test/test/lux/macro/ast.lux @@ -6,7 +6,6 @@ text/format [number]) ["R" math/random] - pipe (macro ["&" ast])) lux/test) diff --git a/stdlib/test/test/lux/macro/poly/eq.lux b/stdlib/test/test/lux/macro/poly/eq.lux index c2f9c0ac1..3cd515fc6 100644 --- a/stdlib/test/test/lux/macro/poly/eq.lux +++ b/stdlib/test/test/lux/macro/poly/eq.lux @@ -9,7 +9,6 @@ [char] [text]) ["R" math/random] - pipe [macro] (macro [poly #+ derived:] ["&" poly/eq])) diff --git a/stdlib/test/test/lux/macro/poly/functor.lux b/stdlib/test/test/lux/macro/poly/functor.lux index b98d75c7a..3294556a4 100644 --- a/stdlib/test/test/lux/macro/poly/functor.lux +++ b/stdlib/test/test/lux/macro/poly/functor.lux @@ -10,7 +10,6 @@ [char] [text]) ["R" math/random] - pipe [macro] (macro [poly #+ derived:] ["&" poly/functor])) diff --git a/stdlib/test/test/lux/macro/poly/text-encoder.lux b/stdlib/test/test/lux/macro/poly/text-encoder.lux index ec312e62b..ec392fc8e 100644 --- a/stdlib/test/test/lux/macro/poly/text-encoder.lux +++ b/stdlib/test/test/lux/macro/poly/text-encoder.lux @@ -9,7 +9,6 @@ [char] [text]) ["R" math/random] - pipe [macro] (macro [poly #+ derived:] ["&" poly/text-encoder])) diff --git a/stdlib/test/test/lux/macro/syntax.lux b/stdlib/test/test/lux/macro/syntax.lux index b9dd304e1..11d456236 100644 --- a/stdlib/test/test/lux/macro/syntax.lux +++ b/stdlib/test/test/lux/macro/syntax.lux @@ -11,7 +11,6 @@ [ident] [error #- fail]) ["R" math/random] - pipe [compiler] (macro [ast] ["s" syntax #+ syntax: Syntax])) diff --git a/stdlib/test/test/lux/math.lux b/stdlib/test/test/lux/math.lux index 4d8b8d12a..2b834b9cc 100644 --- a/stdlib/test/test/lux/math.lux +++ b/stdlib/test/test/lux/math.lux @@ -9,7 +9,6 @@ (coll [list "List/" Fold Functor]) [product]) ["R" math/random] - pipe ["&" math]) lux/test) diff --git a/stdlib/test/test/lux/math/logic/continuous.lux b/stdlib/test/test/lux/math/logic/continuous.lux index fa08ec864..b1770c815 100644 --- a/stdlib/test/test/lux/math/logic/continuous.lux +++ b/stdlib/test/test/lux/math/logic/continuous.lux @@ -3,7 +3,6 @@ (lux [io] (control monad) ["R" math/random] - pipe ["&" math/logic/continuous]) lux/test) diff --git a/stdlib/test/test/lux/math/logic/fuzzy.lux b/stdlib/test/test/lux/math/logic/fuzzy.lux index afcd8b731..284fffa4b 100644 --- a/stdlib/test/test/lux/math/logic/fuzzy.lux +++ b/stdlib/test/test/lux/math/logic/fuzzy.lux @@ -8,7 +8,6 @@ [number] text/format) ["R" math/random] - pipe (math/logic ["&" fuzzy] continuous)) lux/test) diff --git a/stdlib/test/test/lux/math/simple.lux b/stdlib/test/test/lux/math/simple.lux index 32f5fb20c..9aec7f1fc 100644 --- a/stdlib/test/test/lux/math/simple.lux +++ b/stdlib/test/test/lux/math/simple.lux @@ -9,7 +9,6 @@ (coll [list "List/" Fold Functor]) [product]) ["R" math/random] - pipe ["&" math/simple]) lux/test) diff --git a/stdlib/test/test/lux/pipe.lux b/stdlib/test/test/lux/pipe.lux deleted file mode 100644 index 08866a3f4..000000000 --- a/stdlib/test/test/lux/pipe.lux +++ /dev/null @@ -1,74 +0,0 @@ -(;module: - lux - (lux [io] - (control monad) - (data text/format - [number] - [product] - identity - [text "T/" Eq]) - ["R" math/random] - pipe) - lux/test) - -(test: "Pipes" - ($_ seq - (assert "Can dismiss previous pipeline results and begin a new line." - (|> 20 - (i.* 3) - (i.+ 4) - (_> 0 i.inc) - (i.= 1))) - - (assert "Can give names to piped values within a pipeline's scope." - (and (|> 5 - (@> [(i.+ @ @)]) - (i.= 10)) - (|> 5 - (@> X [(i.+ X X)]) - (i.= 10)))) - - (assert "Can do branching in pipelines." - (and (|> 5 - (?> [i.even?] [(i.* 2)] - [i.odd?] [(i.* 3)] - [(_> -1)]) - (i.= 15)) - (|> 4 - (?> [i.even?] [(i.* 2)] - [i.odd?] [(i.* 3)]) - (i.= 8)) - (|> 5 - (?> [i.even?] [(i.* 2)] - [(_> -1)]) - (i.= -1)))) - - (assert "Can loop within pipelines." - (|> 1 - (!> [(i.< 10)] - [i.inc]) - (i.= 10))) - - (assert "Can use monads within pipelines." - (|> 5 - (%> Monad - [(i.* 3)] - [(i.+ 4)] - [i.inc]) - (i.= 20))) - - (assert "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" - _ "???") - (T/= "five"))) - )) diff --git a/stdlib/test/test/lux/type.lux b/stdlib/test/test/lux/type.lux index e9401c738..d1098b960 100644 --- a/stdlib/test/test/lux/type.lux +++ b/stdlib/test/test/lux/type.lux @@ -1,14 +1,14 @@ (;module: lux (lux [io] - (control monad) + (control monad + pipe) (data [text "Text/" Monoid] text/format [number] maybe (coll [list])) ["R" math/random] - pipe ["&" type]) lux/test) diff --git a/stdlib/test/test/lux/type/auto.lux b/stdlib/test/test/lux/type/auto.lux index 536e3b851..c7e321240 100644 --- a/stdlib/test/test/lux/type/auto.lux +++ b/stdlib/test/test/lux/type/auto.lux @@ -11,7 +11,6 @@ maybe (coll [list])) ["R" math/random] - pipe [type] type/auto) lux/test) @@ -32,4 +31,9 @@ (::: = (list;n.range +1 +10) (list;n.range +1 +10))) + + (assert "Can automatically select third-order structures." + (let [lln (::: map (list;n.range +1) + (list;n.range +1 +10))] + (::: = lln lln))) )) diff --git a/stdlib/test/test/lux/type/check.lux b/stdlib/test/test/lux/type/check.lux index 47904c41b..d76a53622 100644 --- a/stdlib/test/test/lux/type/check.lux +++ b/stdlib/test/test/lux/type/check.lux @@ -8,7 +8,6 @@ maybe (coll [list])) ["R" math/random] - pipe [type] ["&" type/check]) lux/test) diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux index c773b3f17..6b23caebd 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/tests.lux @@ -9,9 +9,6 @@ (lux ["_;" cli] ["_;" host] ["_;" io] - ["_;" pipe] - ["_;" lexer] - (lexer ["_;" regex]) (function ["_;" cont] ["_;" reader] ["_;" state] @@ -22,45 +19,44 @@ ["_;" promise] ["_;" stm]) (control ["_;" effect] - ["_;" interval]) - (data [bit] - [bool] - [char] - [error] - [ident] - [identity] - [log] - [maybe] - [number] + ["_;" interval] + ["_;" pipe]) + (data ["_;" bit] + ["_;" bool] + ["_;" char] + ["_;" error] + ["_;" ident] + ["_;" identity] + ["_;" log] + ["_;" maybe] + ["_;" number] (number ["_;" ratio] ["_;" complex]) - [product] - [sum] - [text] - (error [exception]) - (format [json]) - (coll [array] - [dict] - [list] - [queue] - [set] - [ordered] - [stack] - ## [vector] - (tree [rose] - [zipper]) + ["_;" product] + ["_;" sum] + ["_;" text] + (error ["_;" exception]) + (format ["_;" json]) + (coll ["_;" array] + ["_;" dict] + ["_;" list] + ["_;" queue] + ["_;" set] + ["_;" ordered] + ["_;" stack] + ["_;" vector] + (tree ["_;" rose] + ["_;" zipper]) ["_;" seq] ["_;" priority-queue] ["_;" stream]) - (text [format]) - ) + (text ["_;" format] + ["_;" lexer] + ["_;" regex])) ["_;" math] (math ["_;" simple] (logic ["_;" continuous] - ["_;" fuzzy]) - ## ["_;" random] - ) - ## ["_;" macro] + ["_;" fuzzy])) (macro ["_;" ast] ["_;" syntax] (poly ["poly_;" eq] @@ -69,7 +65,13 @@ ["_;" type] (type ["_;" check] ["_;" auto]) - ))) + )) + (lux (control [contract]) + (data [env] + [trace] + [store]) + [macro] + (math [random]))) ## [Program] (program: args -- cgit v1.2.3