parser tests
This commit is contained in:
parent
ab0b4b7c0e
commit
1418e5583a
@ -1,4 +1,4 @@
|
||||
(module parse (parse-line lift followed-by-consuming is-not)
|
||||
(module parse (parse-line lift followed-by-consuming is-not parse-whitespace skip-whitespace parse-symbol parse-number parse-string followed-by-consuming separated-by parse-symbol-or-number-or-string completely-parse parse-statement parse-line)
|
||||
(import scheme)
|
||||
(import chicken.base)
|
||||
(import srfi-13)
|
||||
|
@ -8,4 +8,50 @@
|
||||
(import srfi-14)
|
||||
(import parse)
|
||||
|
||||
(test "apple" (parse (lift list->string (one-or-more (in char-set:letter))) "apple")))
|
||||
(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"))))
|
||||
|
Loading…
Reference in New Issue
Block a user