aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2025-04-23 21:25:22 -0400
committerGravatar Peter McGoron 2025-04-23 21:25:22 -0400
commit9cd7af935a0655018d3a295f6dc56d0e6ba2b18a (patch)
tree4f5e89b5f5ae8e955e3364b4b9d399574ca6b093 /test
start work on the fundamental syntax object
Diffstat (limited to '')
-rw-r--r--test/run.scm16
-rw-r--r--test/syntax-object.scm132
-rw-r--r--test/syntax-object.sld25
3 files changed, 173 insertions, 0 deletions
diff --git a/test/run.scm b/test/run.scm
new file mode 100644
index 0000000..66a719a
--- /dev/null
+++ b/test/run.scm
@@ -0,0 +1,16 @@
+(import r7rs)
+
+(cond-expand
+ (chicken (import (prefix (mcgoron srfi 64)
+ mcgoron-)
+ (srfi 64))
+ (test-runner-factory mcgoron-factory)
+ (test-runner-current (mcgoron-factory))))
+
+(load "../multisyntax/syntax-object.sld")
+(load "syntax-object.sld")
+
+(import (rename (multisyntax syntax-object test)
+ (test test-syntax-object)))
+
+(test-syntax-object)
diff --git a/test/syntax-object.scm b/test/syntax-object.scm
new file mode 100644
index 0000000..fcd8215
--- /dev/null
+++ b/test/syntax-object.scm
@@ -0,0 +1,132 @@
+#| 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 examples-of-self-syntax
+ (list '() 1 #\a #f "a" #u8(1 2 3 4)))
+
+(define (test)
+ (test-group "locations"
+ (test-assert (comparator-test-type environment-key-comparator
+ (generate-lexical-location 'test)))
+ (test-assert (comparator-test-type environment-key-comparator
+ 'test)))
+ (test-group "self-syntax?"
+ (for-each (lambda (x)
+ (test-assert "example of self-syntax" (self-syntax? x)))
+ examples-of-self-syntax)
+ (test-assert "symbol is not self-syntax" (not (self-syntax? 'x)))
+ (test-assert "cons is not self-syntax" (not (self-syntax? (cons 1 2))))
+ (test-assert "vector is not self-syntax" (not (self-syntax? #(1 2)))))
+ (test-group "syntax?"
+ (for-each (lambda (x)
+ (test-assert "self-syntax is syntax" (syntax? x)))
+ examples-of-self-syntax)
+ (for-each (lambda (x)
+ (test-assert "wrap of self-syntax is syntax" (syntax? (empty-wrap x))))
+ examples-of-self-syntax)
+ (test-assert "list of self-syntax is syntax"
+ (syntax? examples-of-self-syntax))
+ (test-assert "vector of self-syntax is syntax"
+ (syntax? (list->vector examples-of-self-syntax)))
+ (test-assert "wrap of symbol is syntax"
+ (syntax? (empty-wrap 'x))))
+ (test-group "identifier?"
+ (for-each (lambda (x)
+ (test-assert "self-syntax is not identifier"
+ (not (identifier? x))))
+ examples-of-self-syntax)
+ (test-assert "wrap of symbol is identifier"
+ (identifier? (empty-wrap 'x)))
+ (test-assert "wrap of list is not identifier"
+ (not (identifier? (empty-wrap (list 'x))))))
+ (test-group "add-timestamp"
+ (test-assert "timestamps are unique"
+ (not (equal? (generate-timestamp) (generate-timestamp))))
+ (let ((ts (generate-timestamp))
+ (id (empty-wrap 'test)))
+ (test-assert "empty wrap has no timestamps"
+ (set-empty? (wrap->timestamps id)))
+ (set! id (add-timestamp id ts))
+ (test-equal "adding a timestamp adds that timestamp"
+ (list ts)
+ (set->list (wrap->timestamps id)))
+ (set! id (add-timestamp id ts))
+ (test-assert "adding the same timestamp removes the timestamp"
+ (set-empty? (wrap->timestamps id)))
+ (let ((new-ts (generate-timestamp)))
+ (set! id (add-timestamp id ts))
+ (set! id (add-timestamp id new-ts))
+ (test-assert "adding one timestamp makes the wrap contain that timestamp"
+ (set-contains? (wrap->timestamps id) ts))
+ (test-assert "adding another timestamp makes the wrap contain that timestamp"
+ (set-contains? (wrap->timestamps id) new-ts))
+ (test-equal "only two timestamps were added"
+ (set-size (wrap->timestamps id))
+ 2)
+ (set! id (add-timestamp id new-ts))
+ (test-equal "adding one timestamp removes one and keeps the other"
+ (list ts)
+ (set->list (wrap->timestamps id))))))
+ (test-group "resolve a symbol"
+ (test-eq (resolve (empty-wrap 'test)) 'test))
+ (test-group "add-substitution"
+ (test-group "no timestamps"
+ (let* ((newloc (generate-lexical-location 'test))
+ (stx (add-substitution (empty-wrap 'test)
+ (empty-wrap 'test)
+ newloc)))
+ (test-assert (=? lexical-location-comparator
+ newloc
+ (resolve stx)))))
+ (test-group "mismatched timestamps"
+ (let* ((newloc (generate-lexical-location 'test))
+ (stx (add-substitution (add-timestamp (empty-wrap 'test)
+ (generate-timestamp))
+ (empty-wrap 'test)
+ newloc)))
+ (test-assert (=? environment-key-comparator
+ 'test
+ (resolve stx)))))
+ (test-group "mismatched resolved name"
+ (let* ((newloc (generate-lexical-location 'test))
+ (stx (add-substitution (empty-wrap 'test)
+ (empty-wrap 'test2)
+ newloc)))
+ (test-assert (=? environment-key-comparator
+ 'test
+ (resolve stx)))))
+ (test-group "multiple names in environment"
+ (let* ((loc1 (generate-lexical-location 'test1))
+ (loc2 (generate-lexical-location 'test2))
+ (stx (add-substitution (empty-wrap 'test)
+ (empty-wrap 'test)
+ loc1))
+ (stx (add-substitution stx
+ (empty-wrap 'test2)
+ loc2)))
+ (test-assert (=? environment-key-comparator
+ (resolve stx)
+ loc1))))
+ (test-group "intermediate substitutions"
+ (let* ((loc1 (generate-lexical-location 'test1))
+ (loc2 (generate-lexical-location 'test2))
+ (stx (add-substitution (empty-wrap 'test)
+ (empty-wrap 'test)
+ loc1))
+ (stx (add-substitution stx stx loc2)))
+ (test-assert (=? environment-key-comparator
+ (resolve stx)
+ loc2))))))
+
diff --git a/test/syntax-object.sld b/test/syntax-object.sld
new file mode 100644
index 0000000..8b09ead
--- /dev/null
+++ b/test/syntax-object.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 syntax-object test)
+ (import (scheme base)
+ (multisyntax syntax-object)
+ (srfi 113) (srfi 128) (srfi 146))
+ (cond-expand
+ (chicken (import (srfi 64)
+ (chicken condition)))
+ (else))
+ (export test)
+ (include "syntax-object.scm"))