(ert-deftest test-json-plist-to-alist ()
(should (equal (json--plist-to-alist '()) '()))
- (should (equal (json--plist-to-alist '(:a 1)) '((:a . 1))))
+ (should (equal (json--plist-to-alist '(:a 1)) '((a . 1))))
+ (let ((json-key-type 'keyword))
+ (should (equal (json--plist-to-alist '(:a 1)) '((:a . 1)))))
(should (equal (json--plist-to-alist '(:a 1 :b 2 :c 3))
- '((:a . 1) (:b . 2) (:c . 3)))))
+ '((a . 1) (b . 2) (c . 3)))))
(ert-deftest test-json-advance ()
(json-tests--with-temp-buffer "{ \"a\": 1 }"
@@ -177,9 +179,16 @@ Point is moved to beginning of the buffer."
"\"\\nasdфыв\\u001f\u007ffgh\\t\"")))
(ert-deftest test-json-encode-key ()
- (should (equal (json-encode-key "foo") "\"foo\""))
- (should (equal (json-encode-key 'foo) "\"foo\""))
- (should (equal (json-encode-key :foo) "\"foo\""))
+ (let ((json-key-type 'string))
+ (should (equal (json-encode-key "foo") "\"foo\""))
+ (should-error (json-encode-key t) :type 'json-key-format))
+ (let ((json-key-type 'symbol))
+ (should (equal (json-encode-key 'foo) "\"foo\""))
+ (should (equal (json-encode-key t) "\"t\""))
+ (should (equal (json-encode-key :t) "\":t\"")))
+ (let ((json-key-type 'keyword))
+ (should (equal (json-encode-key :foo) "\"foo\""))
+ (should-error (json-encode-key t) :type 'json-key-format))
(should-error (json-encode-key 5) :type 'json-key-format)
(should-error (json-encode-key ["foo"]) :type 'json-key-format)
(should-error (json-encode-key '("foo")) :type 'json-key-format))
@@ -238,9 +247,9 @@ Point is moved to beginning of the buffer."
(let ((hash-table (make-hash-table))
(json-encoding-object-sort-predicate 'string<)
(json-encoding-pretty-print nil))
- (puthash :a 1 hash-table)
- (puthash :b 2 hash-table)
- (puthash :c 3 hash-table)
+ (puthash "a" 1 hash-table)
+ (puthash "b" 2 hash-table)
+ (puthash "c" 3 hash-table)
(should (equal (json-encode hash-table)
"{\"a\":1,\"b\":2,\"c\":3}"))))
@@ -261,7 +270,7 @@ Point is moved to beginning of the buffer."
(should (equal (json-encode plist) "{\"a\":1,\"b\":2,\"c\":3}"))))
(ert-deftest test-json-encode-alist-with-sort-predicate ()
- (let ((alist '((:c . 3) (:a . 1) (:b . 2)))
+ (let ((alist '((c . 3) (a . 1) (b . 2)))
(json-encoding-object-sort-predicate 'string<)
(json-encoding-pretty-print nil))
(should (equal (json-encode alist) "{\"a\":1,\"b\":2,\"c\":3}"))))
@@ -270,7 +279,7 @@ Point is moved to beginning of the buffer."
(let ((json-encoding-pretty-print nil))
(should (equal (json-encode-list '(:a 1 :b 2))
"{\"a\":1,\"b\":2}"))
- (should (equal (json-encode-list '((:a . 1) (:b . 2)))
+ (should (equal (json-encode-list '((a . 1) (b . 2)))
"{\"a\":1,\"b\":2}"))
(should (equal (json-encode-list '(1 2 3 4)) "[1,2,3,4]"))))