From e9a9410c26808cf71a52e8ae8fedcf54b7c71b88 Mon Sep 17 00:00:00 2001 From: kilianmh Date: Fri, 13 Oct 2023 23:56:11 +0200 Subject: [PATCH] Feat: Support integer type Now the type :integer is supported. Tests and documentation have been added. --- README.md | 1 + src/to-json.lisp | 4 ++++ src/to-lisp.lisp | 4 ++++ tests/encode-decode.lisp | 5 +++++ tests/tests.lisp | 6 ++++++ 5 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 7d216df..556544d 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Type | Remarks `:any` | Guesses the way to encode and decode the value `:string` | Enforces a string value `:number` | Enforces a number value +`:integer` | Enforces a integer value `:hash-table` | Enforces a hash table value `:vector` | Enforces a vector value `:list` | Enforces a list value diff --git a/src/to-json.lisp b/src/to-json.lisp index 709a946..89ccb9b 100644 --- a/src/to-json.lisp +++ b/src/to-json.lisp @@ -43,6 +43,10 @@ "Return the number VALUE" value) +(defmethod to-json-value ((value integer) (json-type (eql :integer))) + "Return the integer VALUE" + value) + (defmethod to-json-value ((value hash-table) (json-type (eql :hash-table))) "Return the hash-table VALUE" value) diff --git a/src/to-lisp.lisp b/src/to-lisp.lisp index d167442..59846c3 100644 --- a/src/to-lisp.lisp +++ b/src/to-lisp.lisp @@ -47,6 +47,10 @@ "Return the number VALUE" value) +(defmethod to-lisp-value ((value integer) (json-type (eql :integer))) + "Return the number VALUE" + value) + (defmethod to-lisp-value ((value hash-table) (json-type (eql :hash-table))) "Return the hash-table VALUE" value) diff --git a/tests/encode-decode.lisp b/tests/encode-decode.lisp index ad9b652..8e57740 100644 --- a/tests/encode-decode.lisp +++ b/tests/encode-decode.lisp @@ -38,6 +38,11 @@ (is (= (get-number obj) (get-number (obj-rt obj)))))) +(test integer + (for-all ((obj (gen-object))) + (is (= (get-integer obj) + (get-integer (obj-rt obj)))))) + (test hash-table (for-all ((obj (gen-object))) (is (equalp (get-hash-table obj) diff --git a/tests/tests.lisp b/tests/tests.lisp index 9fab66a..3cbb51c 100644 --- a/tests/tests.lisp +++ b/tests/tests.lisp @@ -31,6 +31,10 @@ :reader get-number :json-type :number :json-key "num") + (integer :initarg :integer + :reader get-integer + :json-type :integer + :json-key "int") (hash :initarg :hash-table :reader get-hash-table :json-type :hash-table @@ -119,6 +123,7 @@ (defun gen-object (&key (string (gen-string)) (number (gen-float)) + (integer (gen-integer)) (hash-table (gen-hash-table)) (obj-hash-table (gen-hash-table @@ -134,6 +139,7 @@ (make-instance 'test-class :string (funcall string) :number (funcall number) + :integer (funcall integer) :hash-table (funcall hash-table) :any-hash-table (funcall hash-table) :obj-hash-table (funcall obj-hash-table)