aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2025-04-24 18:09:57 -0400
committerGravatar Peter McGoron 2025-04-24 18:09:57 -0400
commit62db3ceddf24bc83110da897ceb8e1239200671b (patch)
tree1f5f906f2080f7d730cd998649541af3110607e9 /test
parentadd tests for bound-identifier-comparator (diff)
add pattern matcher and some tests
Diffstat (limited to 'test')
-rw-r--r--test/patterns.scm64
-rw-r--r--test/patterns.sld25
-rw-r--r--test/run.scm5
3 files changed, 94 insertions, 0 deletions
diff --git a/test/patterns.scm b/test/patterns.scm
new file mode 100644
index 0000000..7669b86
--- /dev/null
+++ b/test/patterns.scm
@@ -0,0 +1,64 @@
+#| Copyright (c) Peter McGoron 2025
+ |
+ | Licensed under the Apache License, Version 2.0 (the "License");
+ | you may not use this file except in compliance with the License.
+ | You may obtain a copy of the License at
+ |
+ | http://www.apache.org/licenses/LICENSE-2.0
+ |
+ | Unless required by applicable law or agreed to in writing, software
+ | distributed under the License is distributed on an "AS IS" BASIS,
+ | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ | See the License for the specific language governing permissions and
+ | limitations under the License.
+ |#
+
+(define ellipsis (empty-wrap '...))
+(define empty-map (hashmap bound-identifier-comparator))
+(define empty-set (set bound-identifier-comparator))
+
+(define (test-single-match)
+ (define matcher
+ (compile-pattern ellipsis
+ empty-set
+ (empty-wrap 'x)))
+ (let ((returned (matcher empty-map (empty-wrap 'y))))
+ (test-assert "identifier"
+ (bound-identifier=? (hashmap-ref returned
+ (empty-wrap 'x))
+ (empty-wrap 'y))))
+ (let* ((returned (matcher empty-map (list
+ (empty-wrap 'y))))
+ (res (hashmap-ref returned (empty-wrap 'x))))
+ (test-assert "match on list returns list" (list? res))
+ (test-assert "is the same list"
+ (bound-identifier=? (list-ref res 0)
+ (empty-wrap 'y)))))
+
+(define (test-match-in-list)
+ (define matcher
+ (compile-pattern ellipsis
+ empty-set
+ (list (empty-wrap 'x))))
+ (let ((returned (matcher empty-map (empty-wrap 'y))))
+ (test-assert "does not match identifier"
+ (not returned)))
+ (let ((returned (matcher empty-map (list (empty-wrap 'y)))))
+ (test-assert "matches inside of list"
+ (bound-identifier=? (hashmap-ref returned (empty-wrap 'x))
+ (empty-wrap 'y)))))
+
+(define (test-multiple-matches-in-list)
+ (define matcher
+ (compile-pattern ellipsis
+ empty-set
+ (list (empty-wrap 'x)
+ (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-patterns)
+ (test-group "single match" (test-single-match))
+ (test-group "test match in list" (test-match-in-list))
+ (test-group "test multiple matches in list" (test-multiple-matches-in-list))) \ No newline at end of file
diff --git a/test/patterns.sld b/test/patterns.sld
new file mode 100644
index 0000000..fac2736
--- /dev/null
+++ b/test/patterns.sld
@@ -0,0 +1,25 @@
+#| Copyright (c) Peter McGoron 2025
+ |
+ | Licensed under the Apache License, Version 2.0 (the "License");
+ | you may not use this file except in compliance with the License.
+ | You may obtain a copy of the License at
+ |
+ | http://www.apache.org/licenses/LICENSE-2.0
+ |
+ | Unless required by applicable law or agreed to in writing, software
+ | distributed under the License is distributed on an "AS IS" BASIS,
+ | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ | See the License for the specific language governing permissions and
+ | limitations under the License.
+ |#
+
+(define-library (multisyntax patterns test)
+ (import (scheme base) (srfi 113) (srfi 146 hash)
+ (multisyntax syntax-object)
+ (multisyntax patterns))
+ (cond-expand
+ (chicken (import (srfi 64)
+ (chicken condition)))
+ (else))
+ (export test-patterns)
+ (include "patterns.scm"))
diff --git a/test/run.scm b/test/run.scm
index 66a719a..a22fa45 100644
--- a/test/run.scm
+++ b/test/run.scm
@@ -14,3 +14,8 @@
(test test-syntax-object)))
(test-syntax-object)
+
+(load "../multisyntax/patterns.sld")
+(load "patterns.sld")
+(import (multisyntax patterns test))
+(test-patterns)