/usr/share/common-lisp/source/yason/test.lisp is in cl-yason 0.7.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | (defpackage :yason-test
(:use :cl :unit-test))
(in-package :yason-test)
(defparameter *basic-test-json-string* "[{\"foo\":1,\"bar\":[7,8,9]},2,3,4,[5,6,7],true,null]")
(defparameter *basic-test-json-string-indented* "
[
{\"foo\":1,
\"bar\":[7,8,9]
},
2, 3, 4, [5, 6, 7], true, null
]")
(defparameter *basic-test-json-dom* (list (alexandria:plist-hash-table
'("foo" 1 "bar" (7 8 9))
:test #'equal)
2 3 4
'(5 6 7)
t nil))
(deftest :yason "parser.basic"
(let ((result (yason:parse *basic-test-json-string*)))
(test-equal (first *basic-test-json-dom*) (first result) :test #'equalp)
(test-equal (rest *basic-test-json-dom*) (rest result))))
(deftest :yason "parser.basic-with-whitespace"
(let ((result (yason:parse *basic-test-json-string-indented*)))
(test-equal (first *basic-test-json-dom*) (first result) :test #'equalp)
(test-equal (rest *basic-test-json-dom*) (rest result))))
(deftest :yason "dom-encoder.basic"
(let ((result (yason:parse
(with-output-to-string (s)
(yason:encode *basic-test-json-dom* s)))))
(test-equal (first *basic-test-json-dom*) (first result) :test #'equalp)
(test-equal (rest *basic-test-json-dom*) (rest result))))
(defun whitespace-char-p (char)
(member char '(#\space #\tab #\return #\newline #\linefeed)))
(deftest :yason "dom-encoder.indentation"
(test-equal "[
1,
2,
3
]"
(with-output-to-string (s)
(yason:encode '(1 2 3) (yason:make-json-output-stream s :indent 10))))
(dolist (indentation-arg '(nil t 2 20))
(test-equal "[1,2,3]" (remove-if #'whitespace-char-p
(with-output-to-string (s)
(yason:encode '(1 2 3)
(yason:make-json-output-stream s :indent indentation-arg)))))))
(deftest :yason "stream-encoder.basic-array"
(test-equal "[0,1,2]"
(with-output-to-string (s)
(yason:with-output (s)
(yason:with-array ()
(dotimes (i 3)
(yason:encode-array-element i)))))))
(deftest :yason "stream-encoder.basic-object"
(test-equal "{\"hello\":\"hu hu\",\"harr\":[0,1,2]}"
(with-output-to-string (s)
(yason:with-output (s)
(yason:with-object ()
(yason:encode-object-element "hello" "hu hu")
(yason:with-object-element ("harr")
(yason:with-array ()
(dotimes (i 3)
(yason:encode-array-element i)))))))))
(defstruct user name age password)
(defmethod yason:encode ((user user) &optional (stream *standard-output*))
(yason:with-output (stream)
(yason:with-object ()
(yason:encode-object-element "name" (user-name user))
(yason:encode-object-element "age" (user-age user)))))
(deftest :yason "stream-encoder.application-struct"
(test-equal "[{\"name\":\"horst\",\"age\":27},{\"name\":\"uschi\",\"age\":28}]"
(with-output-to-string (s)
(yason:encode (list (make-user :name "horst" :age 27 :password "puppy")
(make-user :name "uschi" :age 28 :password "kitten"))
s))))
|