diff --git a/Makefile b/Makefile index 1ceeadb..d694e97 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,7 @@ URN ?= ${LUA} bin/urn.lua LIBS := $(shell find lib -type f -name "*.lisp") MAIN_TESTS := $(shell find tests -type f -name '*.lisp' ! -name '*-helpers.lisp') -DOC_TESTS := base \ - function \ - list \ - string \ - type \ +DOC_TESTS := $(filter-out test_prelude,$(LIBS:lib/%.lisp=test_%)) ifeq (${TIME},1) LUA_FLAGS += --time @@ -23,7 +19,7 @@ ifeq (${QUIET},1) TEST_FLAGS += --quiet endif -.PHONY: ${MAIN_TESTS} ${DOC_TESTS} all test compiler_test docs +.PHONY: ${MAIN_TESTS} ${DOC_TESTS} all test compiler_test docs tasks all: ${OUT_DIR}/urn compiler_test: all test @@ -44,7 +40,7 @@ ${MAIN_TESTS}: ${DOC_TESTS}: $(eval TMP := $(shell mktemp -d)) - ${URN} plugins/doc-test --run -o ${TMP} -- ${TEST_FLAGS} $@ + ${URN} plugins/doc-test --run -o ${TMP} -- ${TEST_FLAGS} $(@:test_%=%) @rm -rf ${TMP}.lisp ${TMP}.lua ${TMP} docs: @@ -61,3 +57,6 @@ publish_docs: docs git commit -m "Update docs" git push origin gh-pages git checkout master + +tasks: + @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' \ No newline at end of file diff --git a/lib/binders.lisp b/lib/binders.lisp index f7f2029..7c33ae4 100644 --- a/lib/binders.lisp +++ b/lib/binders.lisp @@ -34,9 +34,10 @@ ### Example ```cl - (let* [(foo 1) - (bar (+ foo 1))] - foo + > (let* [(foo 1) + . (bar (+ foo 1))] + . bar) + out = 2 ```" (base/with (len (n vars)) (cond @@ -58,9 +59,10 @@ ### Example ```cl - (let [(foo 1) - (bar 2)] - (+ foo bar)) + > (let [(foo 1) + . (bar 2)] + . (+ foo bar)) + out = 3 ```" `((lambda ,(cars vars) ,@body) @@ -71,15 +73,17 @@ evaluating BODY. ```cl - (when-let [(foo 1) - (bar nil)] - foo) + > (when-let [(foo 1) + . (bar nil)] + . foo) + out = nil ``` Does not evaluate `foo`, while ``` - (when-let [(foo 1) - (bar 2)] - (+ foo bar)) + > (when-let [(foo 1) + . (bar 2)] + . (+ foo bar)) + out = 3 ``` does." `((lambda ,(cars vars) @@ -94,10 +98,11 @@ ### Example ```cl - (when-let* [(foo 1) - (bar nil) - (baz 2) - (+ foo baz)) + > (when-let* [(foo 1) + . (bar nil) + . (baz 2)] + . (+ foo baz)) + out = nil ``` Since `1` is truthy, it is evaluated and bound to `foo`, however, @@ -116,8 +121,8 @@ ### Example ```cl - (when-with (foo (get-idx bar :baz)) - (print! foo)) + > (when-with (foo (.> bar :baz)) + . (print! foo)) ``` When `bar` has an index `baz`, it will be bound to `foo` and @@ -138,13 +143,13 @@ ### Example ``` > (letrec [(is-even? (lambda (n) - (or (= 0 n) - (is-odd? (pred n))))) - (is-odd? (lambda (n) - (and (! (= 0 n)) - (is-even? (pred n)))))] - (is-odd? 11)) - true + . (or (= 0 n) + . (is-odd? (pred n))))) + . (is-odd? (lambda (n) + . (and (! (= 0 n)) + . (is-even? (pred n)))))] + . (is-odd? 11)) + out = true ```" `((lambda ,(cars vars) ,@(map make-setting vars) @@ -154,7 +159,7 @@ `((or (and (getmetatable ,x) (get-idx (getmetatable ,x) :--finalise)) (get-idx ,x :close) - (lambda ())))) + (lambda ())), x)) (defmacro use (var &body) "Bind each variable in VAR, checking for truthyness between bindings, @@ -170,9 +175,10 @@ ### Example: ``` - > (use [(file (io/open \"temp\"))] \\ + > (use [(file (io/open \"tests/data/hello.txt\"))] . (print! (self file :read \"*a\"))) - *contents of temp* + \"Hello, world!\" + out = nil ```" `(when-let* ,var ,@body @@ -182,12 +188,12 @@ (defmacro loop (vs test &body) "A general iteration helper. - ```cl - (loop [(var0 val0) - (var1 val1) - ...] - [test test-body ...] - body ...) + ```cl :no-test + > (loop [(var0 val0) + . (var1 val1) + . ...] + . [test test-body ...] + . body ...) ``` Bind all the variables given in VS. Each iteration begins by @@ -203,7 +209,7 @@ ```cl > (loop [(o '()) - (l '(1 2 3))] + . (l '(1 2 3))] . [(empty? l) o] . (recur (cons (car l) o) (cdr l))) out = (3 2 1) diff --git a/lib/extra/benchmark.lisp b/lib/extra/benchmark.lisp index 6b2e929..dc69505 100644 --- a/lib/extra/benchmark.lisp +++ b/lib/extra/benchmark.lisp @@ -7,7 +7,7 @@ Note that documentation strings and other attributes are not preserved, and that the definition must be of the form - ``` + ```cl :no-test (defun foo (bar) ...) ``` " (destructuring-bind [(defun ?name ?args . ?body) body] @@ -26,7 +26,7 @@ Note that documentation strings and other attributes are not preserved, and that the definition must be of the form - ``` + ```cl :no-test (defun foo (bar) ...) ``` " (destructuring-bind [(defun ?name ?args . ?body) body] diff --git a/lib/extra/check.lisp b/lib/extra/check.lisp index 4693d62..b8bf58c 100644 --- a/lib/extra/check.lisp +++ b/lib/extra/check.lisp @@ -57,11 +57,11 @@ ### Example: ``` - > (check [(number a)] \\ + > (check [(number a)] . (= a a)) (= a a) passed 100 tests. nil - > (check [(number a)] \\ + > (check [(number a)] . (= a (+ 1 a))) (= a (+ 1 a)) falsified after 1 iteration(s) falsifying set of values: @@ -127,8 +127,9 @@ Example: ```cl - (check [(number a)] - (tripping tonumber tostring)) + > (check [(number a)] + . (tripping tonumber tostring a)) + out = true ```" (let* [(y (gensym))] `(let* [(,y ,x)] @@ -139,8 +140,9 @@ Example: ```cl - (check [(number a)] - (=:= id (compose id id) a)) + > (check [(number a)] + . (=:= id (compose id id) a)) + out = true ```" (let* [(y (gensym))] `(let* [(,y ,x)] @@ -156,7 +158,8 @@ name. Example: ```cl - (forall a (eq? a (id a))) + > (forall a (eq? a (id a))) + out = true ```" (let* [(v (if (list? var) var diff --git a/lib/extra/io.lisp b/lib/extra/io.lisp index d78b1a7..d34c074 100644 --- a/lib/extra/io.lisp +++ b/lib/extra/io.lisp @@ -12,9 +12,9 @@ Returns nil if it failed. ### Example - ``` - > (read-all! \"hello.txt\") - \"Hello, world!\" + ```cl + > (read-all! \"tests/data/hello.txt\") + out = \"Hello, world!\" ```" (read-all-mode! path false)) @@ -23,21 +23,21 @@ Returns nil if it failed. ### Example - ``` - > (read-lines! \"lines.txt\") - (\"This is the first line.\" \"This is the second.\") + ```cl + > (read-lines! \"tests/data/lines.txt\") + out = (\"This is the first line.\" \"This is the second.\") ```" (when-with (data (read-all! path)) - (split data "\n"))) + (string/split data "\n"))) (defun read-bytes! (path) "Reads the data from the file at PATH and returns it as a list of bytes (numbers). Returns nil if it failed. ### Example - ``` - > (read-bytes! \"abc.txt\") - (97 98 99) + ```cl + > (read-bytes! \"tests/data/abc.txt\") + out = (97 98 99) ```" (when-with (data (read-all-mode! path true)) (letrec [(string->bytes (str idx) @@ -64,9 +64,9 @@ does. Returns true if it succeeded or false if it failed. ### Example - ``` - > (write-all! \"hello.txt\" \"Hello, world!\") - true + ```cl + > (write-all! \"tests/data/hello_.txt\" \"Hello, world!\") + out = true ```" (write-all-mode! path false false data)) @@ -77,9 +77,9 @@ does. Returns true if it succeeded or false if it failed. ### Example - ``` - > (write-lines! \"lines.txt\" `(\"This is the first line.\" \"This is the second.\")) - true + ```cl + > (write-lines! \"tests/data/lines_.txt\" `(\"This is the first line.\" \"This is the second.\")) + out = true ```" (write-all! path (concat data "\n"))) @@ -90,9 +90,9 @@ does. Returns true if it succeeded or false if it failed. ### Example - ``` - > (write-bytes! \"abc.txt\" `(97 98 99)) - true + ```cl + > (write-bytes! \"tests/data/abc_.txt\" `(97 98 99)) + out = true ```" (letrec [(bytes->string (bytes idx) (if (> idx (n bytes)) @@ -107,9 +107,9 @@ Returns true if it succeeded or false if it failed. ### Example - ``` - > (append-all! \"hello.txt\" \" Some appended text.\") - true + ```cl + > (append-all! \"tests/data/hello_.txt\" \" Some appended text.\") + out = true ```" (write-all-mode! path true false data)) @@ -120,9 +120,9 @@ or false if it failed. ### Example - ``` - > (append-lines! \"lines.txt\" `(\" Here's another line:\" \"Another line.\")) - true + ```cl + > (append-lines! \"tests/data/lines_.txt\" `(\" Here's another line:\" \"Another line.\")) + out = true ```" (append-all! path (concat data "\n"))) @@ -133,9 +133,9 @@ or false if it failed. ### Example - ``` - > (append-bytes! \"abc.txt\" `(100 101 102)) - true + ```cl + > (append-bytes! \"tests/data/abc_.txt\" `(100 101 102)) + out = true ```" (letrec [(bytes->string (bytes idx) (if (> idx (n bytes)) diff --git a/lib/extra/test.lisp b/lib/extra/test.lisp index 9cbb5dc..a00769c 100644 --- a/lib/extra/test.lisp +++ b/lib/extra/test.lisp @@ -78,7 +78,7 @@ (,time (any (lambda (,'x) (or (= ,'x "--time") (= ,'x "-t"))) arg))] ,@body - (when (and ,quiet (> ,tests-total 0)) + (when (and ,quiet (or (> ,tests-total 0) (> (n ,tests-pending) 0))) ;; If we've been outputting dots then add a new line (print!)) diff --git a/lib/lens.lisp b/lib/lens.lisp index 047f9ff..2f342ae 100644 --- a/lib/lens.lisp +++ b/lib/lens.lisp @@ -49,16 +49,16 @@ > (over head succ list-example) out = '(2 2 3 4 5 6 7 8 9 10) ``` - + Notice that [[over]] doesn't just return the new head, but the a copy of the existing list with the new head in place. - + Again, lenses don't seem very useful until you learn the other property that they all have in common: _composition_. Lenses, you see, are like functions: You can take two and [[<>]] them together, producing a lens that [[view]]s and modifies (with [[over]]) a inner piece of the data structure. - + For example, by composing `head` and `tail`, you may focus on the second element of a list using `(<> head tail)`, or the tail of the first element of a list (given that element itself is a list itself) using @@ -293,7 +293,7 @@ Example: ```cl - > (view (traverse (at 3)) '((1 2 3) (4 5 6))) + > (view (traversing (at 3)) '((1 2 3) (4 5 6))) out = (3 6) ```" (lens (lambda (x) diff --git a/lib/match.lisp b/lib/match.lisp index f4ecc8e..bfbae9a 100644 --- a/lib/match.lisp +++ b/lib/match.lisp @@ -414,10 +414,12 @@ ### Example: ```cl - > (handler-case \\ + > (handler-case . (error! \"oh no!\") . [string? (x) . (print! x)]) + \"oh no!\" + out = nil ```" (let* [(gen-arm (cs exc) (destructuring-bind [(?pattern (?arg) . ?body) cs] diff --git a/lib/table.lisp b/lib/table.lisp index f9c0a6e..527966e 100644 --- a/lib/table.lisp +++ b/lib/table.lisp @@ -101,16 +101,17 @@ contrast to variations of [[let]], the pairs are given \"unpacked\": Instead of invoking - ```cl + ```cl :no-test (struct [(:foo bar)]) ``` or - ```cl + ```cl :no-test (struct {:foo bar}) ``` you must instead invoke it like ```cl - (struct :foo bar) + > (struct :foo \"bar\") + out = {\"foo\" \"bar\"} ```" (when (= (% (n entries) 2) 1) (error "Expected an even number of arguments to struct" 2)) diff --git a/lib/urn/set.lisp b/lib/urn/set.lisp index 5338545..298251b 100644 --- a/lib/urn/set.lisp +++ b/lib/urn/set.lisp @@ -90,9 +90,10 @@ (assert-type! set set) (let* [(hash (.> set :hash)) (out (make-set hash))] - (map (lambda (v) - (. set :data) + (. (union (set-of 1 2 3) (set-of 4 5 6)) - out = «hash-set 1 2 3 4 5 6» + out = «hash-set: 1 2 3 4 5 6» ```" (assert-type! a set) (assert-type! b set) diff --git a/tests/data/.gitignore b/tests/data/.gitignore new file mode 100644 index 0000000..35706c1 --- /dev/null +++ b/tests/data/.gitignore @@ -0,0 +1 @@ +*_.txt diff --git a/tests/data/abc.txt b/tests/data/abc.txt new file mode 100644 index 0000000..f2ba8f8 --- /dev/null +++ b/tests/data/abc.txt @@ -0,0 +1 @@ +abc \ No newline at end of file diff --git a/tests/data/hello.txt b/tests/data/hello.txt new file mode 100644 index 0000000..5dd01c1 --- /dev/null +++ b/tests/data/hello.txt @@ -0,0 +1 @@ +Hello, world! \ No newline at end of file diff --git a/tests/data/lines.txt b/tests/data/lines.txt new file mode 100644 index 0000000..58cf6c3 --- /dev/null +++ b/tests/data/lines.txt @@ -0,0 +1,2 @@ +This is the first line. +This is the second. \ No newline at end of file