Use test submodules for yaragg lang tests

remotes/jackfirth/master
Jack Firth 3 years ago
parent 5a90bb6551
commit e7415fc690

@ -1,5 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/01-equal
rackunit)
@ -26,5 +28,4 @@
'(equal (one (equal) "1")
(zero (equal (one (equal) "1")
(zero (equal) "0"))
"0")))
"0"))))

@ -1,5 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/0n1
yaragg/support
rackunit)
@ -47,4 +49,4 @@
(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"))))
(lambda () (parse '("zero" "one" "zero")))))

@ -1,4 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/0n1n
yaragg/support
rackunit)
@ -46,4 +49,4 @@
(lambda () (parse #f (lex (open-input-string "0001110")))))
(check-exn exn:fail:parsing?
(lambda () (parse #f (lex (open-input-string "10001110")))))
(lambda () (parse #f (lex (open-input-string "10001110"))))))

@ -1,26 +0,0 @@
#lang racket/base
(require yaragg/tests/test-0n1
yaragg/tests/test-0n1n
yaragg/tests/test-01-equal
yaragg/tests/test-baby-json
yaragg/tests/test-baby-json-hider
yaragg/tests/test-curly-quantifier
yaragg/tests/test-cutter
yaragg/tests/test-empty-symbol
yaragg/tests/test-errors
yaragg/tests/test-flatten
yaragg/tests/test-hide-and-splice
yaragg/tests/test-lexer
yaragg/tests/test-nested-repeats
yaragg/tests/test-old-token
yaragg/tests/test-parser
yaragg/tests/test-quotation-marks-and-backslashes
yaragg/tests/test-simple-arithmetic-grammar
yaragg/tests/test-simple-line-drawing
yaragg/tests/test-start-and-atok
yaragg/tests/test-top-level-cut
yaragg/tests/test-weird-grammar
yaragg/tests/test-whitespace
yaragg/tests/test-wordy
(submod yaragg/codegen/satisfaction test))

@ -1,4 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/baby-json-hider
yaragg/support
rackunit)
@ -24,4 +27,4 @@
(json (array "[" "]"))
","
(json (array "[" (json (array "[" (json) "]")) "]"))
"]")))
"]"))))

@ -1,4 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/baby-json
(prefix-in alt: yaragg/examples/baby-json-alt)
yaragg/support
@ -27,4 +30,4 @@
(json (array "[" (json (array "[" (json (object "{" "}")) "]")) "]"))
"]"))])
(check-equal? (parse-to-datum str) result)
(check-equal? (alt:parse-to-datum str) result))
(check-equal? (alt:parse-to-datum str) result)))

@ -1,5 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/codepoints
rackunit)
@ -7,4 +9,4 @@
'(start (A "\"A\\")
(c "'c\\")
(def "*d\\\"\\ef\"")
(hello-world "hello world")))
(hello-world "hello world"))))

@ -1,4 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/curly-quantifier
yaragg/support
rackunit)
@ -22,7 +25,9 @@
(check-equal? (parse-to-datum "ddd") '(start (d-rule "d" "d" "d")))
(check-exn exn:fail:parsing? (λ () (parse-to-datum "dddd")))
(check-equal? (syntax->datum ((make-rule-parser e-rule) "")) '(e-rule)) ; to prevent ambiguity with b-rule while parsing empty string
; to prevent ambiguity with b-rule while parsing empty string
(check-equal? (syntax->datum ((make-rule-parser e-rule) "")) '(e-rule))
(check-equal? (parse-to-datum "e") '(start (e-rule "e")))
(check-equal? (parse-to-datum "ee") '(start (e-rule "e" "e")))
(check-equal? (parse-to-datum "eee") '(start (e-rule "e" "e" "e")))
(check-equal? (parse-to-datum "eee") '(start (e-rule "e" "e" "e"))))

@ -1,4 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/cutter-another
yaragg/support
rackunit)
@ -9,4 +12,4 @@
(check-equal? (parse-tree "z") '(top (z)))
(check-equal? (parse-tree "a") '(top (a)))
(check-equal? (parse-tree "bb") '(top (b)))
(check-equal? (parse-tree "c") '(top (c)))
(check-equal? (parse-tree "c") '(top (c))))

@ -1,4 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/cutter
yaragg/support
rackunit)
@ -6,4 +9,4 @@
;; related to rule-flattening problem
(check-equal?
(parse-to-datum (list "(" "x" "," "x" ")"))
'(top (expr (list "(" (expr "x") "," (expr "x") ")"))))
'(top (expr (list "(" (expr "x") "," (expr "x") ")")))))

@ -1,4 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/empty-symbol
yaragg/support
rackunit)
@ -18,4 +21,4 @@
;; z splices
(check-equal? (parse-to-datum "z") '(top (zs "z")))
(check-equal? (parse-to-datum "zz") '(top (zs "z" "z")))
(check-equal? (parse-to-datum "zzz") '(top (zs "z" "z" "z")))
(check-equal? (parse-to-datum "zzz") '(top (zs "z" "z" "z"))))

@ -1,5 +1,7 @@
#lang racket/base
(module+ test
(require rackunit
(for-syntax racket/base))
@ -134,4 +136,4 @@ EOF
(define bad-parser (make-rule-parser crunchy))
EOF
"Rule crunchy is not defined in the grammar"
)
))

@ -1,4 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/rules/stx-types
yaragg/codegen/flatten
rackunit)
@ -172,24 +175,23 @@
[(lit "z") (lit "w")])))
;; seq, repeat
(check-equal? (map syntax->datum
(flatten-rule #'(rule expr (seq (id term) (repeat 0 #f (seq (lit "+") (id term)))))
#:fresh-name (make-fresh-name)))
(test-case "seq, repeat"
(define rule-stx #'(rule expr (seq (id term) (repeat 0 #f (seq (lit "+") (id term))))))
(check-equal? (map syntax->datum (flatten-rule rule-stx #:fresh-name (make-fresh-name)))
'((prim-rule seq expr ((id term) (inferred-id r1 repeat)))
(prim-rule maybe r1 ((inferred-id r2 repeat)) ())
(inferred-prim-rule repeat r2
((inferred-id r2 repeat) (lit "+") (id term))
((lit "+") (id term)))))
((lit "+") (id term))))))
;; larger example: simple arithmetic
(check-equal? (map syntax->datum
(flatten-rules (syntax->list
(test-case "larger example: simple arithmetic"
(define rule-stxs
(syntax->list
#'((rule expr (seq (id term) (repeat 0 #f (seq (lit "+") (id term)))))
(rule term (seq (id factor) (repeat 0 #f (seq (lit "*") (id factor)))))
(rule factor (token INT))))
#:fresh-name (make-fresh-name)))
(rule factor (token INT)))))
(check-equal? (map syntax->datum (flatten-rules rule-stxs #:fresh-name (make-fresh-name)))
'((prim-rule seq expr ((id term) (inferred-id r1 repeat)))
(prim-rule maybe r1 ((inferred-id r2 repeat)) ())
@ -201,4 +203,4 @@
(inferred-prim-rule repeat r4
((inferred-id r4 repeat) (lit "*") (id factor))
((lit "*") (id factor)))
(prim-rule token factor ((token INT)))))
(prim-rule token factor ((token INT)))))))

@ -1,4 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/hide-and-splice
yaragg/support
rackunit)
@ -6,4 +9,4 @@
;; check that an id with both a splice and hide is handled correctly
(check-equal? (parse-to-datum "xxx") '(top ("x" "x" "x")))
(check-equal? (parse-to-datum "yyy") '(top "y" "y" "y"))
(check-equal? (parse-to-datum "yyy") '(top "y" "y" "y")))

@ -1,4 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/rules/lexer
rackunit
yaragg/parser-tools/lex)
@ -71,5 +74,6 @@
(check-equal? (l " @")
'(SPLICE "@" 2 3))
; lexer skips kwarg
(check-equal? (l "#:prefix-out val:")
(list 'EOF eof 18 18)) ; lexer skips kwarg
(list 'EOF eof 18 18)))

@ -1,4 +1,7 @@
#lang racket/base
(module+ test
(require rackunit
yaragg/support
yaragg/examples/subrule)
@ -13,5 +16,4 @@
(check-equal? (syntax->datum (parse-start #f "0")) (syntax->datum (parse-start "0")))
(check-equal? (syntax->datum (parse-next #f "0")) '(next "0"))
(check-equal? (syntax->datum (parse-next #f "0")) (syntax->datum (parse-next "0")))
(check-equal? (syntax->datum (parse-next #f "0")) (syntax->datum (parse-next "0"))))

@ -1,9 +1,10 @@
#lang racket/base
(module+ test
(require yaragg/examples/nested-repeats
rackunit)
(check-equal?
(syntax->datum (parse (list "X" "Y" "X")))
'(start "X" "Y" "X"))
'(start "X" "Y" "X")))

@ -2,6 +2,8 @@
;; Make sure the old token type also works fine.
(module+ test
(require yaragg/examples/simple-line-drawing
yaragg/support
racket/list
@ -67,7 +69,7 @@ EOF
(check-equal? (syntax->datum (fourth the-parsed-object))
'(rows (repeat 3) (chunk 9 "X") ";"))
(check-equal? (syntax-line (list-ref the-parsed-object 3)) 3)
(check-equal? (syntax-line (list-ref the-parsed-object 3)) 3))
;; FIXME: add tests to make sure location is as we expect.
;;

@ -1,5 +1,6 @@
#lang racket/base
(module+ test
(require rackunit
yaragg/parser-tools/lex
@ -97,9 +98,12 @@
#f))))
(check-equal? (grammar-parser (tokenize (open-input-string "expr : COLON | BLAH | BAZ expr")))
(list (rule (p 1) (p 31)
(list
(rule
(p 1) (p 31)
(lhs-id (p 1) (p 5) "expr" #f)
(pattern-choice (p 8) (p 31)
(pattern-choice
(p 8) (p 31)
(list (pattern-token (p 8) (p 13) "COLON" #f)
(pattern-token (p 16) (p 20) "BLAH" #f)
(pattern-seq (p 23) (p 31)
@ -127,27 +131,36 @@
#f))))
(check-equal? (grammar-parser (tokenize (open-input-string "expr : one two* three")))
(list (rule (p 1) (p 22)
(list
(rule
(p 1) (p 22)
(lhs-id (p 1) (p 5) "expr" #f)
(pattern-seq (p 8) (p 22)
(pattern-seq
(p 8) (p 22)
(list (pattern-id (p 8) (p 11) "one" #f)
(pattern-repeat (p 12) (p 16) 0 #f (pattern-id (p 12) (p 15) "two" #f) #f)
(pattern-id (p 17) (p 22) "three" #f))
#f))))
(check-equal? (grammar-parser (tokenize (open-input-string "expr : one two+ three")))
(list (rule (p 1) (p 22)
(list
(rule
(p 1) (p 22)
(lhs-id (p 1) (p 5) "expr" #f)
(pattern-seq (p 8) (p 22)
(pattern-seq
(p 8) (p 22)
(list (pattern-id (p 8) (p 11) "one" #f)
(pattern-repeat (p 12) (p 16) 1 #f (pattern-id (p 12) (p 15) "two" #f) #f)
(pattern-id (p 17) (p 22) "three" #f))
#f))))
(check-equal? (grammar-parser (tokenize (open-input-string "expr : (one two)+ three")))
(list (rule (p 1) (p 24)
(list
(rule
(p 1) (p 24)
(lhs-id (p 1) (p 5) "expr" #f)
(pattern-seq (p 8) (p 24)
(pattern-seq
(p 8) (p 24)
(list (pattern-repeat (p 8) (p 18) 1 #f
(pattern-seq (p 8) (p 17)
(list (pattern-id (p 9) (p 12) "one" #f)
@ -164,7 +177,8 @@ stat: ID '=' expr
| 'print' expr
EOF
)))
(list (rule (p 1) (p 17)
(list
(rule (p 1) (p 17)
(lhs-id (p 1) (p 9) "statlist" #f)
(pattern-repeat (p 12) (p 17) 1 #f (pattern-id (p 12) (p 16) "stat" #f) #f))
(rule (p 18) (p 54)
@ -179,5 +193,4 @@ EOF
(list (pattern-lit (p 42) (p 49) "print" #f)
(pattern-id (p 50) (p 54) "expr" #f))
#f))
#f))))
#f)))))

@ -1,6 +1,9 @@
#lang racket/base
(module+ test
(require yaragg/examples/quotation-marks-and-backslashes
yaragg/support
rackunit)
(check-equal? (parse-tree "a\"'\\a\"'\\") '(start "a" "\"" "'" "\\" "a" "\"" "'" "\\"))
(check-equal? (parse-tree "a\"'\\a\"'\\") '(start "a" "\"" "'" "\\" "a" "\"" "'" "\\")))

@ -1,4 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/simple-arithmetic-grammar
yaragg/support
racket/set
@ -69,4 +72,4 @@
(check-equal? all-token-types
(set '+ '* 'INT))
(set '+ '* 'INT)))

@ -1,5 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/simple-line-drawing
yaragg/support
racket/list
@ -63,7 +65,7 @@ EOF
(check-equal? (syntax->datum (fourth the-parsed-object))
'(rows (repeat 3) (chunk 9 "X") ";"))
(check-equal? (syntax-line (list-ref the-parsed-object 3)) 3)
(check-equal? (syntax-line (list-ref the-parsed-object 3)) 3))
;; FIXME: add tests to make sure location is as we expect.
;;

@ -1,5 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/start-and-atok
yaragg/support
rackunit)
@ -8,7 +10,4 @@
(check-equal? (parse-to-datum (list "start")) '(top "start"))
(check-equal? (parse-to-datum (list "atok")) '(top "atok"))
(check-equal? (parse-to-datum (list "start" "atok")) '(top "start" "atok"))
(check-equal? (parse-to-datum (list "start" "atok")) '(top "start" "atok")))

@ -1,4 +1,7 @@
#lang racket/base
(module+ test
(require (prefix-in 1: yaragg/examples/top-level-cut-1)
(prefix-in 2: yaragg/examples/top-level-cut-2)
(prefix-in 3: yaragg/examples/top-level-cut-3)
@ -7,5 +10,4 @@
(check-equal? (1:parse-to-datum "x") '((sub "x")))
(check-equal? (2:parse-to-datum "x") '(("x")))
(check-equal? (3:parse-to-datum "x") '("x"))
(check-equal? (3:parse-to-datum "x") '("x")))

@ -1,7 +1,9 @@
#lang racket/base
(module+ test
(require yaragg/tests/weird-grammar
rackunit)
(check-equal? (syntax->datum (parse '("foo")))
'(foo "foo"))
'(foo "foo")))

@ -1,4 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/whitespace
yaragg/support
rackunit)
@ -13,4 +16,4 @@
(check-equal?
(parse-to-datum "\a\b\t\n\v\f\r\e")
'(start (all "\a" "\b" "\t" "\n" "\v" "\f" "\r" "\e")))
'(start (all "\a" "\b" "\t" "\n" "\v" "\f" "\r" "\e"))))

@ -1,4 +1,7 @@
#lang racket/base
(module+ test
(require yaragg/examples/wordy
yaragg/support
rackunit)
@ -14,5 +17,4 @@
(syntax->datum
(parse (list "hola" "frumpy" (token 'WORLD "세계"))))
'(sentence (verb (greeting "hola")) (optional-adjective "frumpy") (object "세계")))
'(sentence (verb (greeting "hola")) (optional-adjective "frumpy") (object "세계"))))

Loading…
Cancel
Save