From 2ebab36f8c689fa3e6f88cfc25cecd83848ca129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 24 Nov 2025 07:01:47 -0300 Subject: Big update --- test.lisp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test.lisp (limited to 'test.lisp') 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."))) -- cgit v1.2.3