58 lines
2.3 KiB
Scheme
58 lines
2.3 KiB
Scheme
(module test-parse ()
|
|
(import scheme)
|
|
(import (chicken base))
|
|
(import (chicken syntax))
|
|
(import srfi-1)
|
|
(import test)
|
|
(import comparse)
|
|
(import srfi-14)
|
|
(import parse)
|
|
|
|
(test "apple" (parse (lift list->string (one-or-more (in char-set:letter))) "apple"))
|
|
|
|
(test '(#\o #\r #\a #\n) (parse (one-or-more (is-not #\g)) "orange"))
|
|
|
|
(test-group "parse-whitespace"
|
|
(test '(#\space #\space #\space) (parse parse-whitespace " "))
|
|
|
|
(test #f (parse parse-whitespace "pear")))
|
|
|
|
(test-group "skip-whitespace"
|
|
(test "mango" (parse (preceded-by skip-whitespace (as-string (one-or-more (in char-set:letter)))) " mango"))
|
|
(test "mango" (parse (preceded-by skip-whitespace (as-string (one-or-more (in char-set:letter)))) "mango")))
|
|
|
|
(test-group "parse-symbol"
|
|
(test 'chicken (parse parse-symbol "chicken")))
|
|
|
|
(test-group "parse-number"
|
|
(test 333 (parse parse-number "333"))
|
|
(test #f (parse parse-number "owlfox")))
|
|
|
|
(test-group "parse-string"
|
|
(test "0day" (parse parse-string "\"0day\""))
|
|
(test #f (parse parse-string "\"0day"))
|
|
(test #f (parse parse-string "0day\""))
|
|
(test #f (parse parse-string "0day")))
|
|
|
|
(test-group "followed-by-consuming"
|
|
(test '("achtung" "hovercraft") (parse (sequence (followed-by-consuming (as-string (one-or-more (in char-set:letter)))
|
|
(char-seq ": ")) (as-string (one-or-more (in char-set:letter)))) "achtung: hovercraft")))
|
|
|
|
(test-group "separated-by"
|
|
(test '("fox" "hen" "lizard") (parse (separated-by (char-seq ", ") (as-string (one-or-more (in char-set:letter)))) "fox, hen, lizard")))
|
|
|
|
(test-group "parse-symbol-or-number-or-string"
|
|
(test 'coin (parse parse-symbol-or-number-or-string "coin"))
|
|
(test 67 (parse parse-symbol-or-number-or-string "67"))
|
|
(test "token" (parse parse-symbol-or-number-or-string "\"token\"")))
|
|
|
|
(test-group "completely-parse"
|
|
(test "owlbear" (parse (as-string (completely-parse (one-or-more (in char-set:letter)))) "owlbear"))
|
|
(test #f (parse (as-string (completely-parse (one-or-more (in char-set:letter)))) "owlbear pelt")))
|
|
|
|
(test-group "parse-statement"
|
|
(test '(set "undulate" 33) (parse parse-statement "set \"undulate\" 33")))
|
|
|
|
(test-group "parse-line"
|
|
(test '(set "christmas" 45) (parse parse-statement "set \"christmas\" 45"))))
|