diff options
| author | 2025-04-25 13:08:20 -0400 | |
|---|---|---|
| committer | 2025-04-25 13:08:20 -0400 | |
| commit | 88c84c4decd258f9b199d58a6b5f93a034dee0bf (patch) | |
| tree | 159a95a65456de5a5d31327fdd37f8aa7a57e597 /test/patterns.scm | |
| parent | fix pattern list creation (diff) | |
rewrite expander
Expander now uses dynamically scoped variables. The old lexical scope
variable implementation was getting to four nested lambdas, which was
unreadable.
The dynamic variables are clearly labeled and segregated from the rest
of the code. The actual compiler interacts with the dynamic variables
through an API.
The previous compiler did not handle empty ellipses match properly.
This has some more work to fix that.
Diffstat (limited to 'test/patterns.scm')
| -rw-r--r-- | test/patterns.scm | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/test/patterns.scm b/test/patterns.scm index 0e9df36..754b818 100644 --- a/test/patterns.scm +++ b/test/patterns.scm @@ -18,10 +18,13 @@ (define empty-set (set bound-identifier-comparator)) (define (test-single-match) - (define matcher + (define-values (matcher names) (compile-pattern ellipsis empty-set (empty-wrap 'x))) + (test-equal "nesting level of identifier" + 0 + (hashmap-ref names (empty-wrap 'x))) (let ((returned (matcher empty-map (empty-wrap 'y)))) (test-assert "identifier" (bound-identifier=? (hashmap-ref returned @@ -36,10 +39,13 @@ (empty-wrap 'y))))) (define (test-match-in-list) - (define matcher + (define-values (matcher names) (compile-pattern ellipsis empty-set (list (empty-wrap 'x)))) + (test-equal "nesting level of identifier" + 0 + (hashmap-ref names (empty-wrap 'x))) (let ((returned (matcher empty-map (empty-wrap 'y)))) (test-assert "does not match identifier" (not returned))) @@ -49,28 +55,35 @@ (empty-wrap 'y))))) (define (test-multiple-matches-in-list) - (define matcher + (define-values (matcher names) (compile-pattern ellipsis empty-set (list (empty-wrap 'x) (empty-wrap 'y)))) + (test-equal "nesting level of x" + 0 + (hashmap-ref names (empty-wrap 'x))) + (test-equal "nesting level of y" + 0 + (hashmap-ref names (empty-wrap 'y))) (let ((returned (matcher empty-map (list 1 2)))) (test-equal "first" 1 (hashmap-ref returned (empty-wrap 'x))) (test-equal "second" 2 (hashmap-ref returned (empty-wrap 'y))))) (define (test-simple-ellipsis) - (define matcher + (define-values (matcher names) (compile-pattern ellipsis empty-set (list (empty-wrap 'x) ellipsis))) + (test-equal "nesting level of x" + 1 + (hashmap-ref names (empty-wrap 'x))) (let* ((list '(1 2 3 4 5 6 7 8)) (returned (matcher empty-map list)) (x-value (hashmap-ref returned (empty-wrap 'x)))) - (test-assert "returned is matched-ellipsis" - (matched-ellipsis? x-value)) (test-equal "(x ...)" (reverse list) - (matched-ellipsis-reversed-list x-value))) + x-value)) #;(let* ((returned (matcher empty-map '())) (x-value (hashmap-ref returned (empty-wrap 'x)))))) |
