(import srfi-105 chicken.port chicken.string test) (test-begin "srfi-105") (define (test-example str #!optional fail) (let* ((parts (string-split str "⇏⇒")) (curly (with-input-from-string (car parts) read)) (expansion (with-input-from-string (cadr parts) read))) (if fail (test-assert str (not (equal? expansion curly))) (test str expansion curly)))) (test-group "srfi-105 document examples" (test-example "{n <= 5} ⇒ (<= n 5)") (test-example "{x + 1} ⇒ (+ x 1)") (test-example "{a + b + c} ⇒ (+ a b c)") (test-example "{x ,op y ,op z} ⇒ (,op x y z)") (test-example "{x eqv? `a} ⇒ (eqv? x `a)") (test-example "{'a eq? b} ⇒ (eq? 'a b)") (test-example "{n-1 + n-2} ⇒ (+ n-1 n-2)") (test-example "{a * {b + c}} ⇒ (* a (+ b c))") (test-example "{a + {b - c}} ⇒ (+ a (- b c))") (test-example "{{a + b} - c} ⇒ (- (+ a b) c)") (test-example "{{a > 0} and {b >= 1}} ⇒ (and (> a 0) (>= b 1))") (test-example "{} ⇒ ()") (test-example "{5} ⇒ 5") (test-example "{- x} ⇒ (- x)") (test-example "{length(x) >= 6} ⇒ (>= (length x) 6)") (test-example "{f(x) + g(y) + h(z)} ⇒ (+ (f x) (g y) (h z))") (test-example "{(f a b) + (g h)} ⇒ (+ (f a b) (g h))") (test-example "{f(a b) + g(h)} ⇒ (+ (f a b) (g h))") (test-example "'{a + f(b) + x} ⇒ '(+ a (f b) x)") (test-example "{(- a) / b} ⇒ (/ (- a) b)") (test-example "{-(a) / b} ⇒ (/ (- a) b)") (test-example "{cos(q)} ⇒ (cos q)") (test-example "{e{}} ⇒ (e)") (test-example "{pi()} ⇒ (pi)") (test-example "{'f(x)} ⇒ '(f x)") ;; (test-example "{#1=f(#1#)} ⇒ #1=(f #1#)") (test-group "Deviations from specification (expansions fail)" (test-example "{ (f (g h(x))) } ⇏ (f (g (h x)))" 'fail) (test-example "{#(1 2 f(a) 4)} ⇏ #(1 2 (f a) 4)" 'fail) (test-example "{(f #;g(x) h(x))} ⇏ (f (h x))" 'fail)) (test-group "Workarounds to deviations from specification" (test-example "{ (f (g {h(x)})) } ⇒ (f (g (h x)))") (test-example "{#(1 2 {f(a)} 4)} ⇒ #(1 2 (f a) 4)") (test-assert "NO WORKAROUND: {(f #;g(x) h(x))} ⇏ (f (h x))" #t)) (test-group "Unsupported syntax (expansions error)" (test-assert "UNSUPPORTED: {#1=f(#1#)} ⇏ #1=(f #1#)" #t) (test-assert "UNSUPPORTED: {a . z} ⇏ ($nfx$ a . z)" #t) (test-assert "UNSUPPORTED: {read(. options)} ⇏ (read . options)" #t)) (test-example "{(map - ns)} ⇒ (map - ns)") (test-example "{map(- ns)} ⇒ (map - ns)") (test-example "{n * factorial{n - 1}} ⇒ (* n (factorial (- n 1)))") (test-example "{2 * sin{- x}} ⇒ (* 2 (sin (- x)))") (test-example "{3 + 4 +} ⇒ ($nfx$ 3 + 4 +)") (test-example "{3 + 4 + 5 +} ⇒ ($nfx$ 3 + 4 + 5 +)") (test-example "{a + b - c} ⇒ ($nfx$ a + b - c)") (test-example "{a(x)(y)} ⇒ ((a x) y)") (test-example "{x[a]} ⇒ ($bracket-apply$ x a)") (test-example "{y[a b]} ⇒ ($bracket-apply$ y a b)") (test-example "{f{n - 1}(x)} ⇒ ((f (- n 1)) x)") (test-example "{f{n - 1}{y - 1}} ⇒ ((f (- n 1)) (- y 1))") (test-example "{f{- x}[y]} ⇒ ($bracket-apply$ (f (- x)) y)")) (test-end "srfi-105") (test-exit)