Skip to content

Commit

Permalink
Fix some early bitrot in basic-parsers, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fare committed Sep 27, 2023
1 parent 3307443 commit 39c5c24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions src/std/text/basic-parsers-test.ss
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@
(only-in :std/parser/base parse-error?)
:std/sugar
:std/test
:std/text
:std/text/basic-parsers)

(export basic-parsers-test)

(def (check-parse parser string result)
(check-equal? (parse-string parser string) result)
(check-equal? (call-with-input-string (parse-port parser port) string) result))
(def (check-parse-error parser string)
(check-exception (parse-string parser string) parse-error?)
(check-exception (call-with-input-string (parse-port parser port) string) parse-error?))
(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-error parse-natural "1 "))
(test-case "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))))
2 changes: 1 addition & 1 deletion src/std/text/basic-parsers.ss
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit 39c5c24

Please sign in to comment.