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

@ -1,5 +1,7 @@
#lang racket/base #lang racket/base
(module+ test
(require yaragg/examples/0n1 (require yaragg/examples/0n1
yaragg/support yaragg/support
rackunit) rackunit)
@ -47,4 +49,4 @@
(lambda () (parse '("zero" "one" "zero")))) (lambda () (parse '("zero" "one" "zero"))))
(check-exn (regexp (regexp-quote (check-exn (regexp (regexp-quote
"Encountered unexpected token of type \"zero\" (value \"zero\") while parsing")) "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 #lang racket/base
(module+ test
(require yaragg/examples/0n1n (require yaragg/examples/0n1n
yaragg/support yaragg/support
rackunit) rackunit)
@ -46,4 +49,4 @@
(lambda () (parse #f (lex (open-input-string "0001110"))))) (lambda () (parse #f (lex (open-input-string "0001110")))))
(check-exn exn:fail:parsing? (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 #lang racket/base
(module+ test
(require yaragg/examples/baby-json-hider (require yaragg/examples/baby-json-hider
yaragg/support yaragg/support
rackunit) rackunit)
@ -24,4 +27,4 @@
(json (array "[" "]")) (json (array "[" "]"))
"," ","
(json (array "[" (json (array "[" (json) "]")) "]")) (json (array "[" (json (array "[" (json) "]")) "]"))
"]"))) "]"))))

@ -1,4 +1,7 @@
#lang racket/base #lang racket/base
(module+ test
(require yaragg/examples/baby-json (require yaragg/examples/baby-json
(prefix-in alt: yaragg/examples/baby-json-alt) (prefix-in alt: yaragg/examples/baby-json-alt)
yaragg/support yaragg/support
@ -27,4 +30,4 @@
(json (array "[" (json (array "[" (json (object "{" "}")) "]")) "]")) (json (array "[" (json (array "[" (json (object "{" "}")) "]")) "]"))
"]"))]) "]"))])
(check-equal? (parse-to-datum str) result) (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 #lang racket/base
(module+ test
(require yaragg/examples/codepoints (require yaragg/examples/codepoints
rackunit) rackunit)
@ -7,4 +9,4 @@
'(start (A "\"A\\") '(start (A "\"A\\")
(c "'c\\") (c "'c\\")
(def "*d\\\"\\ef\"") (def "*d\\\"\\ef\"")
(hello-world "hello world"))) (hello-world "hello world"))))

@ -1,4 +1,7 @@
#lang racket/base #lang racket/base
(module+ test
(require yaragg/examples/curly-quantifier (require yaragg/examples/curly-quantifier
yaragg/support yaragg/support
rackunit) rackunit)
@ -22,7 +25,9 @@
(check-equal? (parse-to-datum "ddd") '(start (d-rule "d" "d" "d"))) (check-equal? (parse-to-datum "ddd") '(start (d-rule "d" "d" "d")))
(check-exn exn:fail:parsing? (λ () (parse-to-datum "dddd"))) (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 "e") '(start (e-rule "e")))
(check-equal? (parse-to-datum "ee") '(start (e-rule "e" "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 #lang racket/base
(module+ test
(require yaragg/examples/cutter-another (require yaragg/examples/cutter-another
yaragg/support yaragg/support
rackunit) rackunit)
@ -9,4 +12,4 @@
(check-equal? (parse-tree "z") '(top (z))) (check-equal? (parse-tree "z") '(top (z)))
(check-equal? (parse-tree "a") '(top (a))) (check-equal? (parse-tree "a") '(top (a)))
(check-equal? (parse-tree "bb") '(top (b))) (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 #lang racket/base
(module+ test
(require yaragg/examples/cutter (require yaragg/examples/cutter
yaragg/support yaragg/support
rackunit) rackunit)
@ -6,4 +9,4 @@
;; related to rule-flattening problem ;; related to rule-flattening problem
(check-equal? (check-equal?
(parse-to-datum (list "(" "x" "," "x" ")")) (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 #lang racket/base
(module+ test
(require yaragg/examples/empty-symbol (require yaragg/examples/empty-symbol
yaragg/support yaragg/support
rackunit) rackunit)
@ -18,4 +21,4 @@
;; z splices ;; z splices
(check-equal? (parse-to-datum "z") '(top (zs "z"))) (check-equal? (parse-to-datum "z") '(top (zs "z")))
(check-equal? (parse-to-datum "zz") '(top (zs "z" "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 #lang racket/base
(module+ test
(require rackunit (require rackunit
(for-syntax racket/base)) (for-syntax racket/base))
@ -134,4 +136,4 @@ EOF
(define bad-parser (make-rule-parser crunchy)) (define bad-parser (make-rule-parser crunchy))
EOF EOF
"Rule crunchy is not defined in the grammar" "Rule crunchy is not defined in the grammar"
) ))

@ -1,4 +1,7 @@
#lang racket/base #lang racket/base
(module+ test
(require yaragg/rules/stx-types (require yaragg/rules/stx-types
yaragg/codegen/flatten yaragg/codegen/flatten
rackunit) rackunit)
@ -172,24 +175,23 @@
[(lit "z") (lit "w")]))) [(lit "z") (lit "w")])))
;; seq, repeat (test-case "seq, repeat"
(check-equal? (map syntax->datum (define rule-stx #'(rule expr (seq (id term) (repeat 0 #f (seq (lit "+") (id term))))))
(flatten-rule #'(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)))
#:fresh-name (make-fresh-name)))
'((prim-rule seq expr ((id term) (inferred-id r1 repeat))) '((prim-rule seq expr ((id term) (inferred-id r1 repeat)))
(prim-rule maybe r1 ((inferred-id r2 repeat)) ()) (prim-rule maybe r1 ((inferred-id r2 repeat)) ())
(inferred-prim-rule repeat r2 (inferred-prim-rule repeat r2
((inferred-id r2 repeat) (lit "+") (id term)) ((inferred-id r2 repeat) (lit "+") (id term))
((lit "+") (id term))))) ((lit "+") (id term))))))
;; larger example: simple arithmetic (test-case "larger example: simple arithmetic"
(check-equal? (map syntax->datum (define rule-stxs
(flatten-rules (syntax->list (syntax->list
#'((rule expr (seq (id term) (repeat 0 #f (seq (lit "+") (id term))))) #'((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 term (seq (id factor) (repeat 0 #f (seq (lit "*") (id factor)))))
(rule factor (token INT)))) (rule factor (token INT)))))
#:fresh-name (make-fresh-name))) (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 seq expr ((id term) (inferred-id r1 repeat)))
(prim-rule maybe r1 ((inferred-id r2 repeat)) ()) (prim-rule maybe r1 ((inferred-id r2 repeat)) ())
@ -201,4 +203,4 @@
(inferred-prim-rule repeat r4 (inferred-prim-rule repeat r4
((inferred-id r4 repeat) (lit "*") (id factor)) ((inferred-id r4 repeat) (lit "*") (id factor))
((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 #lang racket/base
(module+ test
(require yaragg/examples/hide-and-splice (require yaragg/examples/hide-and-splice
yaragg/support yaragg/support
rackunit) rackunit)
@ -6,4 +9,4 @@
;; check that an id with both a splice and hide is handled correctly ;; 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 "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 #lang racket/base
(module+ test
(require yaragg/rules/lexer (require yaragg/rules/lexer
rackunit rackunit
yaragg/parser-tools/lex) yaragg/parser-tools/lex)
@ -71,5 +74,6 @@
(check-equal? (l " @") (check-equal? (l " @")
'(SPLICE "@" 2 3)) '(SPLICE "@" 2 3))
; lexer skips kwarg
(check-equal? (l "#:prefix-out val:") (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 #lang racket/base
(module+ test
(require rackunit (require rackunit
yaragg/support yaragg/support
yaragg/examples/subrule) 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-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")) '(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 #lang racket/base
(module+ test
(require yaragg/examples/nested-repeats (require yaragg/examples/nested-repeats
rackunit) rackunit)
(check-equal? (check-equal?
(syntax->datum (parse (list "X" "Y" "X"))) (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. ;; Make sure the old token type also works fine.
(module+ test
(require yaragg/examples/simple-line-drawing (require yaragg/examples/simple-line-drawing
yaragg/support yaragg/support
racket/list racket/list
@ -67,7 +69,7 @@ EOF
(check-equal? (syntax->datum (fourth the-parsed-object)) (check-equal? (syntax->datum (fourth the-parsed-object))
'(rows (repeat 3) (chunk 9 "X") ";")) '(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. ;; FIXME: add tests to make sure location is as we expect.
;; ;;

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

@ -1,6 +1,9 @@
#lang racket/base #lang racket/base
(module+ test
(require yaragg/examples/quotation-marks-and-backslashes (require yaragg/examples/quotation-marks-and-backslashes
yaragg/support yaragg/support
rackunit) 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 #lang racket/base
(module+ test
(require yaragg/examples/simple-arithmetic-grammar (require yaragg/examples/simple-arithmetic-grammar
yaragg/support yaragg/support
racket/set racket/set
@ -69,4 +72,4 @@
(check-equal? all-token-types (check-equal? all-token-types
(set '+ '* 'INT)) (set '+ '* 'INT)))

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

@ -1,5 +1,7 @@
#lang racket/base #lang racket/base
(module+ test
(require yaragg/examples/start-and-atok (require yaragg/examples/start-and-atok
yaragg/support yaragg/support
rackunit) rackunit)
@ -8,7 +10,4 @@
(check-equal? (parse-to-datum (list "start")) '(top "start")) (check-equal? (parse-to-datum (list "start")) '(top "start"))
(check-equal? (parse-to-datum (list "atok")) '(top "atok")) (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 #lang racket/base
(module+ test
(require (prefix-in 1: yaragg/examples/top-level-cut-1) (require (prefix-in 1: yaragg/examples/top-level-cut-1)
(prefix-in 2: yaragg/examples/top-level-cut-2) (prefix-in 2: yaragg/examples/top-level-cut-2)
(prefix-in 3: yaragg/examples/top-level-cut-3) (prefix-in 3: yaragg/examples/top-level-cut-3)
@ -7,5 +10,4 @@
(check-equal? (1:parse-to-datum "x") '((sub "x"))) (check-equal? (1:parse-to-datum "x") '((sub "x")))
(check-equal? (2:parse-to-datum "x") '(("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 #lang racket/base
(module+ test
(require yaragg/tests/weird-grammar (require yaragg/tests/weird-grammar
rackunit) rackunit)
(check-equal? (syntax->datum (parse '("foo"))) (check-equal? (syntax->datum (parse '("foo")))
'(foo "foo")) '(foo "foo")))

@ -1,4 +1,7 @@
#lang racket/base #lang racket/base
(module+ test
(require yaragg/examples/whitespace (require yaragg/examples/whitespace
yaragg/support yaragg/support
rackunit) rackunit)
@ -13,4 +16,4 @@
(check-equal? (check-equal?
(parse-to-datum "\a\b\t\n\v\f\r\e") (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 #lang racket/base
(module+ test
(require yaragg/examples/wordy (require yaragg/examples/wordy
yaragg/support yaragg/support
rackunit) rackunit)
@ -14,5 +17,4 @@
(syntax->datum (syntax->datum
(parse (list "hola" "frumpy" (token 'WORLD "세계")))) (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