Skip to content

Commit

Permalink
two unit tests for syntax-rules #43
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Feb 4, 2024
1 parent bc7af27 commit c99013e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1530,3 +1530,31 @@

(t.is (undswap 3 (if _ (+ 3 _ )))
6)))

(test "syntax: alist into code"
(lambda (t)
(define-syntax alist
(syntax-rules ()
((_)
'())
((_ key value . rest)
(cons (cons key value) (alist . rest)))))

(t.is (alist 'foo 10 'bar 20 'baz 30)
'((foo . 10) (bar . 20) (baz . 30)))))

(test "syntax: alist literal"
(lambda (t)
;; ref: https://stackoverflow.com/a/64672095/387194
(define-syntax alist
(syntax-rules (alist-builder)
((_ alist-builder () (results ...))
'(results ...))
((_ alist-builder (a) . rest)
(raise 'bad-alist))
((_ alist-builder (a b rest ...) (results ...))
(alist alist-builder (rest ...) (results ... (a . b))))
((_ a ...) (alist alist-builder (a ...) ()))))

(t.is (alist 'foo 10 'bar 20 'baz 30)
'((foo . 10) (bar . 20) (baz . 30)))))

0 comments on commit c99013e

Please sign in to comment.