From a4ba7c8ebc3eb6ba3620a8fe0a224b8b30d199a2 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Mon, 12 Mar 2012 05:54:42 -0400 Subject: [PATCH] Some semi-quick tests for the json code. (With some items that need to be done.) --- collects/json/info.rkt | 2 + collects/json/tests/json.rkt | 71 ++++++++++++++++++++++++++++++++++++ collects/meta/props | 1 + 3 files changed, 74 insertions(+) create mode 100644 collects/json/tests/json.rkt diff --git a/collects/json/info.rkt b/collects/json/info.rkt index ec04bd2359..f28c0a79d0 100644 --- a/collects/json/info.rkt +++ b/collects/json/info.rkt @@ -1,3 +1,5 @@ #lang setup/infotab (define scribblings '(("json.scrbl" () (parsing-library)))) + +(define compile-omit-paths '("tests")) diff --git a/collects/json/tests/json.rkt b/collects/json/tests/json.rkt new file mode 100644 index 0000000000..cfc022056c --- /dev/null +++ b/collects/json/tests/json.rkt @@ -0,0 +1,71 @@ +#lang at-exp racket/base + +(require json racket/string tests/eli-tester) + +(define T string-append) + +(define (pred-tests) + (test (jsexpr? 0) + (jsexpr? 1) + (jsexpr? -1) + (jsexpr? 12345) + (jsexpr? 0.0) + (jsexpr? 1.0) + (not (jsexpr? 1/2)) + (not (jsexpr? +i)) + (not (jsexpr? 'foo)) + (not (jsexpr? 'true)) + (jsexpr? #t) + (jsexpr? #f) + (jsexpr? #\null) ; TODO + (jsexpr? "") + (jsexpr? "abc") + (jsexpr? "abc\n\\") + (jsexpr? '()) + (jsexpr? '(1 2 3)) + (jsexpr? '(1 "2" (3) #t #f #\null)) + (jsexpr? '((((()))))) + (not (jsexpr? '(1 2 . 3))) + (not (jsexpr? '#(1 2 3))) + (jsexpr? '#hasheq()) + (jsexpr? '#hasheq([x . 1])) + (jsexpr? '#hasheq([x . 1] [y . 2])) + (jsexpr? '#hash([x . 1] [y . 2])) ; fine as a jsexpr too + (jsexpr? '#hasheq([|x\y| . 1] [y . 2])) + (not (jsexpr? '#hasheq([1 . 1]))) + (not (jsexpr? '#hasheq(["x" . 1]))) + (not (jsexpr? '#hasheq(['() . 1]))) + )) + +(define (print-tests) + (for ([x (list 0 1 -1 12345 0.0 1.0 #t #f #\null "" "abc" "abc\n\\" + '() '(1 2 3) '(1 "2" (3) #t #f #\null) '((((())))) + '#hasheq() + '#hasheq([x . 1]) + '#hasheq([x . 1] [y . 2]) + ;; '#hasheq([|x\y| . 1] [y . 2]) ; TODO + )]) + (test (json->jsexpr (jsexpr->json x)) => x))) + +(define (parse-tests) + (test (json->jsexpr @T{ 1 }) => 1 + ;; (json->jsexpr @T{ +1 }) => 1 ; TODO + (json->jsexpr @T{ -1 }) => -1 + (json->jsexpr @T{ 1.0 }) => 1.0 + ;; (json->jsexpr @T{ +1.0 }) => +1.0 ; TODO + (json->jsexpr @T{ -1.0 }) => -1.0 + (json->jsexpr @T{ true }) => #t + (json->jsexpr @T{ false }) => #f + (json->jsexpr @T{ null }) => #\null ; TODO + (json->jsexpr @T{ [] }) => '() + (json->jsexpr @T{ [1,[2],3] }) => '(1 (2) 3) + (json->jsexpr @T{ [ 1 , [ 2 ] , 3 ] }) => '(1 (2) 3) + (json->jsexpr @T{ [true, false, null] }) => '(#t #f #\null) + (json->jsexpr @T{ {} }) => '#hasheq() + (json->jsexpr @T{ {"x":1} }) => '#hasheq([x . 1]) + (json->jsexpr @T{ {"x":1,"y":2} }) => '#hasheq([x . 1] [y . 2]) + )) + +(test do (pred-tests) + do (print-tests) + do (parse-tests)) diff --git a/collects/meta/props b/collects/meta/props index 0222410625..0910d3c43e 100755 --- a/collects/meta/props +++ b/collects/meta/props @@ -972,6 +972,7 @@ path/s is either such a string or a list of them. "collects/icons/private/svg/render-png.rkt" drdr:command-line #f "collects/images" responsible (ntoronto) "collects/images/tests/effects-tests.rkt" drdr:command-line #f +"collects/json" responsible (eli) "collects/lang" responsible (mflatt robby matthias) "collects/lang/htdp-langs.rkt" drdr:command-line (gracket-text "-t" *) "collects/lang/plt-pretty-big.rkt" drdr:command-line (gracket-text "-t" *)