# HG changeset patch # User Steve Losh # Date 1598744577 14400 # Node ID 1633c31dbdda66710652a1c12177bcf141ce677d # Parent 2a95e54cdcac7cdea1dd9a54aae2cc27d83e9416 Test reading objects with an explicit class designator, not just t diff -r 2a95e54cdcac -r 1633c31dbdda .TODO.done --- a/.TODO.done Sat Aug 29 19:30:37 2020 -0400 +++ b/.TODO.done Sat Aug 29 19:42:57 2020 -0400 @@ -7,5 +7,6 @@ Add size and depth limits | id:ab9b49ec993f1e46c34b9d627549f41cad80609d Add fuzz tests against other implementations | id:cd53968480f72453ee820d65a180efe6da0fef71 Add extra key preservation | id:cfb63b37d87893083fc98477ec3d488fb909a984 +Test reading explicit types, not just t. | id:d2def699c46f12c02d49c01c869fc9b927bda72d Fix `Undefined function (SETF CCL:SLOT-DEFINITION-INITARGS)` in CCL | id:e834dd6749849e10669a643019337533e87f5cdd Add basic unit tests | id:ed372a368fce619ce8230043635de5258212f607 diff -r 2a95e54cdcac -r 1633c31dbdda TODO --- a/TODO Sat Aug 29 19:30:37 2020 -0400 +++ b/TODO Sat Aug 29 19:42:57 2020 -0400 @@ -2,6 +2,5 @@ Clean up error hierarchy | id:3d3efa4af649474151661a9d294080ab24e22ff7 Input wrapping. | id:7bc7f71a7dd85e13efde40b5ea2a5b6bfe13cf58 Fuzz against other JSON implementations | id:ccfe488e219c9454228a0510c61f8c59946e5875 -Test reading explicit types, not just t. | id:d2def699c46f12c02d49c01c869fc9b927bda72d Ensure slots are coalesced properly. | id:d800e6516a5bf5f8ce843f442956078e7a1b672e Add more MOP-based tests (including errors). | id:df727baeb41bad02c7d79b92f98c24c8a28ca772 diff -r 2a95e54cdcac -r 1633c31dbdda test/tests.lisp --- a/test/tests.lisp Sat Aug 29 19:30:37 2020 -0400 +++ b/test/tests.lisp Sat Aug 29 19:42:57 2020 -0400 @@ -93,88 +93,95 @@ ;;;; Basic Tests -------------------------------------------------------------- (defmacro define-basic-tests (name &rest clauses) `(define-test ,name - ,@(loop :for (object string) :in clauses :collect + ,@(loop :for (object class-designator string) :in clauses :collect (alexandria:once-only (object string) `(let ((,string (json ,string))) - ; Check that the entire string deserializes to the expected form. + ;; Check that the entire string deserializes to the expected form. (check-reads-one-object ,object ,string) - ; Check that we can roundtrip the form reliably. + ;; Check that we can roundtrip the form reliably. (check-roundtrips ,object) - ; Check that we can discard it safely. - (check-discards-one-object ,string)))))) + ;; Check that we can discard it safely. + (check-discards-one-object ,string) + ;; Check that we can read it with an explicit class designator, not just t. + (is (same ,object (jarl:read ',class-designator ,string))) + ;; Check that reading it with a wrong class designator signals an error. + ,@(loop :for wrong-class + :in (remove class-designator '(null keyword string vector hash-table number)) + :collect `(signals error (jarl:read ',wrong-class ,string)))))))) (define-basic-tests null - (nil "null")) + (nil null "null")) (define-basic-tests keywords - (:true "true") - (:false "false")) + (:true keyword "true") + (:false keyword "false")) (define-basic-tests integers - (0 "0") - (0 "-0") - (1 "1") - (-1 "-1") - (10 "10") - (-10 "-10") - (123456789123456789123456789 "123456789123456789123456789") - (-123456789123456789123456789 "-123456789123456789123456789")) + (0 number "0") + (0 number "-0") + (1 number "1") + (-1 number "-1") + (10 number "10") + (-10 number "-10") + (123456789123456789123456789 number "123456789123456789123456789") + (-123456789123456789123456789 number "-123456789123456789123456789")) (define-basic-tests floats - (0.0d0 "0e0") - (0.0d0 "0.0e0") - (-0.0d0 "-0.0e0") - (1.0d0 "1e0") - (1.0d0 "1e+0") - (1.0d0 "1e-0") - (1.2d0 "1.2e0") - (1.2d0 "1.2e+0") - (1.2d0 "1.2e-0") - (100.0d0 "1e2") - (100.0d0 "1e+2") - (123.4d0 "0.01234e+4") - (0.1234d0 "1.234e-1") - (1.234d-10 "1.234e-10")) + (0.0d0 number "0e0") + (0.0d0 number "0.0e0") + (-0.0d0 number "-0.0e0") + (1.0d0 number "1e0") + (1.0d0 number "1e+0") + (1.0d0 number "1e-0") + (1.2d0 number "1.2e0") + (1.2d0 number "1.2e+0") + (1.2d0 number "1.2e-0") + (100.0d0 number "1e2") + (100.0d0 number "1e+2") + (123.4d0 number "0.01234e+4") + (0.1234d0 number "1.234e-1") + (1.234d-10 number "1.234e-10")) (define-basic-tests strings - ("" "''") - (" " "' '") - (" " " ' ' ") - ("foo" "'foo'") - ("\"foo" "'\\'foo'") - ("f\\oo" "'f\\\\oo'") - ((format nil "foo~%bar") "'foo\\nbar'") - ((format nil "foo~Abar" #\tab) "'foo\\tbar'") - ((format nil "u: ~A" (code-char #x1234)) "'u: \\u1234'") - ((format nil "(~A)" (code-char #xCAFE)) "'(\\uCaFe)'") - ((format nil "~A~A" (code-char #xABCD) (code-char #xBEEF)) "'\\uABCD\\ubeef'")) + ("" string "''") + (" " string "' '") + (" " string " ' ' ") + ("foo" string "'foo'") + ("\"foo" string "'\\'foo'") + ("f\\oo" string "'f\\\\oo'") + ((format nil "foo~%bar") string "'foo\\nbar'") + ((format nil "foo~Abar" #\tab) string "'foo\\tbar'") + ((format nil "u: ~A" (code-char #x1234)) string "'u: \\u1234'") + ((format nil "(~A)" (code-char #xCAFE)) string "'(\\uCaFe)'") + ((format nil "~A~A" (code-char #xABCD) (code-char #xBEEF)) string "'\\uABCD\\ubeef'")) (define-basic-tests vectors - (#() "[]") - (#(1) "[1]") - (#(1 2 3) "[1,2,3]") - (#("meow" "wow") "['meow', 'wow']") - (#(1 nil "meow" :false -2 :true) "[1, null, 'meow', false, -2, true]") - (#(#(1 2) #() #(3.0d0 4.0d0 5.0d0)) "[[1, 2], [], [3e0, 40e-1, 0.5e1]]")) + (#() vector "[]") + (#(1) vector "[1]") + (#(1 2 3) vector "[1,2,3]") + (#("meow" "wow") vector "['meow', 'wow']") + (#(1 nil "meow" :false -2 :true) vector "[1, null, 'meow', false, -2, true]") + (#(#(1 2) #() #(3.0d0 4.0d0 5.0d0)) vector "[[1, 2], [], [3e0, 40e-1, 0.5e1]]")) (define-basic-tests objects - ((h) "{}") - ((h "foo" 1 "bar" 2) "{'foo': 1, 'bar': 2}") - ((h "foo" 1 "bar" 2) "{'bar': 2, 'foo': 1}") + ((h) hash-table "{}") + ((h "foo" 1 "bar" 2) hash-table "{'foo': 1, 'bar': 2}") + ((h "foo" 1 "bar" 2) hash-table "{'bar': 2, 'foo': 1}") ((h "foo" (h "a" nil "b" :false) "bar" :true "baz" (v (h) (h) (h))) + hash-table "{'foo': {'a': null, 'b': false}, 'bar': true, 'baz': [{},{},{}]}")) (define-basic-tests whitespace - (#() "[ ]") - ((h) " { }") - ((v (v) (h)) " [[ ] , { }]") - (#(1 2 3 4 5) " [ 1, 2 ,3, 4,5]")) + (#() vector "[ ]") + ((h) hash-table " { }") + ((v (v) (h)) vector " [[ ] , { }]") + (#(1 2 3 4 5) vector " [ 1, 2 ,3, 4,5]")) (define-test multiple-objects