1
0
Fork 0

- made a couple of names more consistent.

This commit is contained in:
cage 2022-12-17 20:31:59 +01:00
parent 53379fdd37
commit 87e0a3620c
3 changed files with 28 additions and 28 deletions

View File

@ -256,12 +256,12 @@
(with-output-to-string (stream) (with-output-to-string (stream)
(yason:with-output (stream) (yason:with-output (stream)
(let ((yason:*list-encoder* #'yason:encode-alist)) (let ((yason:*list-encoder* #'yason:encode-alist))
(yason:encode-alist (render-flat payload))))))) (yason:encode-alist (render-as-list payload)))))))
(defmethod jsonify ((object rpc-request)) (defmethod jsonify ((object rpc-request))
(with-output-to-string (stream) (with-output-to-string (stream)
(let ((yason:*list-encoder* #'yason:encode-alist)) (let ((yason:*list-encoder* #'yason:encode-alist))
(yason:encode (render-flat object) stream)))) (yason:encode (render-as-list object) stream))))
(defmethod jsonify ((object rpc-request-batch)) (defmethod jsonify ((object rpc-request-batch))
(with-output-to-string (stream) (with-output-to-string (stream)
@ -269,7 +269,7 @@
(yason:with-array () (yason:with-array ()
(loop for request in (requests object) do (loop for request in (requests object) do
(let ((yason:*list-encoder* #'yason:encode-alist)) (let ((yason:*list-encoder* #'yason:encode-alist))
(yason:encode-array-element (render-flat request)))))))) (yason:encode-array-element (render-as-list request))))))))
(defmethod jsonify ((object (eql nil))) (defmethod jsonify ((object (eql nil)))
nil) nil)
@ -280,20 +280,20 @@
(yason:with-output (stream) (yason:with-output (stream)
(yason:with-array () (yason:with-array ()
(loop for element in object do (loop for element in object do
(yason:encode-array-element (render-flat element)))))))) (yason:encode-array-element (render-as-list element))))))))
(defgeneric render-flat (object)) (defgeneric render-as-list (object))
(defmethod render-flat (object) (defmethod render-as-list (object)
object) object)
(defmethod render-flat ((object rpc-request-batch)) (defmethod render-as-list ((object rpc-request-batch))
(loop for i in (requests object) collect (render-flat i))) (loop for i in (requests object) collect (render-as-list i)))
(defmethod render-flat ((object rpc-response)) (defmethod render-as-list ((object rpc-response))
(payload object)) (payload object))
(defmethod render-flat ((object rpc-request)) (defmethod render-as-list ((object rpc-request))
(with-accessors ((id id) (with-accessors ((id id)
(function-id function-id) (function-id function-id)
(params params)) object (params params)) object

View File

@ -14,9 +14,9 @@
;; You should have received a copy of the GNU General Public License ;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :jsonrpc2-tests) (in-package :json-rpc2-tests)
(defsuite jsonrpc-suite (all-suite)) (defsuite json-rpc2-suite (all-suite))
(defun dummy-update (&rest params) (defun dummy-update (&rest params)
(mapcar #'1+ params)) (mapcar #'1+ params))
@ -37,7 +37,7 @@
(register-function "notify_hello" '+ (list (cons "values0" 0))) (register-function "notify_hello" '+ (list (cons "values0" 0)))
,@body)) ,@body))
(deftest test-simple (jsonrpc-suite) (deftest test-simple (json-rpc2-suite)
(prepare-rpc (prepare-rpc
(assert-equality #'string= (assert-equality #'string=
"{\"jsonrpc\":\"2.0\",\"result\":30,\"id\":1}" "{\"jsonrpc\":\"2.0\",\"result\":30,\"id\":1}"
@ -55,24 +55,24 @@
(assert-equality #'string= expected-req json-req) (assert-equality #'string= expected-req json-req)
(assert-equality #'string= expected-response json-resp)))) (assert-equality #'string= expected-response json-resp))))
(deftest test-sub-positional (jsonrpc-suite) (deftest test-sub-positional (json-rpc2-suite)
(transaction-test (make-request "subtract" 1 42 23) (transaction-test (make-request "subtract" 1 42 23)
"{\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":[42,23],\"id\":1}" "{\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":[42,23],\"id\":1}"
"{\"jsonrpc\":\"2.0\",\"result\":19,\"id\":1}")) "{\"jsonrpc\":\"2.0\",\"result\":19,\"id\":1}"))
(deftest test-sub-positional-2 (jsonrpc-suite) (deftest test-sub-positional-2 (json-rpc2-suite)
(transaction-test (make-request "subtract" 2 23 42) (transaction-test (make-request "subtract" 2 23 42)
"{\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":[23,42],\"id\":2}" "{\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":[23,42],\"id\":2}"
"{\"jsonrpc\":\"2.0\",\"result\":-19,\"id\":2}")) "{\"jsonrpc\":\"2.0\",\"result\":-19,\"id\":2}"))
(deftest test-sub-named (jsonrpc-suite) (deftest test-sub-named (json-rpc2-suite)
(transaction-test (make-request "subtract" 3 (cons "subtrahend" 23) (transaction-test (make-request "subtract" 3 (cons "subtrahend" 23)
(cons "minuend" 42)) (cons "minuend" 42))
(strcat "{\"jsonrpc\":\"2.0\",\"method\":\"subtract\"," (strcat "{\"jsonrpc\":\"2.0\",\"method\":\"subtract\","
"\"params\":{\"subtrahend\":23,\"minuend\":42},\"id\":3}") "\"params\":{\"subtrahend\":23,\"minuend\":42},\"id\":3}")
"{\"jsonrpc\":\"2.0\",\"result\":19,\"id\":3}")) "{\"jsonrpc\":\"2.0\",\"result\":19,\"id\":3}"))
(deftest test-sub-named-2 (jsonrpc-suite) (deftest test-sub-named-2 (json-rpc2-suite)
(transaction-test (make-request "subtract" 4 (transaction-test (make-request "subtract" 4
(cons "minuend" 42) (cons "minuend" 42)
(cons "subtrahend" 23)) (cons "subtrahend" 23))
@ -80,19 +80,19 @@
"\"params\":{\"minuend\":42,\"subtrahend\":23},\"id\":4}") "\"params\":{\"minuend\":42,\"subtrahend\":23},\"id\":4}")
"{\"jsonrpc\":\"2.0\",\"result\":19,\"id\":4}")) "{\"jsonrpc\":\"2.0\",\"result\":19,\"id\":4}"))
(deftest test-notifications (jsonrpc-suite) (deftest test-notifications (json-rpc2-suite)
(transaction-test (make-notification* "update" '(1 2 3 4 5)) (transaction-test (make-notification* "update" '(1 2 3 4 5))
"{\"jsonrpc\":\"2.0\",\"method\":\"update\",\"params\":[1,2,3,4,5]}" "{\"jsonrpc\":\"2.0\",\"method\":\"update\",\"params\":[1,2,3,4,5]}"
nil)) nil))
(deftest test-non-existent-method (jsonrpc-suite) (deftest test-non-existent-method (json-rpc2-suite)
(transaction-test (make-request "foobar" 1) (transaction-test (make-request "foobar" 1)
"{\"jsonrpc\":\"2.0\",\"method\":\"foobar\",\"id\":1}" "{\"jsonrpc\":\"2.0\",\"method\":\"foobar\",\"id\":1}"
(strcat "{\"jsonrpc\":\"2.0\"," (strcat "{\"jsonrpc\":\"2.0\","
"\"error\":{\"code\":-32601," "\"error\":{\"code\":-32601,"
"\"message\":\"Method not found: \\\"foobar\\\"\"},\"id\":1}"))) "\"message\":\"Method not found: \\\"foobar\\\"\"},\"id\":1}")))
(deftest test-invalid-json (jsonrpc-suite) (deftest test-invalid-json (json-rpc2-suite)
(let* ((json-req "{\"jsonrpc\": \"2.0\", \"method\": \"foobar, \"params\": \"bar\", \"baz]") (let* ((json-req "{\"jsonrpc\": \"2.0\", \"method\": \"foobar, \"params\": \"bar\", \"baz]")
(json-resp (jsonify (elaborate-request json-req)))) (json-resp (jsonify (elaborate-request json-req))))
(assert-true (assert-true
@ -100,7 +100,7 @@
(strcat "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32700," (strcat "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32700,"
"\"message\":\"Parse error\"},\"id\":null}"))))) "\"message\":\"Parse error\"},\"id\":null}")))))
(deftest test-invalid-request (jsonrpc-suite) (deftest test-invalid-request (json-rpc2-suite)
(let* ((json-req "{\"jsonrpc\": \"2.0\", \"method\": 1, \"params\": \"bar\"}") (let* ((json-req "{\"jsonrpc\": \"2.0\", \"method\": 1, \"params\": \"bar\"}")
(json-resp (jsonify (elaborate-request json-req)))) (json-resp (jsonify (elaborate-request json-req))))
(assert-true (assert-true
@ -108,7 +108,7 @@
(strcat "{\"jsonrpc\":\"2.0\",\"error\":" (strcat "{\"jsonrpc\":\"2.0\",\"error\":"
"{\"code\":-32600,\"message\":\"Invalid Request\"},\"id\":null}"))))) "{\"code\":-32600,\"message\":\"Invalid Request\"},\"id\":null}")))))
(deftest test-batch (jsonrpc-suite) (deftest test-batch (json-rpc2-suite)
(prepare-rpc (prepare-rpc
(let ((req (make-batch (make-request "add" (let ((req (make-batch (make-request "add"
2 2
@ -126,7 +126,7 @@
expected expected
(jsonify (elaborate-request (jsonify req))))))) (jsonify (elaborate-request (jsonify req)))))))
(deftest test-batch-json-invalid (jsonrpc-suite) (deftest test-batch-json-invalid (json-rpc2-suite)
(let* ((json-req (strcat "[" (let* ((json-req (strcat "["
"{\"jsonrpc\": \"2.0\", \"method\": \"sum\", \"params\":" "{\"jsonrpc\": \"2.0\", \"method\": \"sum\", \"params\":"
"[1,2,4], \"id\": \"1\"}," "[1,2,4], \"id\": \"1\"},"
@ -138,7 +138,7 @@
(strcat "{\"jsonrpc\":\"2.0\",\"error\":" (strcat "{\"jsonrpc\":\"2.0\",\"error\":"
"{\"code\":-32700,\"message\":\"Parse error\"},\"id\":null}"))))) "{\"code\":-32700,\"message\":\"Parse error\"},\"id\":null}")))))
(deftest test-batch-empty-array (jsonrpc-suite) (deftest test-batch-empty-array (json-rpc2-suite)
(let* ((json-req "[]") (let* ((json-req "[]")
(json-resp (jsonify (elaborate-request json-req)))) (json-resp (jsonify (elaborate-request json-req))))
(assert-true (assert-true
@ -146,7 +146,7 @@
(strcat "{\"jsonrpc\":\"2.0\",\"error\":" (strcat "{\"jsonrpc\":\"2.0\",\"error\":"
"{\"code\":-32600,\"message\":\"Invalid Request\"},\"id\":null}"))))) "{\"code\":-32600,\"message\":\"Invalid Request\"},\"id\":null}")))))
(deftest test-batch-invalid (jsonrpc-suite) (deftest test-batch-invalid (json-rpc2-suite)
(let* ((json-req "[1]") (let* ((json-req "[1]")
(json-resp (jsonify (elaborate-request json-req)))) (json-resp (jsonify (elaborate-request json-req))))
(assert-true (assert-true
@ -156,7 +156,7 @@
"{\"code\":-32600,\"message\":\"Invalid Request\"},\"id\":null}" "{\"code\":-32600,\"message\":\"Invalid Request\"},\"id\":null}"
"]"))))) "]")))))
(deftest test-batch-invalid-2 (jsonrpc-suite) (deftest test-batch-invalid-2 (json-rpc2-suite)
(let* ((json-req "[1, 2, 3]") (let* ((json-req "[1, 2, 3]")
(json-resp (jsonify (elaborate-request json-req)))) (json-resp (jsonify (elaborate-request json-req))))
(assert-true (assert-true
@ -170,7 +170,7 @@
"-32600,\"message\":\"Invalid Request\"},\"id\":null}" "-32600,\"message\":\"Invalid Request\"},\"id\":null}"
"]"))))) "]")))))
(deftest test-batch-notification (jsonrpc-suite) (deftest test-batch-notification (json-rpc2-suite)
(transaction-test (make-batch (make-notification "notify_sum" 1 2 4) (transaction-test (make-batch (make-notification "notify_sum" 1 2 4)
(make-notification "notify_hello" 7)) (make-notification "notify_hello" 7))
(strcat "[" (strcat "["

View File

@ -127,7 +127,7 @@
:all-tests) :all-tests)
(:export)) (:export))
(defpackage :jsonrpc2-tests (defpackage :json-rpc2-tests
(:use :cl (:use :cl
:clunit :clunit
:misc :misc