From b7d79720c5e474a4999b5b08ec72c62a46b47cef Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 19 Jun 2017 20:52:54 -0400 Subject: - In lux/test, renamed "test:" to "context:", and "assert" to "test". --- stdlib/source/lux/test.lux | 90 +++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 45 deletions(-) (limited to 'stdlib/source') 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 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 rand-gen) y (:: @ map 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 rand-gen) y (:: @ map 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 rand-gen) y (:: @ map 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) -- cgit v1.2.3