From f22673531794e612a27096ed5b1830074da73fcc Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Fri, 26 Jan 2024 12:06:53 +0100 Subject: [PATCH] add failing tests #291 --- README.md | 2 +- src/lips.js | 1 + tests/syntax.scm | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c07579d9..4d9fbc43 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/src/lips.js b/src/lips.js index 16f40af4..a1cd8b24 100644 --- a/src/lips.js +++ b/src/lips.js @@ -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) { diff --git a/tests/syntax.scm b/tests/syntax.scm index 8fae5640..5dbde695 100644 --- a/tests/syntax.scm +++ b/tests/syntax.scm @@ -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" + (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)" + (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)" + (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)))