--- 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