From 867b84f16e69722d216ead4d920a2890b7081fcf Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 24 May 2018 21:05:41 -0700 Subject: [PATCH] test new syntax --- brag/brag/examples/baby-json-alt.rkt | 16 +++++++++ brag/brag/test/test-baby-json.rkt | 49 +++++++++++++--------------- 2 files changed, 39 insertions(+), 26 deletions(-) create mode 100755 brag/brag/examples/baby-json-alt.rkt diff --git a/brag/brag/examples/baby-json-alt.rkt b/brag/brag/examples/baby-json-alt.rkt new file mode 100755 index 0000000..c454397 --- /dev/null +++ b/brag/brag/examples/baby-json-alt.rkt @@ -0,0 +1,16 @@ +#lang brag + +;; Simple baby example of JSON structure +json ::= number | string + | array + | object + +number ::= NUMBER + +string ::= STRING + +array ::= "[" [json ("," json)*] "]" + +object ::= "{" [kvpair ("," kvpair)*] "}" + +kvpair ::= ID ":" json diff --git a/brag/brag/test/test-baby-json.rkt b/brag/brag/test/test-baby-json.rkt index d59fd2d..f09fa1e 100755 --- a/brag/brag/test/test-baby-json.rkt +++ b/brag/brag/test/test-baby-json.rkt @@ -1,33 +1,30 @@ #lang racket/base (require brag/examples/baby-json + (prefix-in alt: brag/examples/baby-json-alt) brag/support rackunit) -(check-equal? - (syntax->datum - (parse (list "{" - (token 'ID "message") - ":" - (token 'STRING "'hello world'") - "}"))) - '(json (object "{" - (kvpair "message" ":" (json (string "'hello world'"))) - "}"))) +(let ([str (list "{" + (token 'ID "message") + ":" + (token 'STRING "'hello world'") + "}")] + [result '(json (object "{" + (kvpair "message" ":" (json (string "'hello world'"))) + "}"))]) + (check-equal? (parse-to-datum str) result) + (check-equal? (alt:parse-to-datum str) result)) -(check-equal? - (syntax->datum - (parse "[[[{}]],[],[[{}]]]")) - '(json - (array - "[" - (json (array "[" (json (array "[" (json (object "{" "}")) "]")) "]")) - "," - (json (array "[" "]")) - "," - (json (array "[" (json (array "[" (json (object "{" "}")) "]")) "]")) - "]"))) - - - - +(let ([str "[[[{}]],[],[[{}]]]"] + [result '(json + (array + "[" + (json (array "[" (json (array "[" (json (object "{" "}")) "]")) "]")) + "," + (json (array "[" "]")) + "," + (json (array "[" (json (array "[" (json (object "{" "}")) "]")) "]")) + "]"))]) + (check-equal? (parse-to-datum str) result) + (check-equal? (alt:parse-to-datum str) result)) \ No newline at end of file