diff options
Diffstat (limited to 'stdlib/source')
-rw-r--r-- | stdlib/source/lux/test.lux | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/stdlib/source/lux/test.lux b/stdlib/source/lux/test.lux index b104df4f9..ab64ee86e 100644 --- a/stdlib/source/lux/test.lux +++ b/stdlib/source/lux/test.lux @@ -38,7 +38,7 @@ (All [a] (-> Text Test)) (:: Monad<Promise> wrap (#E;Error message))) -(def: #export (assert message condition) +(def: #export (test message condition) {#;doc "Check that a condition is true, and fail with the given message otherwise."} (-> Text Bool Test) (if condition @@ -160,65 +160,65 @@ output (#E;Error error) - (assert error false))) + (test error false))) -(syntax: #export (test: description [body test^]) +(syntax: #export (context: description [body test^]) {#;doc (doc "Macro for definint tests." - (test: "Simple macros and constructs" + (context: "Simple macros and constructs" ($_ seq - (assert "Can write easy loops for iterative programming." - (i.= 1000 - (loop [counter 0 - value 1] - (if (i.< 3 counter) - (recur (i.inc counter) (i.* 10 value)) - value)))) - - (assert "Can create lists easily through macros." - (and (case (list 1 2 3) - (#;Cons 1 (#;Cons 2 (#;Cons 3 #;Nil))) - true - - _ - false) - - (case (list& 1 2 3 (list 4 5 6)) - (#;Cons 1 (#;Cons 2 (#;Cons 3 (#;Cons 4 (#;Cons 5 (#;Cons 6 #;Nil)))))) - true - - _ - false))) - - (assert "Can have defaults for Maybe values." - (and (is "yolo" (default "yolo" - #;None)) - - (is "lol" (default "yolo" - (#;Some "lol"))))) + (test "Can write easy loops for iterative programming." + (i.= 1000 + (loop [counter 0 + value 1] + (if (i.< 3 counter) + (recur (i.inc counter) (i.* 10 value)) + value)))) + + (test "Can create lists easily through macros." + (and (case (list 1 2 3) + (#;Cons 1 (#;Cons 2 (#;Cons 3 #;Nil))) + true + + _ + false) + + (case (list& 1 2 3 (list 4 5 6)) + (#;Cons 1 (#;Cons 2 (#;Cons 3 (#;Cons 4 (#;Cons 5 (#;Cons 6 #;Nil)))))) + true + + _ + false))) + + (test "Can have defaults for Maybe values." + (and (is "yolo" (default "yolo" + #;None)) + + (is "lol" (default "yolo" + (#;Some "lol"))))) )) "Also works with random generation of values for property-based testing." - (test: "Addition & Substraction" + (context: "Addition & Substraction" [x (:: @ map <prep> rand-gen) y (:: @ map <prep> rand-gen)] - (assert "" - (and (|> x (- y) (+ y) (= x)) - (|> x (+ y) (- y) (= x))))) + (test "" + (and (|> x (- y) (+ y) (= x)) + (|> x (+ y) (- y) (= x))))) "By default, random tests will be tried 100 times, you can specify the amount you want:" - (test: "Addition & Substraction" + (context: "Addition & Substraction" #times +1234 [x (:: @ map <prep> rand-gen) y (:: @ map <prep> rand-gen)] - (assert "" - (and (|> x (- y) (+ y) (= x)) - (|> x (+ y) (- y) (= x))))) + (test "" + (and (|> x (- y) (+ y) (= x)) + (|> x (+ y) (- y) (= x))))) "If a test fails, you'll be shown a seed that you can then use to reproduce a failing scenario." - (test: "Addition & Substraction" + (context: "Addition & Substraction" #seed +987654321 [x (:: @ map <prep> rand-gen) y (:: @ map <prep> rand-gen)] - (assert "" - (and (|> x (- y) (+ y) (= x)) - (|> x (+ y) (- y) (= x))))) + (test "" + (and (|> x (- y) (+ y) (= x)) + (|> x (+ y) (- y) (= x))))) )} (let [body (case body (#Property config bindings body) |