From 87e0a3620c6e18e411fe698cf7583b24cd0d3b3c Mon Sep 17 00:00:00 2001 From: cage Date: Sat, 17 Dec 2022 20:31:59 +0100 Subject: [PATCH] - made a couple of names more consistent. --- src/json-rpc2.lisp | 20 ++++++++++---------- src/tests/jsonrpc2-tests.lisp | 34 +++++++++++++++++----------------- src/tests/package.lisp | 2 +- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/json-rpc2.lisp b/src/json-rpc2.lisp index 21d4680..1dc3302 100644 --- a/src/json-rpc2.lisp +++ b/src/json-rpc2.lisp @@ -256,12 +256,12 @@ (with-output-to-string (stream) (yason:with-output (stream) (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)) (with-output-to-string (stream) (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)) (with-output-to-string (stream) @@ -269,7 +269,7 @@ (yason:with-array () (loop for request in (requests object) do (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))) nil) @@ -280,20 +280,20 @@ (yason:with-output (stream) (yason:with-array () (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) -(defmethod render-flat ((object rpc-request-batch)) - (loop for i in (requests object) collect (render-flat i))) +(defmethod render-as-list ((object rpc-request-batch)) + (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)) -(defmethod render-flat ((object rpc-request)) +(defmethod render-as-list ((object rpc-request)) (with-accessors ((id id) (function-id function-id) (params params)) object diff --git a/src/tests/jsonrpc2-tests.lisp b/src/tests/jsonrpc2-tests.lisp index 5eaeee5..d9d97e4 100644 --- a/src/tests/jsonrpc2-tests.lisp +++ b/src/tests/jsonrpc2-tests.lisp @@ -14,9 +14,9 @@ ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . -(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) (mapcar #'1+ params)) @@ -37,7 +37,7 @@ (register-function "notify_hello" '+ (list (cons "values0" 0))) ,@body)) -(deftest test-simple (jsonrpc-suite) +(deftest test-simple (json-rpc2-suite) (prepare-rpc (assert-equality #'string= "{\"jsonrpc\":\"2.0\",\"result\":30,\"id\":1}" @@ -55,24 +55,24 @@ (assert-equality #'string= expected-req json-req) (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) "{\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":[42,23],\"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) "{\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":[23,42],\"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) (cons "minuend" 42)) (strcat "{\"jsonrpc\":\"2.0\",\"method\":\"subtract\"," "\"params\":{\"subtrahend\":23,\"minuend\":42},\"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 (cons "minuend" 42) (cons "subtrahend" 23)) @@ -80,19 +80,19 @@ "\"params\":{\"minuend\":42,\"subtrahend\":23},\"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)) "{\"jsonrpc\":\"2.0\",\"method\":\"update\",\"params\":[1,2,3,4,5]}" nil)) -(deftest test-non-existent-method (jsonrpc-suite) +(deftest test-non-existent-method (json-rpc2-suite) (transaction-test (make-request "foobar" 1) "{\"jsonrpc\":\"2.0\",\"method\":\"foobar\",\"id\":1}" (strcat "{\"jsonrpc\":\"2.0\"," "\"error\":{\"code\":-32601," "\"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]") (json-resp (jsonify (elaborate-request json-req)))) (assert-true @@ -100,7 +100,7 @@ (strcat "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32700," "\"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\"}") (json-resp (jsonify (elaborate-request json-req)))) (assert-true @@ -108,7 +108,7 @@ (strcat "{\"jsonrpc\":\"2.0\",\"error\":" "{\"code\":-32600,\"message\":\"Invalid Request\"},\"id\":null}"))))) -(deftest test-batch (jsonrpc-suite) +(deftest test-batch (json-rpc2-suite) (prepare-rpc (let ((req (make-batch (make-request "add" 2 @@ -126,7 +126,7 @@ expected (jsonify (elaborate-request (jsonify req))))))) -(deftest test-batch-json-invalid (jsonrpc-suite) +(deftest test-batch-json-invalid (json-rpc2-suite) (let* ((json-req (strcat "[" "{\"jsonrpc\": \"2.0\", \"method\": \"sum\", \"params\":" "[1,2,4], \"id\": \"1\"}," @@ -138,7 +138,7 @@ (strcat "{\"jsonrpc\":\"2.0\",\"error\":" "{\"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 "[]") (json-resp (jsonify (elaborate-request json-req)))) (assert-true @@ -146,7 +146,7 @@ (strcat "{\"jsonrpc\":\"2.0\",\"error\":" "{\"code\":-32600,\"message\":\"Invalid Request\"},\"id\":null}"))))) -(deftest test-batch-invalid (jsonrpc-suite) +(deftest test-batch-invalid (json-rpc2-suite) (let* ((json-req "[1]") (json-resp (jsonify (elaborate-request json-req)))) (assert-true @@ -156,7 +156,7 @@ "{\"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]") (json-resp (jsonify (elaborate-request json-req)))) (assert-true @@ -170,7 +170,7 @@ "-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) (make-notification "notify_hello" 7)) (strcat "[" diff --git a/src/tests/package.lisp b/src/tests/package.lisp index 83d4159..bdd3686 100644 --- a/src/tests/package.lisp +++ b/src/tests/package.lisp @@ -127,7 +127,7 @@ :all-tests) (:export)) -(defpackage :jsonrpc2-tests +(defpackage :json-rpc2-tests (:use :cl :clunit :misc