From 48226fa7c9749a1a62532251ade401aace4b7d33 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 11 Jun 2018 10:59:09 -0700 Subject: [PATCH] tests --- brag/examples/curly-quantifier.rkt | 7 +++++++ brag/test/test-curly-quantifier.rkt | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 brag/examples/curly-quantifier.rkt create mode 100755 brag/test/test-curly-quantifier.rkt diff --git a/brag/examples/curly-quantifier.rkt b/brag/examples/curly-quantifier.rkt new file mode 100644 index 0000000..7f0d961 --- /dev/null +++ b/brag/examples/curly-quantifier.rkt @@ -0,0 +1,7 @@ +#lang brag +;; test the curly quantifier +start : a-rule | b-rule | c-rule | d-rule +a-rule : "a"{2} ; exactly 2 +b-rule : "b"{,2} ; up to 2 +c-rule : "c"{2,} ; 2 or more +d-rule : "d"{2,3} ; 2 or 3 \ No newline at end of file diff --git a/brag/test/test-curly-quantifier.rkt b/brag/test/test-curly-quantifier.rkt new file mode 100755 index 0000000..c531368 --- /dev/null +++ b/brag/test/test-curly-quantifier.rkt @@ -0,0 +1,23 @@ +#lang racket/base +(require brag/examples/curly-quantifier + brag/support + rackunit) + +(check-exn exn:fail:parsing? (λ () (parse-to-datum "a"))) +(check-equal? (parse-to-datum "aa") '(start (a-rule "a" "a"))) +(check-exn exn:fail:parsing? (λ () (parse-to-datum "aaa"))) + +(check-equal? (parse-to-datum "") '(start (b-rule))) +(check-equal? (parse-to-datum "b") '(start (b-rule "b"))) +(check-equal? (parse-to-datum "bb") '(start (b-rule "b" "b"))) +(check-exn exn:fail:parsing? (λ () (parse-to-datum "bbb"))) + +(check-exn exn:fail:parsing? (λ () (parse-to-datum "c"))) +(check-equal? (parse-to-datum "cc") '(start (c-rule "c" "c"))) +(check-equal? (parse-to-datum "ccc") '(start (c-rule "c" "c" "c"))) +(check-equal? (parse-to-datum "cccc") '(start (c-rule "c" "c" "c" "c"))) + +(check-exn exn:fail:parsing? (λ () (parse-to-datum "d"))) +(check-equal? (parse-to-datum "dd") '(start (d-rule "d" "d"))) +(check-equal? (parse-to-datum "ddd") '(start (d-rule "d" "d" "d"))) +(check-exn exn:fail:parsing? (λ () (parse-to-datum "dddd")))