[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
- [elpa] master cbd3352 55/60: Add parsec-lookahead, (continued)
- [elpa] master cbd3352 55/60: Add parsec-lookahead, Junpeng Qiu, 2016/10/25
- [elpa] master a951fbe 41/60: Unify tag names, Junpeng Qiu, 2016/10/25
- [elpa] master dfb3af0 60/60: Add 'packages/parsec/' from commit '8f0c266d8b9b0ee5fcf9b80c518644b2849ff3b3', Junpeng Qiu, 2016/10/25
- [elpa] master 6cc3100 07/60: Fix indentations, Junpeng Qiu, 2016/10/25
- [elpa] master d98e8c8 05/60: Add url-encoded string parser, Junpeng Qiu, 2016/10/25
- [elpa] master a268b9f 08/60: Add more APIs, Junpeng Qiu, 2016/10/25
- [elpa] master 13637e1 15/60: Rename parsec-do-parse to parsec-with-input, Junpeng Qiu, 2016/10/25
- [elpa] master ba23b01 19/60: Add more APIs, Junpeng Qiu, 2016/10/25
- [elpa] master f3ce070 09/60: Add simple scheme parser, Junpeng Qiu, 2016/10/25
- [elpa] master 9bc1d77 28/60: Move examples to under sub-directory, Junpeng Qiu, 2016/10/25
- [elpa] master 52f1886 33/60: Update pjson,
Junpeng Qiu <=
- [elpa] master 7e65db0 51/60: Merge pull request #1 from tarsius/master, Junpeng Qiu, 2016/10/25
- [elpa] master 311a5ca 49/60: Fix typo, Junpeng Qiu, 2016/10/25
- [elpa] master e6d5f38 46/60: Update the comment in source file, Junpeng Qiu, 2016/10/25
- [elpa] master 8c22dcb 39/60: Add :group example, Junpeng Qiu, 2016/10/25
- [elpa] master a45d8f4 03/60: Error propagation to pl-until, Junpeng Qiu, 2016/10/25