aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2022-01-03 00:05:53 +0530
committerArun Isaac2022-01-03 00:17:22 +0530
commita19281d1f04583c711329aa219555dd2067eb2c2 (patch)
treeaffe9a3cd88460408195972db0741dd29af3b930
parent055fd7b9fbf60a1c984dfc58588362dda71f6c1f (diff)
downloadkolam-a19281d1f04583c711329aa219555dd2067eb2c2.tar.gz
kolam-a19281d1f04583c711329aa219555dd2067eb2c2.tar.lz
kolam-a19281d1f04583c711329aa219555dd2067eb2c2.zip
tests: Add tests.
* tests/parse.scm: New file.
-rw-r--r--tests/parse.scm66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/parse.scm b/tests/parse.scm
new file mode 100644
index 0000000..d8d3594
--- /dev/null
+++ b/tests/parse.scm
@@ -0,0 +1,66 @@
+;;; kolam --- GraphQL implementation
+;;; Copyright © 2022 Arun Isaac <arunisaac@systemreboot.net>
+;;;
+;;; This file is part of kolam.
+;;;
+;;; kolam is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU Affero General Public License as
+;;; published by the Free Software Foundation; either version 3 of the
+;;; License, or (at your option) any later version.
+;;;
+;;; kolam is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;;; Affero General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU Affero General Public
+;;; License along with kolam. If not, see
+;;; <http://www.gnu.org/licenses/>.
+
+(import (srfi srfi-64))
+
+(define token-pattern
+ (@@ (kolam parse) token-pattern))
+
+(define token-value-pattern
+ (@@ (kolam parse) token-value-pattern))
+
+(define optional?
+ (@@ (kolam parse) optional?))
+
+(eval-when (expand load eval)
+ (define (macro-ref module symbol)
+ (macro-transformer
+ (module-ref (resolve-module module) symbol))))
+
+(define-syntax pattern-many
+ (macro-ref '(kolam parse) 'pattern-many))
+
+(define-syntax pattern-optional
+ (macro-ref '(kolam parse) 'pattern-optional))
+
+(define-syntax pattern-and
+ (macro-ref '(kolam parse) 'pattern-and))
+
+(define-syntax pattern-or
+ (macro-ref '(kolam parse) 'pattern-or))
+
+(test-begin "parse")
+
+(test-assert "pattern-and should not fail when matching an optional pattern on an empty list of tokens"
+ ((pattern-and identity
+ (pattern-optional (token-pattern 'foo)))
+ (list)))
+
+(test-assert "pattern-or should not fail when matching an optional pattern on an empty list of tokens"
+ ((pattern-or identity
+ (pattern-optional (token-pattern 'foo)))
+ (list)))
+
+(test-equal "pattern-many should return an empty list when there are no matches"
+ (list)
+ ((pattern-many identity
+ (token-pattern 'foo))
+ (list (cons 'bar 1))))
+
+(test-end "parse")