You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
brag/tests/test-0n1.rkt

53 lines
1.4 KiB
Racket

8 years ago
#lang racket/base
(module+ test
8 years ago
(require yaragg/examples/0n1
yaragg/support
rackunit)
8 years ago
(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")])))
8 years ago
(check-equal? (syntax->datum (parse #f (lex (open-input-string "1"))))
'(rule "1"))
8 years ago
(check-equal? (syntax->datum (parse #f (lex (open-input-string "01"))))
'(rule "0" "1"))
8 years ago
(check-equal? (syntax->datum (parse #f (lex (open-input-string "001"))))
'(rule "0" "0" "1"))
8 years ago
(check-exn exn:fail:parsing?
(lambda ()
(parse #f (lex (open-input-string "0")))))
8 years ago
(check-exn exn:fail:parsing?
(lambda ()
(parse #f (lex (open-input-string "10")))))
8 years ago
(check-exn exn:fail:parsing?
(lambda ()
(parse #f (lex (open-input-string "010")))))
8 years ago
;; This should fail predictably because we're passing in tokens
;; that the parser doesn't know.
(check-exn exn:fail:parsing?
(lambda () (parse '("zero" "one" "zero"))))
(check-exn (regexp (regexp-quote
"Encountered unexpected token of type \"zero\" (value \"zero\") while parsing"))
(lambda () (parse '("zero" "one" "zero")))))