summaryrefslogtreecommitdiff
path: root/test.lisp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2025-11-24 07:01:47 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2025-11-24 07:01:47 -0300
commit2ebab36f8c689fa3e6f88cfc25cecd83848ca129 (patch)
tree63208a8be028b19974b8a5e686470bd4fb3fc657 /test.lisp
parent1c1162747d8d7e12140329a105c0776d5555a351 (diff)
downloadmonparser-2ebab36f8c689fa3e6f88cfc25cecd83848ca129.tar.gz
monparser-2ebab36f8c689fa3e6f88cfc25cecd83848ca129.zip
Big update
Diffstat (limited to 'test.lisp')
-rw-r--r--test.lisp62
1 files changed, 62 insertions, 0 deletions
diff --git a/test.lisp b/test.lisp
new file mode 100644
index 0000000..b0ffdc2
--- /dev/null
+++ b/test.lisp
@@ -0,0 +1,62 @@
+(in-package #:monparser)
+
+(defmacro deftest (title &body tests)
+ (let ((result '(progn)))
+ (push `(format t "~a:~&" ,title) result)
+ (dolist (test tests)
+ (let ((parser (first test))
+ (input (second test)))
+ (push `(format t "~a~&" (parse ,parser ,input)) result)))
+ (push '(format t "~%") result)
+ (reverse result)))
+
+(defun test ()
+ (deftest "unit"
+ ((unit) "hello")
+ ((unit #\h) "hello"))
+ (deftest "many"
+ ((many (unit #\h)) "hello")
+ ((many (unit #\h)) "hhhhhhhello")
+ ((many (unit #\h)) "ello"))
+ (deftest "optional many"
+ ((optional (many (unit #\h))) "hello")
+ ((optional (many (unit #\h))) "hhhhhhhello")
+ ((optional (many (unit #\h))) "ello"))
+ (deftest "many optional"
+ ((many (optional (unit #\h))) "hello")
+ ((many (optional (unit #\h))) "hhhhhhhello")
+ ((many (optional (unit #\h))) "ello"))
+ (deftest "until literal"
+ ((comp ((prefix (optional (literal "zy")))
+ (match (if prefix
+ (fail "Reached prefix")
+ (unit))))
+ match)
+ "zy")
+ ((comp (((prefix) (optional (literal "zy")))
+ ((match) (if (parsing-tree prefix)
+ (fail "Reached prefix")
+ (progn
+ (format t "prefix start: ~a, end: ~a~&"
+ (parsing-start prefix)
+ (parsing-end prefix))
+ (unit)))))
+ (format t "match start: ~a, end: ~a~&"
+ (parsing-start match)
+ (parsing-end match))
+ match)
+ "ezy")
+ ((many (comp ((prefix (optional (literal "zy")))
+ (match (if prefix
+ (fail "Reached prefix")
+ (unit))))
+ match))
+ "the quick brown fox jumps over the lazy dog.")
+ ((optional
+ (many
+ (comp ((prefix (optional (literal "zy")))
+ (match (if prefix
+ (fail "Reached prefix")
+ (unit))))
+ match)))
+ "the quick brown fox jumps over the lazy dog.")))