diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/test/lux/abstract/enum.lux | 4 | ||||
-rw-r--r-- | stdlib/source/test/lux/control.lux | 4 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/concurrency/semaphore.lux | 5 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/parser/xml.lux | 171 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/region.lux | 9 | ||||
-rw-r--r-- | stdlib/source/test/lux/data/binary.lux | 3 | ||||
-rw-r--r-- | stdlib/source/test/lux/data/collection/list.lux | 14 | ||||
-rw-r--r-- | stdlib/source/test/lux/data/collection/sequence.lux | 21 | ||||
-rw-r--r-- | stdlib/source/test/lux/math/logic/fuzzy.lux | 6 | ||||
-rw-r--r-- | stdlib/source/test/lux/type/implicit.lux | 15 |
10 files changed, 213 insertions, 39 deletions
diff --git a/stdlib/source/test/lux/abstract/enum.lux b/stdlib/source/test/lux/abstract/enum.lux index c020ec211..17e1d0cce 100644 --- a/stdlib/source/test/lux/abstract/enum.lux +++ b/stdlib/source/test/lux/abstract/enum.lux @@ -32,6 +32,9 @@ (let [expected-size (|> end (n.- start) inc) expected-start? (|> range list.head (maybe@map (n.= start)) (maybe.default false)) expected-end? (|> range list.last (maybe@map (n.= end)) (maybe.default false)) + can-be-backwards? (:: (list.equivalence n.equivalence) = + (/.range n.enum start end) + (list.reverse (/.range n.enum end start))) every-element-is-a-successor? (case range (#.Cons head tail) (|> (list@fold (function (_ next [verdict prev]) @@ -47,5 +50,6 @@ (and (n.= expected-size (list.size range)) expected-start? expected-end? + can-be-backwards? every-element-is-a-successor?))) ))))) diff --git a/stdlib/source/test/lux/control.lux b/stdlib/source/test/lux/control.lux index fe35c0500..b3e55e901 100644 --- a/stdlib/source/test/lux/control.lux +++ b/stdlib/source/test/lux/control.lux @@ -27,7 +27,8 @@ ["#/." synthesis] ["#/." text] ["#/." tree] - ["#/." type]] + ["#/." type] + ["#/." xml]] ["#." pipe] ["#." reader] ["#." region] @@ -73,6 +74,7 @@ /parser/text.test /parser/tree.test /parser/type.test + /parser/xml.test )) (def: security diff --git a/stdlib/source/test/lux/control/concurrency/semaphore.lux b/stdlib/source/test/lux/control/concurrency/semaphore.lux index 469ff4308..dcdb78f78 100644 --- a/stdlib/source/test/lux/control/concurrency/semaphore.lux +++ b/stdlib/source/test/lux/control/concurrency/semaphore.lux @@ -2,7 +2,8 @@ [lux #* ["_" test (#+ Test)] [abstract - ["." monad (#+ do)]] + ["." monad (#+ do)] + ["." enum]] [control ["." io] ["." try] @@ -153,7 +154,7 @@ [#let [ending (|> "_" (list.repeat limit) (text.join-with "")) - ids (list.n/range 0 (dec limit)) + ids (enum.range n.enum 0 (dec limit)) waiters (list@map (function (_ id) (exec (io.run (atom.update (|>> (format "_")) resource)) (waiter resource barrier id))) diff --git a/stdlib/source/test/lux/control/parser/xml.lux b/stdlib/source/test/lux/control/parser/xml.lux new file mode 100644 index 000000000..15e0e993b --- /dev/null +++ b/stdlib/source/test/lux/control/parser/xml.lux @@ -0,0 +1,171 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)]] + [control + ["." try] + ["." exception]] + [data + ["." text ("#@." equivalence)] + ["." name] + [format + ["." xml]] + [number + ["n" nat]] + [collection + ["." dictionary]]] + [math + ["." random (#+ Random)]] + [macro + ["." template]] + ["." type ("#@." equivalence)]] + {1 + ["." / + ["/#" // ("#@." monad)]]}) + +(template: (!expect <pattern> <value>) + (case <value> + <pattern> + true + + _ + false)) + +(template: (!failure <exception> <cases>) + (with-expansions [<<cases>> (template.splice <cases>)] + (do {@ random.monad} + [expected (random.ascii/alpha 1)] + (_.cover [<exception>] + (`` (and (~~ (template [<parser> <input>] + [(|> (/.run <parser> <input>) + (!expect (^multi (#try.Failure error) + (exception.match? <exception> error))))] + + <<cases>>)))))))) + +(def: random-label + (Random Name) + (random.and (random.ascii/alpha 1) + (random.ascii/alpha 1))) + +(def: random-tag ..random-label) +(def: random-attribute ..random-label) + +(def: #export test + Test + (<| (_.covering /._) + (_.with-cover [/.Parser]) + ($_ _.and + (do {@ random.monad} + [expected (random.ascii/alpha 1)] + (_.cover [/.run /.text] + (|> (/.run /.text (#xml.Text expected)) + (!expect (^multi (#try.Success actual) + (text@= expected actual)))))) + (!failure /.unconsumed-inputs + [[(//@wrap expected) + (#xml.Text expected)]]) + (do {@ random.monad} + [expected (random.ascii/alpha 1)] + (_.cover [/.ignore] + (|> (/.run /.ignore (#xml.Text expected)) + (!expect (#try.Success []))))) + (do {@ random.monad} + [expected ..random-tag] + (_.cover [/.node] + (|> (/.run (do //.monad + [_ (/.node expected)] + /.ignore) + (#xml.Node expected (dictionary.new name.hash) (list))) + (!expect (#try.Success []))))) + (!failure /.wrong-tag + [[(/.node ["" expected]) + (#xml.Node [expected ""] (dictionary.new name.hash) (list))]]) + (do {@ random.monad} + [expected-tag ..random-tag + expected-attribute ..random-attribute + expected-value (random.ascii/alpha 1)] + (_.cover [/.attr] + (|> (/.run (do //.monad + [_ (/.node expected-tag) + _ (/.attr expected-attribute)] + /.ignore) + (#xml.Node expected-tag + (|> (dictionary.new name.hash) + (dictionary.put expected-attribute expected-value)) + (list))) + (!expect (#try.Success []))))) + (!failure /.unknown-attribute + [[(do //.monad + [_ (/.attr ["" expected])] + /.ignore) + (#xml.Node [expected expected] + (|> (dictionary.new name.hash) + (dictionary.put [expected ""] expected)) + (list))]]) + (do {@ random.monad} + [expected ..random-tag] + (_.cover [/.children] + (|> (/.run (do {@ //.monad} + [_ (/.node expected)] + (/.children + (do @ + [_ (/.node expected)] + /.ignore))) + (#xml.Node expected + (dictionary.new name.hash) + (list (#xml.Node expected + (dictionary.new name.hash) + (list))))) + (!expect (#try.Success []))))) + (!failure /.empty-input + [[(do //.monad + [_ /.ignore] + /.ignore) + (#xml.Text expected)] + [(do //.monad + [_ /.ignore] + /.text) + (#xml.Text expected)] + [(do //.monad + [_ /.ignore] + (/.node [expected expected])) + (#xml.Node [expected expected] + (dictionary.new name.hash) + (list))] + [(do //.monad + [_ /.ignore] + (/.node [expected expected])) + (#xml.Node [expected expected] + (|> (dictionary.new name.hash) + (dictionary.put [expected expected] expected)) + (list))] + [(do //.monad + [_ /.ignore] + (/.children + (/.node [expected expected]))) + (#xml.Node [expected expected] + (dictionary.new name.hash) + (list (#xml.Node [expected expected] + (dictionary.new name.hash) + (list))))]]) + (!failure /.unexpected-input + [[/.text + (#xml.Node [expected expected] (dictionary.new name.hash) (list))] + [(do //.monad + [_ (/.node [expected expected])] + /.ignore) + (#xml.Text expected)] + [(do //.monad + [_ (/.attr [expected expected])] + /.ignore) + (#xml.Text expected)] + [(do {@ //.monad} + [_ (/.node [expected expected])] + (/.children + (do @ + [_ (/.node [expected expected])] + /.ignore))) + (#xml.Text expected)]]) + ))) diff --git a/stdlib/source/test/lux/control/region.lux b/stdlib/source/test/lux/control/region.lux index d0c9eef40..550b3b872 100644 --- a/stdlib/source/test/lux/control/region.lux +++ b/stdlib/source/test/lux/control/region.lux @@ -6,6 +6,7 @@ [functor (#+ Functor)] [apply (#+ Apply)] ["." monad (#+ Monad do)] + ["." enum] {[0 #spec] [/ ["$." functor (#+ Injection Comparison)] @@ -100,7 +101,7 @@ outcome (/.run @ (do {@ (/.monad @)} [_ (monad.map @ (/.acquire //@ count-clean-up) - (list.n/range 1 expected-clean-ups))] + (enum.range n.enum 1 expected-clean-ups))] (wrap []))) actual-clean-ups (thread.read clean-up-counter)] (wrap (and (success? outcome) @@ -118,7 +119,7 @@ outcome (/.run @ (do {@ (/.monad @)} [_ (monad.map @ (/.acquire //@ count-clean-up) - (list.n/range 1 expected-clean-ups)) + (enum.range n.enum 1 expected-clean-ups)) _ (/.fail //@ (exception.construct ..oops []))] (wrap []))) actual-clean-ups (thread.read clean-up-counter)] @@ -137,7 +138,7 @@ outcome (/.run @ (do {@ (/.monad @)} [_ (monad.map @ (/.acquire //@ count-clean-up) - (list.n/range 1 expected-clean-ups)) + (enum.range n.enum 1 expected-clean-ups)) _ (/.throw //@ ..oops [])] (wrap []))) actual-clean-ups (thread.read clean-up-counter)] @@ -157,7 +158,7 @@ outcome (/.run @ (do {@ (/.monad @)} [_ (monad.map @ (/.acquire //@ count-clean-up) - (list.n/range 1 expected-clean-ups))] + (enum.range n.enum 1 expected-clean-ups))] (wrap []))) actual-clean-ups (thread.read clean-up-counter)] (wrap (and (or (n.= 0 expected-clean-ups) diff --git a/stdlib/source/test/lux/data/binary.lux b/stdlib/source/test/lux/data/binary.lux index 508a2c1af..492fdac24 100644 --- a/stdlib/source/test/lux/data/binary.lux +++ b/stdlib/source/test/lux/data/binary.lux @@ -5,6 +5,7 @@ ["_" test (#+ Test)] [abstract ["." monad (#+ do)] + ["." enum] {[0 #spec] [/ ["$." equivalence]]}] @@ -78,7 +79,7 @@ (_.test "Can slice binaries." (let [slice-size (|> to (n.- from) inc) random-slice (try.assume (/.slice from to random-binary)) - idxs (list.n/range 0 (dec slice-size)) + idxs (enum.range n.enum 0 (dec slice-size)) reader (function (_ binary idx) (/.read/8 idx binary))] (and (n.= slice-size (/.size random-slice)) (case [(monad.map try.monad (reader random-slice) idxs) diff --git a/stdlib/source/test/lux/data/collection/list.lux b/stdlib/source/test/lux/data/collection/list.lux index a49a71e38..e1f469fae 100644 --- a/stdlib/source/test/lux/data/collection/list.lux +++ b/stdlib/source/test/lux/data/collection/list.lux @@ -4,6 +4,7 @@ ["_" test (#+ Test)] [abstract [monad (#+ do)] + ["." enum] {[0 #spec] [/ ["$." equivalence] @@ -171,7 +172,7 @@ (and (not (/.any? n.even? sample)) (/.every? (bit.complement n.even?) sample)))) (_.test "You can iteratively construct a list, generating values until you're done." - (/@= (/.n/range 0 (dec size)) + (/@= (enum.range n.enum 0 (dec size)) (/.iterate (function (_ n) (if (n.< size n) (#.Some (inc n)) #.None)) 0))) (_.test "Can enumerate all elements in a list." @@ -180,15 +181,4 @@ (/@map product.left enum-sample)) (/@= sample (/@map product.right enum-sample))))) - (do @ - [from (|> r.nat (:: @ map (n.% 10))) - to (|> r.nat (:: @ map (n.% 10)))] - (_.test "Ranges can be constructed forward and backwards." - (and (/@= (/.n/range from to) - (/.reverse (/.n/range to from))) - (let [from (.int from) - to (.int to) - (^open "/@.") (/.equivalence int.equivalence)] - (/@= (/.i/range from to) - (/.reverse (/.i/range to from))))))) )))) diff --git a/stdlib/source/test/lux/data/collection/sequence.lux b/stdlib/source/test/lux/data/collection/sequence.lux index 4b204d37a..f47629d70 100644 --- a/stdlib/source/test/lux/data/collection/sequence.lux +++ b/stdlib/source/test/lux/data/collection/sequence.lux @@ -5,7 +5,8 @@ [abstract comonad [functor (#+)] - [monad (#+ do)]] + [monad (#+ do)] + ["." enum]] [data ["." maybe] [number @@ -33,31 +34,31 @@ sample1 (/.iterate inc offset)]] ($_ _.and (_.test "Can move along a sequence and take slices off it." - (and (and (list@= (list.n/range 0 (dec size)) + (and (and (list@= (enum.range n.enum 0 (dec size)) (/.take size sample0)) - (list@= (list.n/range offset (dec (n.+ offset size))) + (list@= (enum.range n.enum offset (dec (n.+ offset size))) (/.take size (/.drop offset sample0))) (let [[drops takes] (/.split size sample0)] - (and (list@= (list.n/range 0 (dec size)) + (and (list@= (enum.range n.enum 0 (dec size)) drops) - (list@= (list.n/range size (dec (n.* 2 size))) + (list@= (enum.range n.enum size (dec (n.* 2 size))) (/.take size takes))))) - (and (list@= (list.n/range 0 (dec size)) + (and (list@= (enum.range n.enum 0 (dec size)) (/.take-while (n.< size) sample0)) - (list@= (list.n/range offset (dec (n.+ offset size))) + (list@= (enum.range n.enum offset (dec (n.+ offset size))) (/.take-while (n.< (n.+ offset size)) (/.drop-while (n.< offset) sample0))) (let [[drops takes] (/.split-while (n.< size) sample0)] - (and (list@= (list.n/range 0 (dec size)) + (and (list@= (enum.range n.enum 0 (dec size)) drops) - (list@= (list.n/range size (dec (n.* 2 size))) + (list@= (enum.range n.enum size (dec (n.* 2 size))) (/.take-while (n.< (n.* 2 size)) takes))))) )) (_.test "Can repeat any element and infinite number of times." (n.= elem (/.nth offset (/.repeat elem)))) (_.test "Can obtain the head & tail of a sequence." (and (n.= offset (/.head sample1)) - (list@= (list.n/range (inc offset) (n.+ offset size)) + (list@= (enum.range n.enum (inc offset) (n.+ offset size)) (/.take size (/.tail sample1))))) (_.test "Can filter sequences." (and (n.= (n.* 2 offset) diff --git a/stdlib/source/test/lux/math/logic/fuzzy.lux b/stdlib/source/test/lux/math/logic/fuzzy.lux index eeace02be..d692cb3f4 100644 --- a/stdlib/source/test/lux/math/logic/fuzzy.lux +++ b/stdlib/source/test/lux/math/logic/fuzzy.lux @@ -1,7 +1,9 @@ (.module: [lux #* ["%" data/text/format (#+ format)] - [abstract/monad (#+ do)] + [abstract + [monad (#+ do)] + ["." enum]] [math ["." random (#+ Random)]] ["_" test (#+ Test)] @@ -142,7 +144,7 @@ (def: predicates-and-sets Test (do {@ random.monad} - [#let [set-10 (set.from-list n.hash (list.n/range 0 10))] + [#let [set-10 (set.from-list n.hash (enum.range n.enum 0 10))] sample (|> random.nat (:: @ map (n.% 20)))] ($_ _.and (_.test (%.name (name-of /.from-predicate)) diff --git a/stdlib/source/test/lux/type/implicit.lux b/stdlib/source/test/lux/type/implicit.lux index 520776996..7c55a0d6f 100644 --- a/stdlib/source/test/lux/type/implicit.lux +++ b/stdlib/source/test/lux/type/implicit.lux @@ -5,7 +5,8 @@ [abstract [equivalence (#+)] [functor (#+)] - [monad (#+ do)]] + [monad (#+ do)] + ["." enum]] [data ["." bit ("#@." equivalence)] [number @@ -31,14 +32,14 @@ (let [(^open "list@.") (list.equivalence n.equivalence)] (and (bit@= (:: n.equivalence = left right) (/.::: = left right)) - (list@= (:: list.functor map inc (list.n/range start end)) - (/.::: map inc (list.n/range start end)))))) + (list@= (:: list.functor map inc (enum.range n.enum start end)) + (/.::: map inc (enum.range n.enum start end)))))) (_.test "Can automatically select second-order structures." (/.::: = - (list.n/range start end) - (list.n/range start end))) + (enum.range n.enum start end) + (enum.range n.enum start end))) (_.test "Can automatically select third-order structures." - (let [lln (/.::: map (list.n/range start) - (list.n/range start end))] + (let [lln (/.::: map (enum.range n.enum start) + (enum.range n.enum start end))] (/.::: = lln lln))) )))) |