Skip to content

Commit

Permalink
add failing tests #291
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 26, 2024
1 parent c65c0c3 commit f226735
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.18.1-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
![1.0.0 Complete](https://img.shields.io/github/milestones/progress-percent/jcubic/lips/1?label=1.0.0%20Complete)
[![Build and test](https://github.com/jcubic/lips/actions/workflows/build.yaml/badge.svg?branch=devel&event=push)](https://github.com/jcubic/lips/actions/workflows/build.yaml)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&e1ff7e2064314cd6b09e6d807fec2752)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&43f0209f785ba081ef8f8184bcc86f51)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips)
![NPM Download Count](https://img.shields.io/npm/dm/@jcubic/lips)
![JSDelivr Download count](https://img.shields.io/jsdelivr/npm/hm/@jcubic/lips)
Expand Down
1 change: 1 addition & 0 deletions src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -3668,6 +3668,7 @@ function extract_patterns(pattern, code, symbols, ellipsis_symbol, scope = {}) {
return traverse(pattern.cdr.cdr, code.cdr);
}
}
// code as improper list
const last_pair = code.last_pair();
if (last_pair.cdr !== nil) {
if (pattern.cdr.cdr === nil) {
Expand Down
51 changes: 51 additions & 0 deletions tests/syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1318,3 +1318,54 @@

(t.is (foo ((lis transducer . transducers) (display x)))
'(apply (lambda (lis transducer . transducers) (display x)) args))))

(test "syntax: multiple values after ellipsis"
(lambda (t)
(define-syntax foo
(syntax-rules ()
((_ (a ... b c) d ...)
(list a ... b c d ...))))

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

;; ref: https://stackoverflow.com/q/37644555/387194
(test "syntax: identifer with variable"

Check failure on line 1333 in tests/syntax.scm

View workflow job for this annotation

GitHub Actions / Check for spelling errors

identifer ==> identifier
(lambda (t)
(define-syntax hello
(syntax-rules (in)
((_ name in world) (format "Hello ~a in ~a" name world))
((_ in name) (format "Hello ~a in here" name))))

(define in "inside")
(t.is (hello "me" in in)
"Hello me in inside")))

;; ref: https://practical-scheme.net/gauche/man/gauche-refe/Hygienic-macros.html#Syntax_002drules-macro-transformer
(test.failing "syntax: let shadow identifer (1)"

Check failure on line 1345 in tests/syntax.scm

View workflow job for this annotation

GitHub Actions / Check for spelling errors

identifer ==> identifier
(lambda (t)
(define-syntax if+
(syntax-rules (then else)
((_ test then expr1 else expr2) (if test expr1 expr2))))

(define else #f)
(t.is (if+ (even? x) then (/ x 2) else (/ (+ x 1) 2))
5)

(t.is (to.throw (let ((else #f) (x 10))
(if+ (even? x) then (/ x 2) else (/ (+ x 1) 2))))
#t)))

(test.failing "syntax: let shadow identifer (2)"

Check failure on line 1359 in tests/syntax.scm

View workflow job for this annotation

GitHub Actions / Check for spelling errors

identifer ==> identifier
(lambda (t)
(define else #f)
(define-syntax if+
(syntax-rules (then else)
((_ test then expr1 else expr2) (if test expr1 expr2))))

(t.is (if+ (even? x) then (/ x 2) else (/ (+ x 1) 2))
5)

(t.is (to.throw (let ((else #f) (x 10))
(if+ (even? x) then (/ x 2) else (/ (+ x 1) 2))))
#t)))

0 comments on commit f226735

Please sign in to comment.