diff --git a/src/std/text/basic-parsers-test.ss b/src/std/text/basic-parsers-test.ss new file mode 100644 index 000000000..7755c7160 --- /dev/null +++ b/src/std/text/basic-parsers-test.ss @@ -0,0 +1,28 @@ +(import + :std/error + (only-in :std/parser/base parse-error?) + :std/sugar + :std/test + :std/text/basic-parsers) + +(export basic-parsers-test) + +(defrule (check-parse parser string result) + (begin + (check-equal? (parse-string parser string) result) + (check-equal? (call-with-input-string string (cut parse-port parser <>)) result))) +(defrule (check-parse-error parser string) + (begin + (check-exception (parse-string parser string) parse-error?) + (check-exception (call-with-input-string string (cut parse-port parser <>)) parse-error?))) + +(def basic-parsers-test + (test-suite "test suite for std/misc/basic-parsers" + (test-case "1" + (check-parse parse-natural "1" 1) + (check-parse parse-natural "010" 10) ;; ain't no octal + (check-parse (cut parse-natural <> 8) "10" 8) ;; octal this time. + (check-parse-error parse-natural " 1") ;; no space allowed in front unless you ask + (check-parse-error parse-natural "1 no junk allowed")) + (test-case "parse-integer" + (check-equal? 1 1)))) diff --git a/src/std/text/basic-parsers.ss b/src/std/text/basic-parsers.ss index 0848fcd12..5286da79a 100644 --- a/src/std/text/basic-parsers.ss +++ b/src/std/text/basic-parsers.ss @@ -157,7 +157,7 @@ ;; Parse an entire port (def (parse-port parser port (description port) (where 'parse-port)) - (parse-reader parser (PeekableStringReader (make-raw-input-port port)) description where)) + (parse-reader parser (PeekableStringReader (make-raw-textual-input-port port)) description where)) ;; Parse an entire file (def (parse-file parser file (description file) (where 'parse-file)) @@ -198,7 +198,7 @@ (parse-or (parse-begin parse-terminator (parse-pure '())) (parse-bind parse-element - (lambda (e) (parse-repeated (parse-begin parse-separator parse-element) + (lambda (e) (parse-repeated (parse-begin parse-separator parse-element) parse-terminator [e]))))) (def ((parse-n-repeats n parse-element) reader) (for/collect ((_ (in-range n))) (parse-element reader)))