Commits

Moritz Heidkamp  committed 73e1702

Put all tests in groups

  • Participants
  • Parent commits ccc1113

Comments (0)

Files changed (1)

File tests/run.scm

     ((_ expect parser input)
      (test-parse expect (as-string parser) input))))
 
-(test-parse* "aaba" (repeated (satisfies (char-set #\a #\b))) "aabac")
-(test-parse* "   " (repeated (is #\space) max: 3) "      ")
-(test-parse* "" (repeated (is #\f)) "x")
-(test-parse* #f (repeated (is #\a) min: 1) "b")
-(test-parse #\a (preceded-by (none-of (is #\b) (is #\c)) item) "a")
-(test-parse* "b52" (zero-or-more (any-of (satisfies char-set:digit) (is #\b))) "b52s")
-
-(test-parse #f (none-of (is #\b) (is #\a)) "a")
-
-(test-parse* "ab"
-             (sequence* 
-                 ((a (is #\a)) (b (is #\b)))
-               (result (list a b)))
-             "abc")
-
 (test-group "tests one-or-more / zero-or-more"
   (test-parse* "ooooo" (one-or-more (is #\o)) "ooooom")
   (test-parse* #f (one-or-more (is #\o)) "m")
   (test-parse "hey" (char-seq "hey") "heyyy")
   (test-parse #f (char-seq "hey") "he"))
 
-
-(define (quoted-string #!key
-                       (delimiter (satisfies (char-set #\" #\')))
-                       (escape (is #\\)))
-  (let ((escaped-char (preceded-by escape item)))
-    (sequence* ((_ (zero-or-more (satisfies char-set:whitespace)))
-                (actual-delimiter delimiter)
-                (chars (zero-or-more
-                        (any-of escaped-char
-                                (preceded-by (none-of escape (is actual-delimiter))
-                                             item))))
-                (_ (is actual-delimiter)))
-      (result (list->string chars)))))
-
-(test-assert (not (parse (quoted-string) "this ain't a string")))
-(test "nice" (parse (quoted-string) "\"nice\""))
-
-(receive (result rest) (parse (quoted-string) "\"string 1\" 'string 2'  some trailing ")
-  (test "string 1" result)
-  (receive (result rest) (parse (quoted-string) rest)
-    (test "string 2" result)
-    (receive (result rest) (parse (quoted-string) rest)
-      (test-assert (not result))
-      (test "  some trailing " (list->string (lazy-seq->list rest))))))
-
-(let ((singly-quoted-bang-string (quoted-string delimiter: (is #\') escape: (is #\!))))
-  (test "this 'is' a string" (parse singly-quoted-bang-string "'this !'is!' a string'"))
-  (test "ok\\" (parse singly-quoted-bang-string "'ok\\'"))
-  (test-assert (not (parse singly-quoted-bang-string "\"check\""))))
-
 (test-group "followed-by"
   (let ((lol (preceded-by (followed-by item (is #\o) (is #\l)) item)))
     (test #\o (parse lol "lol"))
     (test-parse #f not-xy "x")
     (test-parse #f not-xy "y")))
 
+(test-group "misc"
+  (test-parse* "aaba" (repeated (satisfies (char-set #\a #\b))) "aabac")
+  (test-parse* "   " (repeated (is #\space) max: 3) "      ")
+  (test-parse* "" (repeated (is #\f)) "x")
+  (test-parse* #f (repeated (is #\a) min: 1) "b")
+  (test-parse #\a (preceded-by (none-of (is #\b) (is #\c)) item) "a")
+  (test-parse* "b52" (zero-or-more (any-of (satisfies char-set:digit) (is #\b))) "b52s")
+
+  (test-parse #f (none-of (is #\b) (is #\a)) "a")
+
+  (test-parse* "ab"
+               (sequence* 
+                   ((a (is #\a)) (b (is #\b)))
+                 (result (list a b)))
+               "abc"))
+
+(test-group "quoted string"
+  (define (quoted-string #!key
+                         (delimiter (satisfies (char-set #\" #\')))
+                         (escape (is #\\)))
+    (let ((escaped-char (preceded-by escape item)))
+      (sequence* ((_ (zero-or-more (satisfies char-set:whitespace)))
+                  (actual-delimiter delimiter)
+                  (chars (zero-or-more
+                          (any-of escaped-char
+                                  (preceded-by (none-of escape (is actual-delimiter))
+                                               item))))
+                  (_ (is actual-delimiter)))
+        (result (list->string chars)))))
+
+  (test-assert (not (parse (quoted-string) "this ain't a string")))
+  (test "nice" (parse (quoted-string) "\"nice\""))
+
+
+  (receive (result rest) (parse (quoted-string) "\"string 1\" 'string 2'  some trailing ")
+    (test "string 1" result)
+    (receive (result rest) (parse (quoted-string) rest)
+      (test "string 2" result)
+      (receive (result rest) (parse (quoted-string) rest)
+        (test-assert (not result))
+        (test "  some trailing " (list->string (lazy-seq->list rest))))))
+
+  (define singly-quoted-bang-string (quoted-string delimiter: (is #\') escape: (is #\!)))
+  (test "this 'is' a string" (parse singly-quoted-bang-string "'this !'is!' a string'"))
+  (test "ok\\" (parse singly-quoted-bang-string "'ok\\'"))
+  (test-assert (not (parse singly-quoted-bang-string "\"check\""))))
+
 (test-exit)