emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 52f1886 33/60: Update pjson


From: Junpeng Qiu
Subject: [elpa] master 52f1886 33/60: Update pjson
Date: Tue, 25 Oct 2016 17:45:14 +0000 (UTC)

branch: master
commit 52f188648758978ba57c17818dbbd9496fe1acd5
Author: Junpeng Qiu <address@hidden>
Commit: Junpeng Qiu <address@hidden>

    Update pjson
---
 examples/pjson-tests.el |  102 +++++++++++++++++++++++++++++++++++++++++++++++
 examples/pjson.el       |   22 +---------
 2 files changed, 104 insertions(+), 20 deletions(-)

diff --git a/examples/pjson-tests.el b/examples/pjson-tests.el
new file mode 100644
index 0000000..6360152
--- /dev/null
+++ b/examples/pjson-tests.el
@@ -0,0 +1,102 @@
+;;; pjson-tests.el --- Test for parsec json parser   -*- lexical-binding: t; 
-*-
+
+;; Copyright (C) 2016  Junpeng Qiu
+
+;; Author: Junpeng Qiu <address@hidden>
+;; Keywords:
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'ert)
+(require 'pjson)
+
+(ert-deftest test-pjson-number ()
+  (should
+   (equal
+    (parsec-with-input "123"
+      (pjson-number))
+    123)))
+
+(ert-deftest test-pjson-boolean ()
+  (should
+   (equal
+    (parsec-with-input "false"
+      (pjson-boolean))
+    nil)))
+
+(ert-deftest test-pjson-null ()
+  (should
+   (equal
+    (parsec-with-input "null"
+      (pjson-null))
+    nil)))
+
+(ert-deftest test-pjson-array ()
+  (should
+   (equal
+    (parsec-with-input "[1,true,1,\"abc\",[1],null)"
+      (pjson-array))
+    (parsec-error-new-2 "]" ")")))
+  (should
+   (equal
+    (parsec-with-input "[1,true,1,\"abc\",[1],null]"
+      (pjson-array))
+    (vector 1 t 1 "abc"
+            (vector 1)
+            nil))))
+(ert-deftest test-pjson-string ()
+  (should
+   (equal
+    (parsec-with-input "\"asdf\""
+      (pjson-string))
+    "asdf")))
+
+(ert-deftest test-pjson-object ()
+  (should
+   (equal
+    (parsec-with-input "{\"a\" :1, \"b\":2, \"c\":[1,true] }"
+      (pjson-object))
+    '(("a" . 1)
+      ("b" . 2)
+      ("c" .
+       [1 t])))))
+
+(ert-deftest test-pjson-jvalue ()
+  (should
+   (equal
+    (parsec-with-input "[false]" (pjson-jvalue))
+    (vector nil))))
+
+(ert-deftest test-pjson-parse ()
+  (should
+   (equal
+    (pjson-parse "{\"a\" :1, \"b\":2, \"c\":[1,{\"d\":null}]}")
+    '(("a" . 1)
+      ("b" . 2)
+      ("c" .
+       [1
+        (("d"))]))))
+  (should
+   (equal
+    (pjson-parse  "{\"a\" :1, \"b\":2, [{ \"c\":[1,true] }]}")
+    (parsec-error-new-2 "\"" "["))))
+
+(provide 'pjson-tests)
+;;; pjson-tests.el ends here
diff --git a/examples/pjson.el b/examples/pjson.el
index 48b4589..be3e9c6 100644
--- a/examples/pjson.el
+++ b/examples/pjson.el
@@ -20,7 +20,7 @@
 
 ;;; Commentary:
 
-;;
+;; Ref: 
https://hackage.haskell.org/package/json-0.9.1/docs/src/Text-JSON-Parsec.html
 
 ;;; Code:
 
@@ -80,7 +80,7 @@
 (defun pjson-char ()
   (parsec-or
    (parsec-and (parsec-ch ?\\) (pjson-esc))
-   (parsec-re "[^\"\\]")))
+   (parsec-none-of ?\" ?\\)))
 
 (defun pjson-esc ()
   (parsec-or
@@ -120,23 +120,5 @@
   (parsec-with-input input
     (pjson-object)))
 
-(parsec-with-input "123"
-  (pjson-number))
-(parsec-with-input "\"asdf\""
-  (pjson-string))
-(parsec-with-input "false"
-  (pjson-boolean))
-(parsec-with-input "[1,true,1,\"abc\",[1],null)"
-  (pjson-array))
-(message "%s" (parsec-msg-get (parsec-with-input "fallls"
-                                (pjson-jvalue))))
-(parsec-with-input "{\"a\" :1, \"b\":2, \"c\":[1,true] }"
-  (pjson-object))
-
-(pjson-parse  "{\"a\" :1, \"b\":2, [{ \"c\":[1,true] }]}")
-(json-read-from-string  "{\"a\" :1, \"b\":2, [{ \"c\":[1,true] }]}")
-(pjson-parse    "{\"a\" :1, \"b\":2, \"c\":[1,{\"d\":null}]}")
-(json-read-from-string  "{\"a\" :1, \"b\":2, \"c\":[1,{\"d\":null}]}")
-
 (provide 'pjson)
 ;;; pjson.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]