Add a regression test for make-rule-parser

pull/28/head
Markus Pfeiffer 3 years ago
parent 8d7546f228
commit 555e2e0193
No known key found for this signature in database
GPG Key ID: 9E429BDC79806DC1

@ -0,0 +1,4 @@
#lang brag
start: next
next: "0"

@ -0,0 +1,44 @@
#lang racket/base
(require rackunit
brag/support
br-parser-tools/lex
brag/rules/parser
brag/rules/lexer
)
(require "make-rule-parser-grammar.rkt")
(define parse-next
(make-rule-parser next))
(define parse-start
(make-rule-parser start))
(define (lex ip)
(port-count-lines! ip)
(lambda ()
(define next-char (read-char ip))
(cond [(eof-object? next-char)
(token eof)]
[(char=? next-char #\0)
(token "0" "0")]
[(char=? next-char #\1)
(token "1" "1")])))
(check-equal? (syntax->datum (parse #f (lex (open-input-string "0"))))
'(start (next "0")))
(check-equal? (syntax->datum (parse #f (lex (open-input-string "0"))))
(syntax->datum (parse (lex (open-input-string "0")))))
(check-equal? (syntax->datum (parse-start #f (lex (open-input-string "0"))))
'(start (next "0")))
(check-equal? (syntax->datum (parse-start #f (lex (open-input-string "0"))))
(syntax->datum (parse-start (lex (open-input-string "0")))))
(check-equal? (syntax->datum (parse-next #f (lex (open-input-string "0"))))
'(next "0"))
(check-equal? (syntax->datum (parse-next #f (lex (open-input-string "0"))))
(syntax->datum (parse-next (lex (open-input-string "0")))))
Loading…
Cancel
Save