Skip to content

Commit

Permalink
more unit tests for syntax-rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 25, 2024
1 parent a6f12d8 commit c65c0c3
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,24 @@

(t.is result '(1 2 3 4 5 6))))

(test "syntax: tripple elispsis (Gauche example)"

Check failure on line 442 in tests/syntax.scm

View workflow job for this annotation

GitHub Actions / Check for spelling errors

tripple ==> triple
(lambda (t)
(define-syntax my-append
(syntax-rules ()
[(_ ((a ...) ...) ...)
'(a ... ... ...)]))

(t.is (my-append ((1 2) (3 4)) ((5) (6 7 8))) '(1 2 3 4 5 6 7 8))))

(test "syntax: my-let"
(lambda (t)
(define-syntax my-let
(syntax-rules ()
[(_ ((var init) ...) body ...)
((lambda (var ...) body ...) init ...)]))

(t.is (my-let ((x 10) (y 20)) (+ x y)) 30)))

(test.failing "syntax: lifted ellipsis (SRFI-149)"
(lambda (t)
(define result
Expand Down Expand Up @@ -942,6 +960,32 @@
(+ a b c))
6)))


;; ref: https://stackoverflow.com/a/64659565/387194
(test "syntax: alist"
(lambda (t)
(define-syntax alist
(syntax-rules ()
((_) ())
((_ a b) (list (cons a b)))
((_ x y z ...)
(cons (cons x y) (alist z ...)))))

(t.is (alist "foo" 1 "bar" 2 "baz" 3)
'(("foo" . 1) ("bar" . 2) ("baz" . 3)))))

(test "syntax: alist + rest"
(lambda (t)
(define-syntax alist
(syntax-rules ()
((_) ())
((_ a b) (list (cons a b)))
((_ x y . rest)
(cons (cons x y) (alist . rest)))))

(t.is (alist "foo" 1 "bar" 2 "baz" 3)
'(("foo" . 1) ("bar" . 2) ("baz" . 3)))))

(test.failing "syntax: nested _"
(lambda (t)
(define-syntax foo
Expand Down

0 comments on commit c65c0c3

Please sign in to comment.