diff options
| author | Andrey Orst <andreyorst@gmail.com> | 2020-11-05 21:37:47 +0300 |
|---|---|---|
| committer | Andrey Orst <andreyorst@gmail.com> | 2020-11-05 21:39:16 +0300 |
| commit | 6b65999a1f565651fc48a076a7473b6e93f6357a (patch) | |
| tree | d143581a580b06263522d105e0e01dfb0e4b9b9c | |
| parent | 11617c42a4fb249c4f7199ca5eba3b93518ded0a (diff) | |
feature(testing): move tests to separate directory. Also add some tests
| -rw-r--r-- | Makefile | 9 | ||||
| -rw-r--r-- | test/core.fnl (renamed from core_test.fnl) | 2 | ||||
| -rw-r--r-- | test/fn.fnl | 49 | ||||
| -rw-r--r-- | test/macros.fnl (renamed from macros_test.fnl) | 34 | ||||
| -rw-r--r-- | test/test.fnl (renamed from test.fnl) | 24 |
5 files changed, 97 insertions, 21 deletions
@@ -19,18 +19,15 @@ clean-all: clean rm -f luacov* test: clean - @fennel --lua $(LUA) core_test.fnl - @fennel --lua $(LUA) macros_test.fnl + @fennel --lua $(LUA) test/fn.fnl + @fennel --lua $(LUA) test/core.fnl + @fennel --lua $(LUA) test/macros.fnl luacov: | clean-all all luacov-stats luacov luacov-console: | luacov - @mv core_test.lua core_test.lua.tmp - @mv macros_test.lua macros_test.lua.tmp luacov-console . - @mv core_test.lua.tmp core_test.lua - @mv macros_test.lua.tmp macros_test.lua luacov-stats: core_test.lua macros_test.lua @$(LUA) -lluarocks.loader -lluacov $< diff --git a/core_test.fnl b/test/core.fnl index 7922e34..ed34e02 100644 --- a/core_test.fnl +++ b/test/core.fnl @@ -1,6 +1,6 @@ (import-macros {: fn*} :macros.fn) (import-macros {: into : defmethod : defmulti} :macros.core) -(import-macros {: assert-eq : assert-ne : assert* : testing : deftest} :test) +(import-macros {: assert-eq : assert-ne : assert* : testing : deftest} :test.test) (local {: apply diff --git a/test/fn.fnl b/test/fn.fnl new file mode 100644 index 0000000..b9876ca --- /dev/null +++ b/test/fn.fnl @@ -0,0 +1,49 @@ +(import-macros {: assert-eq : assert-ne : assert* : testing : deftest} :test.test) +(import-macros {: meta} :macros.core) +(local {: eq} (require :core)) ;; required for testing + +(import-macros {: fn* : fn&} :macros.fn) + +(deftest fn* + (testing fn*-meta + (fn* f + "docstring" + [x] x) + (assert-eq (meta f) {:fnl/docstring "docstring" + :fnl/arglist ["x"]}) + + (fn* f + "docstring" + ([x] x)) + (assert-eq (meta f) {:fnl/docstring "docstring" + :fnl/arglist ["x"]}) + + (fn* f + "docstring" + ([x] x) + ([x y] (+ x y))) + (assert-eq (meta f) {:fnl/docstring "docstring" + :fnl/arglist ["\n [x]" + "\n [x y]"]}) + + (fn* f + "docstring" + ([x] x) + ([x y] (+ x y)) + ([x y & z] (+ x y))) + (assert-eq (meta f) {:fnl/docstring "docstring" + :fnl/arglist ["\n [x]" + "\n [x y]" + "\n [x y & z]"]}))) + +(deftest fn& + (testing fn&-meta + (fn& f "docstring" [x] x) + (assert-eq (meta f) {:fnl/docstring "docstring" + ;; :fnl/arglist ["x"] ;; TODO: why this works only in REPL? + }) + + (fn& f "docstring" [...] [...]) + (assert-eq (meta f) {:fnl/docstring "docstring" + ;; :fnl/arglist ["..."] ;; TODO: same as above + }))) diff --git a/macros_test.fnl b/test/macros.fnl index 3ed5ad1..6341433 100644 --- a/macros_test.fnl +++ b/test/macros.fnl @@ -1,7 +1,19 @@ -(import-macros {: if-let : when-let : if-some : when-some : into : defmethod : defmulti : defonce : def} :macros.core) -(import-macros {: assert-eq : assert-ne : assert* : testing : deftest} :test) +(import-macros {: assert-eq : assert-ne : assert* : testing : deftest} :test.test) (local {: eq : identity} (require :core)) ;; required for testing +(import-macros + {: if-let + : when-let + : if-some + : when-some + : into + : defmethod + : defmulti + : defonce + : def + : meta + : with-meta} :macros.core) + (deftest into (testing into (assert-eq (into [] []) []) @@ -116,3 +128,21 @@ (defonce b.a 10) (assert-eq b.a 10) (assert-eq a 10))) + +(deftest meta + (testing with-meta + (assert-eq (meta (with-meta :a {:k :v})) {:k :v})) + + (testing def-meta + (def {:doc "x"} x 10) + (assert-eq (meta x) {:fnl/docstring "x"}) + (def {:doc "x" :dynamic true} x 10) + (assert-eq (meta x) {:fnl/docstring "x"})) + + (testing defonce-meta + (defonce {:doc "x"} x 10) + (assert-eq (meta x) {:fnl/docstring "x"}) + (defonce {:doc "y"} x 20) + (assert-eq (meta x) {:fnl/docstring "x"}) + (defonce {:doc "y" :dynamic true} y 20) + (assert-eq (meta y) {:fnl/docstring "y"}))) @@ -5,23 +5,23 @@ ([expr1 expr2] (assert-eq expr1 expr2 nil)) ([expr1 expr2 msg] - `(let [left# ,expr1 - right# ,expr2 - view# (require :fennelview)] - (assert (eq left# right#) (or ,msg (.. "equality assertion failed - Left: " (view# left#) " - Right: " (view# right#) "\n")))))) + `(let [left# ,expr1 + right# ,expr2 + (res# view#) (pcall require :fennelview)] + (assert (eq left# right#) (or ,msg (.. "equality assertion failed + Left: " ((if res# view# tostring) left#) " + Right: " ((if res# view# tostring) right#) "\n")))))) (fn* assert-ne ([expr1 expr2] (assert-ne expr1 expr2 nil)) ([expr1 expr2 msg] - `(let [left# ,expr1 - right# ,expr2 - view# (require :fennelview)] - (assert (not (eq left# right#)) (or ,msg (.. "unequality assertion failed - Left: " (view# left#) " - Right: " (view# right#) "\n")))))) + `(let [left# ,expr1 + right# ,expr2 + (res# view#) (pcall require :fennelview)] + (assert (not (eq left# right#)) (or ,msg (.. "unequality assertion failed + Left: " ((if res# view# tostring) left#) " + Right: " ((if res# view# tostring) right#) "\n")))))) (fn* assert* ([expr] |