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

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

[nongnu] elpa/parseclj 6d40b39cec 082/185: Rename clj-edn to parseedn, k


From: ELPA Syncer
Subject: [nongnu] elpa/parseclj 6d40b39cec 082/185: Rename clj-edn to parseedn, keep it in this package for now.
Date: Tue, 28 Dec 2021 14:05:20 -0500 (EST)

branch: elpa/parseclj
commit 6d40b39cecc184d5ae7911812da1643a3e91306b
Author: Arne Brasseur <arne@arnebrasseur.net>
Commit: Arne Brasseur <arne@arnebrasseur.net>

    Rename clj-edn to parseedn, keep it in this package for now.
    
    This will need to be moved into its own package eventually.
---
 Cask                                       |   2 +-
 DESIGN.md                                  |  10 +-
 benchmark/speed-comparison.el              |   2 +-
 parseclj.el                                |   2 +-
 clj-edn.el => parseedn.el                  |  50 ++---
 test/clj-edn-el-parity-test.el             | 286 -----------------------------
 test/parseedn-el-parity-test.el            | 286 +++++++++++++++++++++++++++++
 test/{clj-edn-test.el => parseedn-test.el} |  40 ++--
 8 files changed, 339 insertions(+), 339 deletions(-)

diff --git a/Cask b/Cask
index add9a8b9d9..3238d1f31b 100644
--- a/Cask
+++ b/Cask
@@ -5,7 +5,7 @@
 (package-file "parseclj.el")
 
 (files "parseclj-lex.el"
-       "clj-edn.el"
+       "parseedn.el"
        "parseclj-ast.el")
 
 (development
diff --git a/DESIGN.md b/DESIGN.md
index 0b52f2401b..8e5b88acef 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -248,7 +248,7 @@ These are the choices that the edn.el library has made:
 
 ### Differences with EDN.el
 
-At the moment the `parseclj-edn-*` copy the parsing behavior of edn.el, 
*except* that the character literals `\newline`, `\return`, `\space`, and 
`\tab` are parsed to their character code (10, 13, 32, and 9 respectively), 
instead of to symbols.
+At the moment the `parseedn-*` copy the parsing behavior of edn.el, *except* 
that the character literals `\newline`, `\return`, `\space`, and `\tab` are 
parsed to their character code (10, 13, 32, and 9 respectively), instead of to 
symbols.
 
 ## AST
 
@@ -289,11 +289,11 @@ For each of these there can be the following functions
 Each of these have `-str` variant which instead works on strings. This yields 
a total potential API of:
 
 ```
-(defun parseclj-edn (&OPTIONAL tag-handler))
-(defun parseclj-edn-full (&OPTIONAL tag-handler))
+(defun parseedn (&OPTIONAL tag-handler))
+(defun parseedn-full (&OPTIONAL tag-handler))
 (defun clj-print-edn (edn))
-(defun parseclj-edn-str (string &OPTIONAL tag-handler))
-(defun parseclj-edn-full-str (string &OPTIONAL tag-handler))
+(defun parseedn-str (string &OPTIONAL tag-handler))
+(defun parseedn-full-str (string &OPTIONAL tag-handler))
 (defun clj-print-edn-str (edn))
 (defun parseclj-ast ())
 (defun parseclj-ast-full ())
diff --git a/benchmark/speed-comparison.el b/benchmark/speed-comparison.el
index 2529e782eb..12682112d2 100644
--- a/benchmark/speed-comparison.el
+++ b/benchmark/speed-comparison.el
@@ -14,7 +14,7 @@
       ;;(message fn)
       (with-current-buffer buff
         (let ((start (time-to-seconds (current-time))))
-          (clj-edn-read)
+          (parseedn-read)
           (setq clj-time (+ clj-time (- (time-to-seconds (current-time)) 
start))))
         (goto-char 1)
         (let ((start (time-to-seconds (current-time))))
diff --git a/parseclj.el b/parseclj.el
index 0baf76e635..9b8617c3c5 100644
--- a/parseclj.el
+++ b/parseclj.el
@@ -34,7 +34,7 @@
 (require 'a)
 
 (require 'parseclj-lex)
-(require 'clj-edn)
+(require 'parseedn)
 (require 'parseclj-ast)
 
 (defvar parseclj--leaf-tokens '(:whitespace
diff --git a/clj-edn.el b/parseedn.el
similarity index 76%
rename from clj-edn.el
rename to parseedn.el
index 393dd6783c..510d5536c7 100644
--- a/clj-edn.el
+++ b/parseedn.el
@@ -1,4 +1,4 @@
-;;; clj-edn.el --- EDN reader/writer              -*- lexical-binding: t; -*-
+;;; parseedn.el --- EDN reader/writer              -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 2017  Arne Brasseur
 
@@ -30,7 +30,7 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Reader
 
-(defvar clj-edn-default-tag-readers
+(defvar parseedn-default-tag-readers
   (a-list 'inst (lambda (s)
                   (cl-list* 'edn-inst (date-to-time s)))
           'uuid (lambda (s)
@@ -41,12 +41,12 @@ is not recommended you change this variable, as this 
globally
 changes the behavior of the EDN reader. Instead pass your own
 handlers as an optional argument to the reader functions.")
 
-(defun clj-edn-reduce-leaf (stack token)
+(defun parseedn-reduce-leaf (stack token)
   (if (member (parseclj-lex-token-type token) (list :whitespace :comment))
       stack
     (cons (parseclj--leaf-token-value token) stack)))
 
-(defun clj-edn-reduce-branch (tag-readers)
+(defun parseedn-reduce-branch (tag-readers)
   (lambda (stack opener-token children)
     (let ((token-type (parseclj-lex-token-type opener-token)))
       (if (member token-type '(:root :discard))
@@ -69,38 +69,38 @@ handlers as an optional argument to the reader functions.")
                    (funcall reader (car children)))))
          stack)))))
 
-(defun clj-edn-read (&optional tag-readers)
-  (parseclj-parse #'clj-edn-reduce-leaf
-                    (clj-edn-reduce-branch (a-merge 
clj-edn-default-tag-readers tag-readers))))
+(defun parseedn-read (&optional tag-readers)
+  (parseclj-parse #'parseedn-reduce-leaf
+                    (parseedn-reduce-branch (a-merge 
parseedn-default-tag-readers tag-readers))))
 
-(defun clj-edn-read-str (s &optional tag-readers)
+(defun parseedn-read-str (s &optional tag-readers)
   (with-temp-buffer
     (insert s)
     (goto-char 1)
-    (car (clj-edn-read tag-readers))))
+    (car (parseedn-read tag-readers))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Printer
 
 
-(defun clj-edn-print-seq (coll)
-  (clj-edn-print (elt coll 0))
+(defun parseedn-print-seq (coll)
+  (parseedn-print (elt coll 0))
   (let ((next (seq-drop coll 1)))
     (when (not (seq-empty-p next))
       (insert " ")
-      (clj-edn-print-seq next))))
+      (parseedn-print-seq next))))
 
-(defun clj-edn-print-kvs (map)
+(defun parseedn-print-kvs (map)
   (let ((keys (a-keys map)))
-    (clj-edn-print (car keys))
+    (parseedn-print (car keys))
     (insert " ")
-    (clj-edn-print (a-get map (car keys)))
+    (parseedn-print (a-get map (car keys)))
     (let ((next (cdr keys)))
       (when (not (seq-empty-p next))
         (insert ", ")
-        (clj-edn-print-kvs next)))))
+        (parseedn-print-kvs next)))))
 
-(defun clj-edn-print (datum)
+(defun parseedn-print (datum)
   (cond
    ((or (null datum) (numberp datum))
     (prin1 datum (current-buffer)))
@@ -124,22 +124,22 @@ handlers as an optional argument to the reader 
functions.")
    ((symbolp datum)
     (insert (symbol-name datum)))
 
-   ((vectorp datum) (insert "[") (clj-edn-print-seq datum) (insert "]"))
+   ((vectorp datum) (insert "[") (parseedn-print-seq datum) (insert "]"))
 
    ((consp datum)
     (cond
      ((eq 'edn-set (car datum))
-      (insert "#{") (clj-edn-print-seq (cadr datum)) (insert "}"))
-     (t (insert "(") (clj-edn-print-seq datum) (insert ")"))))
+      (insert "#{") (parseedn-print-seq (cadr datum)) (insert "}"))
+     (t (insert "(") (parseedn-print-seq datum) (insert ")"))))
 
    ((hash-table-p datum)
-    (insert "{") (clj-edn-print-kvs datum) (insert "}"))))
+    (insert "{") (parseedn-print-kvs datum) (insert "}"))))
 
-(defun clj-edn-print-str (datum)
+(defun parseedn-print-str (datum)
   (with-temp-buffer
-    (clj-edn-print datum)
+    (parseedn-print datum)
     (buffer-substring-no-properties (point-min) (point-max))))
 
-(provide 'clj-edn)
+(provide 'parseedn)
 
-;;; clj-edn.el ends here
+;;; parseedn.el ends here
diff --git a/test/clj-edn-el-parity-test.el b/test/clj-edn-el-parity-test.el
deleted file mode 100644
index ea5243627d..0000000000
--- a/test/clj-edn-el-parity-test.el
+++ /dev/null
@@ -1,286 +0,0 @@
-;;; edn-el-parity.el --- Tests from edn.el
-
-;; Author: Lars Andersen <expez@expez.com>, Arne Brasseur 
<arne@arnebrasseur.net>
-
-;; Copyright (C) 2015  Lars Andersen
-
-;; This file is not part of GNU Emacs.
-
-;; This file 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, or (at your option)
-;; any later version.
-
-;; This file 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 GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
-
-;;; Commentary:
-
-;; These tests are copied verbatim from the edn.el source, and adapted to use
-;; our API. This way we assure that parseclj can act as a drop-in replacement
-;; for edn.el.
-
-;;; Code:
-
-(require 'ert)
-(require 'parseclj)
-(eval-when-compile (require 'subr-x)) ;; for things like hash-table-keys
-
-(ert-deftest whitespace ()
-  (should (null (clj-edn-read-str "")))
-  (should (null (clj-edn-read-str " ")))
-  (should (null (clj-edn-read-str "   ")))
-  (should (null (clj-edn-read-str "    ")))
-  (should (null (clj-edn-read-str "            ")))
-  (should (null (clj-edn-read-str ",")))
-  (should (null (clj-edn-read-str ",,,,")))
-  (should (null (clj-edn-read-str "      , ,\n")))
-  (should (null (clj-edn-read-str "\n ,,       ")))
-  (should (equal [a b c d] (clj-edn-read-str "[a ,,,,,, b,,,,,c ,d]"))))
-
-(ert-deftest symbols ()
-  :tags '(edn symbol)
-  (should (equal 'foo (clj-edn-read-str "foo")))
-  (should (equal 'foo\. (clj-edn-read-str "foo.")))
-  (should (equal '%foo\. (clj-edn-read-str "%foo.")))
-  (should (equal 'foo/bar (clj-edn-read-str "foo/bar")))
-  (equal 'some\#sort\#of\#symbol (clj-edn-read-str "some#sort#of#symbol"))
-  (equal 'truefalse (clj-edn-read-str "truefalse"))
-  (equal 'true. (clj-edn-read-str "true."))
-  (equal '/ (clj-edn-read-str "/"))
-  (should (equal '.true (clj-edn-read-str ".true")))
-  (should (equal 'some:sort:of:symbol (clj-edn-read-str 
"some:sort:of:symbol")))
-  (equal 'foo-bar (clj-edn-read-str "foo-bar"))
-  (should (equal '+some-symbol (clj-edn-read-str "+some-symbol")))
-  (should (equal '-symbol (clj-edn-read-str "-symbol"))))
-
-(ert-deftest booleans ()
-  :tags '(edn boolean)
-  (should (equal t (clj-edn-read-str "true")))
-  (should (equal nil (clj-edn-read-str "false "))))
-
-(ert-deftest characters ()
-  :tags '(edn characters)
-  (should (equal 97 (clj-edn-read-str "\\a")))
-  (should (equal 960 (clj-edn-read-str "\\u03C0")))
-  ;;(should (equal 'newline (clj-edn-read-str "\\newline")))
-  )
-
-(ert-deftest elision ()
-  :tags '(edn elision)
-  (should-not (clj-edn-read-str "#_foo"))
-  (should-not (clj-edn-read-str "#_ 123"))
-  (should-not (clj-edn-read-str "#_:foo"))
-  (should-not (clj-edn-read-str "#_ \\a"))
-  (should-not (clj-edn-read-str "#_
-\"foo\""))
-  (should-not (clj-edn-read-str "#_ (1 2 3)"))
-  (should (equal '(1 3) (clj-edn-read-str "(1 #_ 2 3)")))
-  (should (equal '[1 2 3 4] (clj-edn-read-str "[1 2 #_[4 5 6] 3 4]")))
-  (should (map-equal (make-seeded-hash-table :foo :bar)
-                     (clj-edn-read-str "{:foo #_elided :bar}")))
-  (should (equal '(edn-set (1 2 3 4))
-                 (clj-edn-read-str "#{1 2 #_[1 2 3] 3 #_ (1 2) 4}")))
-  (should (equal [a d] (clj-edn-read-str "[a #_ ;we are discarding what comes 
next
- c d]"))))
-
-(ert-deftest string ()
-  :tags '(edn string)
-  (should (equal "this is a string" (clj-edn-read-str "\"this is a string\"")))
-  (should (equal "this has an escaped \"quote in it"
-                 (clj-edn-read-str "\"this has an escaped \\\"quote in it\"")))
-  (should (equal "foo\tbar" (clj-edn-read-str "\"foo\\tbar\"")))
-  (should (equal "foo\nbar" (clj-edn-read-str "\"foo\\nbar\"")))
-  (should (equal "this is a string \\ that has an escaped backslash"
-                 (clj-edn-read-str "\"this is a string \\\\ that has an 
escaped backslash\"")))
-  (should (equal "[" (clj-edn-read-str "\"[\""))))
-
-(ert-deftest keywords ()
-  :tags '(edn keywords)
-  (should (equal :namespace\.of\.some\.length/keyword-name
-                 (clj-edn-read-str ":namespace.of.some.length/keyword-name")))
-  (should (equal :\#/\# (clj-edn-read-str ":#/#")))
-  (should (equal :\#/:a (clj-edn-read-str ":#/:a")))
-  (should (equal :\#foo (clj-edn-read-str ":#foo"))))
-
-(ert-deftest integers ()
-  :tags '(edn integers)
-  (should (= 0 (clj-edn-read-str "0")))
-  (should (= 0 (clj-edn-read-str "+0")))
-  (should (= 0 (clj-edn-read-str "-0")))
-  (should (= 100 (clj-edn-read-str "100")))
-  (should (= -100 (clj-edn-read-str "-100"))))
-
-(ert-deftest floats ()
-  :tags '(edn floats)
-  (should (= 12.32 (clj-edn-read-str "12.32")))
-  (should (= -12.32 (clj-edn-read-str "-12.32")))
-  (should (= 9923.23 (clj-edn-read-str "+9923.23")))
-  (should (= 4.5e+044 (clj-edn-read-str "45e+43")))
-  (should (= -4.5e-042 (clj-edn-read-str "-45e-43")))
-  (should (= 4.5e+044 (clj-edn-read-str "45E+43"))))
-
-(ert-deftest lists ()
-  :tags '(edn lists)
-  (should-not (clj-edn-read-str "()"))
-  (should (equal '(1 2 3) (clj-edn-read-str "( 1 2 3)")))
-  (should (equal '(12.1 ?a foo :bar) (clj-edn-read-str "(12.1 \\a foo :bar)")))
-  (should (equal '((:foo bar :bar 12)) (clj-edn-read-str "( (:foo bar :bar 
12))")))
-  (should (equal
-           '(defproject com\.thortech/data\.edn "0.1.0-SNAPSHOT")
-           (clj-edn-read-str "(defproject com.thortech/data.edn 
\"0.1.0-SNAPSHOT\")"))))
-
-(ert-deftest vectors ()
-  :tags '(edn vectors)
-  (should (equal [] (clj-edn-read-str "[]")))
-  (should (equal [] (clj-edn-read-str "[ ]")))
-  (should (equal '[1 2 3] (clj-edn-read-str "[ 1 2 3 ]")))
-  (should (equal '[12.1 ?a foo :bar] (clj-edn-read-str "[ 12.1 \\a foo 
:bar]")))
-  (should (equal '[[:foo bar :bar 12]] (clj-edn-read-str "[[:foo bar :bar 
12]]")))
-  (should (equal '[( :foo bar :bar 12 ) "foo"]
-                 (clj-edn-read-str "[(:foo bar :bar 12) \"foo\"]")))
-  (should (equal '[/ \. * ! _ \? $ % & = - +]
-                 (clj-edn-read-str "[/ . * ! _ ? $ % & = - +]")))
-  (should (equal
-           ;;[99 newline return space tab]
-           [99 10 13 32 9]
-           (clj-edn-read-str "[\\c \\newline \\return \\space \\tab]"))))
-
-(defun map-equal (m1 m2)
-  (and (and (hash-table-p m1) (hash-table-p m2))
-       (eq (hash-table-test m1) (hash-table-test m2))
-       (= (hash-table-count m1) (hash-table-count m2))
-       (equal (hash-table-keys m1) (hash-table-keys m2))
-       (equal (hash-table-values m1) (hash-table-values m2))))
-
-(defun make-seeded-hash-table (&rest keys-and-values)
-  (let ((m (make-hash-table :test #'equal)))
-    (while keys-and-values
-      (puthash (pop keys-and-values) (pop keys-and-values) m))
-    m))
-
-(ert-deftest maps ()
-  :tags '(edn maps)
-  (should (hash-table-p (clj-edn-read-str "{ }")))
-  (should (hash-table-p (clj-edn-read-str "{}")))
-  (should (map-equal (make-seeded-hash-table :foo :bar :baz :qux)
-                     (clj-edn-read-str "{ :foo :bar :baz :qux}")))
-  (should (map-equal (make-seeded-hash-table 1 "123" 'vector [1 2 3])
-                     (clj-edn-read-str "{ 1 \"123\" vector [1 2 3]}")))
-  (should (map-equal (make-seeded-hash-table [1 2 3] "some numbers")
-                     (clj-edn-read-str "{[1 2 3] \"some numbers\"}"))))
-
-(ert-deftest sets ()
-  :tags '(edn sets)
-  (should (eq 'edn-set (car (clj-edn-read-str "#{}"))))
-  (should (eq 'edn-set (car (clj-edn-read-str "#{ }"))))
-  (should (equal '(edn-set (1 2 3)) (clj-edn-read-str "#{1 2 3}")))
-  (should (equal '(edn-set (1 [1 2 3] 3)) (clj-edn-read-str "#{1 [1 2 3] 
3}"))))
-
-(ert-deftest comment ()
-  :tags '(edn comments)
-  (should-not (clj-edn-read-str ";nada"))
-  (should (equal 1 (clj-edn-read-str ";; comment
-1")))
-  (should (equal [1 2 3] (clj-edn-read-str "[1 2 ;comment to eol
-3]")))
-  (should (equal '[valid more items] (clj-edn-read-str "[valid;touching 
trailing comment
- more items]")))
-  (should (equal [valid vector more vector items] (clj-edn-read-str "[valid 
vector
- ;;comment in vector
- more vector items]"))))
-
-(defun test-val-passed-to-handler (val)
-  (should (listp val))
-  (should (= (length val) 2))
-  (should (= 1 (car val)))
-  1)
-
-(setq clj-edn-test-extra-handlers
-      (a-list
-       'my/type #'test-val-passed-to-handler
-       'my/other-type (lambda (val) 2)))
-
-(ert-deftest tags ()
-  :tags '(edn tags)
-  (should-error (clj-edn-read-str "#my/type value" 
clj-edn-test-extra-handlers))
-  (should (= 1 (clj-edn-read-str "#my/type (1 2)" 
clj-edn-test-extra-handlers)))
-  (should (= 2 (clj-edn-read-str "#my/other-type {:foo :bar}" 
clj-edn-test-extra-handlers)))
-  (should-error (clj-edn-read-str "#myapp/Person {:first \"Fred\" :last 
\"Mertz\"}")))
-
-(ert-deftest roundtrip ()
-  :tags '(edn roundtrip)
-  (let ((data [1 2 3 :foo (4 5) qux "quux"]))
-    (should (equal data (clj-edn-read-str (clj-edn-print-str data))))
-    (should (map-equal (make-seeded-hash-table :foo :bar)
-                       (clj-edn-read-str (clj-edn-print-str 
(make-seeded-hash-table :foo :bar)))))
-    (should (equal '(edn-set (1 2 3 [3 1.11]))
-                   (clj-edn-read-str (clj-edn-print-str '(edn-set (1 2 3 [3 
1.11]))))))))
-
-(ert-deftest inst ()
-  :tags '(edn inst)
-  (let* ((inst-str "#inst \"1985-04-12T23:20:50.52Z\"")
-         (inst (clj-edn-read-str inst-str))
-         (time (date-to-time "1985-04-12T23:20:50.52Z")))
-    (should (eq 'edn-inst (car inst)))
-    (should (equal time (cdr inst)))))
-
-(ert-deftest uuid ()
-  :tags '(edn uuid)
-  (let* ((str "f81d4fae-7dec-11d0-a765-00a0c91e6bf6")
-         (uuid (clj-edn-read-str (concat "#uuid \"" str "\""))))
-    (should (eq 'edn-uuid (car uuid)))))
-
-;; (ert-deftest invalid-edn ()
-;;   (should-error (clj-edn-read-str "///"))
-;;   (should-error (clj-edn-read-str "~cat"))
-;;   (should-error (clj-edn-read-str "foo/bar/baz/qux/quux"))
-;;   (should-error (clj-edn-read-str "#foo/"))
-;;   (should-error (clj-edn-read-str "foo/"))
-;;   (should-error (clj-edn-read-str ":foo/"))
-;;   (should-error (clj-edn-read-str "#/foo"))
-;;   (should-error (clj-edn-read-str "/symbol"))
-;;   (should-error (clj-edn-read-str ":/foo"))
-;;   (should-error (clj-edn-read-str "+5symbol"))
-;;   (should-error (clj-edn-read-str ".\\newline"))
-;;   (should-error (clj-edn-read-str "0cat"))
-;;   (should-error (clj-edn-read-str "-4cats"))
-;;   (should-error (clj-edn-read-str ".9"))
-;;   (should-error (clj-edn-read-str ":keyword/with/too/many/slashes"))
-;;   (should-error (clj-edn-read-str ":a.b.c/"))
-;;   (should-error (clj-edn-read-str "\\itstoolong"))
-;;   (should-error (clj-edn-read-str ":#/:"))
-;;   (should-error (clj-edn-read-str "/foo//"))
-;;   (should-error (clj-edn-read-str "///foo"))
-;;   (should-error (clj-edn-read-str ":{}"))
-;;   (should-error (clj-edn-read-str "//"))
-;;   (should-error (clj-edn-read-str "##"))
-;;   (should-error (clj-edn-read-str "::"))
-;;   (should-error (clj-edn-read-str "::a"))
-;;   (should-error (clj-edn-read-str ".5symbol"))
-;;   (should-error (clj-edn-read-str "{ \"foo\""))
-;;   (should-error (clj-edn-read-str "{ \"foo\" :bar"))
-;;   (should-error (clj-edn-read-str "{"))
-;;   (should-error (clj-edn-read-str ":{"))
-;;   (should-error (clj-edn-read-str "{{"))
-;;   (should-error (clj-edn-read-str "}"))
-;;   (should-error (clj-edn-read-str ":}"))
-;;   (should-error (clj-edn-read-str "}}"))
-;;   (should-error (clj-edn-read-str "#:foo"))
-;;   (should-error (clj-edn-read-str "\\newline."))
-;;   (should-error (clj-edn-read-str "\\newline0.1"))
-;;   (should-error (clj-edn-read-str "^"))
-;;   (should-error (clj-edn-read-str ":^"))
-;;   (should-error (clj-edn-read-str "_:^"))
-;;   (should-error (clj-edn-read-str "#{{[}}"))
-;;   (should-error (clj-edn-read-str "[}"))
-;;   (should-error (clj-edn-read-str "@cat")))
-
-;;; edn-el-parity-test.el ends here
diff --git a/test/parseedn-el-parity-test.el b/test/parseedn-el-parity-test.el
new file mode 100644
index 0000000000..c58641a4f3
--- /dev/null
+++ b/test/parseedn-el-parity-test.el
@@ -0,0 +1,286 @@
+;;; edn-el-parity.el --- Tests from edn.el
+
+;; Author: Lars Andersen <expez@expez.com>, Arne Brasseur 
<arne@arnebrasseur.net>
+
+;; Copyright (C) 2015  Lars Andersen
+
+;; This file is not part of GNU Emacs.
+
+;; This file 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, or (at your option)
+;; any later version.
+
+;; This file 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 GNU Emacs; see the file COPYING.  If not, write to
+;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;; These tests are copied verbatim from the edn.el source, and adapted to use
+;; our API. This way we assure that parseclj can act as a drop-in replacement
+;; for edn.el.
+
+;;; Code:
+
+(require 'ert)
+(require 'parseclj)
+(eval-when-compile (require 'subr-x)) ;; for things like hash-table-keys
+
+(ert-deftest whitespace ()
+  (should (null (parseedn-read-str "")))
+  (should (null (parseedn-read-str " ")))
+  (should (null (parseedn-read-str "   ")))
+  (should (null (parseedn-read-str "   ")))
+  (should (null (parseedn-read-str "           ")))
+  (should (null (parseedn-read-str ",")))
+  (should (null (parseedn-read-str ",,,,")))
+  (should (null (parseedn-read-str "     , ,\n")))
+  (should (null (parseedn-read-str "\n ,,      ")))
+  (should (equal [a b c d] (parseedn-read-str "[a ,,,,,, b,,,,,c ,d]"))))
+
+(ert-deftest symbols ()
+  :tags '(edn symbol)
+  (should (equal 'foo (parseedn-read-str "foo")))
+  (should (equal 'foo\. (parseedn-read-str "foo.")))
+  (should (equal '%foo\. (parseedn-read-str "%foo.")))
+  (should (equal 'foo/bar (parseedn-read-str "foo/bar")))
+  (equal 'some\#sort\#of\#symbol (parseedn-read-str "some#sort#of#symbol"))
+  (equal 'truefalse (parseedn-read-str "truefalse"))
+  (equal 'true. (parseedn-read-str "true."))
+  (equal '/ (parseedn-read-str "/"))
+  (should (equal '.true (parseedn-read-str ".true")))
+  (should (equal 'some:sort:of:symbol (parseedn-read-str 
"some:sort:of:symbol")))
+  (equal 'foo-bar (parseedn-read-str "foo-bar"))
+  (should (equal '+some-symbol (parseedn-read-str "+some-symbol")))
+  (should (equal '-symbol (parseedn-read-str "-symbol"))))
+
+(ert-deftest booleans ()
+  :tags '(edn boolean)
+  (should (equal t (parseedn-read-str "true")))
+  (should (equal nil (parseedn-read-str "false "))))
+
+(ert-deftest characters ()
+  :tags '(edn characters)
+  (should (equal 97 (parseedn-read-str "\\a")))
+  (should (equal 960 (parseedn-read-str "\\u03C0")))
+  ;;(should (equal 'newline (parseedn-read-str "\\newline")))
+  )
+
+(ert-deftest elision ()
+  :tags '(edn elision)
+  (should-not (parseedn-read-str "#_foo"))
+  (should-not (parseedn-read-str "#_ 123"))
+  (should-not (parseedn-read-str "#_:foo"))
+  (should-not (parseedn-read-str "#_ \\a"))
+  (should-not (parseedn-read-str "#_
+\"foo\""))
+  (should-not (parseedn-read-str "#_ (1 2 3)"))
+  (should (equal '(1 3) (parseedn-read-str "(1 #_ 2 3)")))
+  (should (equal '[1 2 3 4] (parseedn-read-str "[1 2 #_[4 5 6] 3 4]")))
+  (should (map-equal (make-seeded-hash-table :foo :bar)
+                     (parseedn-read-str "{:foo #_elided :bar}")))
+  (should (equal '(edn-set (1 2 3 4))
+                 (parseedn-read-str "#{1 2 #_[1 2 3] 3 #_ (1 2) 4}")))
+  (should (equal [a d] (parseedn-read-str "[a #_ ;we are discarding what comes 
next
+ c d]"))))
+
+(ert-deftest string ()
+  :tags '(edn string)
+  (should (equal "this is a string" (parseedn-read-str "\"this is a 
string\"")))
+  (should (equal "this has an escaped \"quote in it"
+                 (parseedn-read-str "\"this has an escaped \\\"quote in 
it\"")))
+  (should (equal "foo\tbar" (parseedn-read-str "\"foo\\tbar\"")))
+  (should (equal "foo\nbar" (parseedn-read-str "\"foo\\nbar\"")))
+  (should (equal "this is a string \\ that has an escaped backslash"
+                 (parseedn-read-str "\"this is a string \\\\ that has an 
escaped backslash\"")))
+  (should (equal "[" (parseedn-read-str "\"[\""))))
+
+(ert-deftest keywords ()
+  :tags '(edn keywords)
+  (should (equal :namespace\.of\.some\.length/keyword-name
+                 (parseedn-read-str ":namespace.of.some.length/keyword-name")))
+  (should (equal :\#/\# (parseedn-read-str ":#/#")))
+  (should (equal :\#/:a (parseedn-read-str ":#/:a")))
+  (should (equal :\#foo (parseedn-read-str ":#foo"))))
+
+(ert-deftest integers ()
+  :tags '(edn integers)
+  (should (= 0 (parseedn-read-str "0")))
+  (should (= 0 (parseedn-read-str "+0")))
+  (should (= 0 (parseedn-read-str "-0")))
+  (should (= 100 (parseedn-read-str "100")))
+  (should (= -100 (parseedn-read-str "-100"))))
+
+(ert-deftest floats ()
+  :tags '(edn floats)
+  (should (= 12.32 (parseedn-read-str "12.32")))
+  (should (= -12.32 (parseedn-read-str "-12.32")))
+  (should (= 9923.23 (parseedn-read-str "+9923.23")))
+  (should (= 4.5e+044 (parseedn-read-str "45e+43")))
+  (should (= -4.5e-042 (parseedn-read-str "-45e-43")))
+  (should (= 4.5e+044 (parseedn-read-str "45E+43"))))
+
+(ert-deftest lists ()
+  :tags '(edn lists)
+  (should-not (parseedn-read-str "()"))
+  (should (equal '(1 2 3) (parseedn-read-str "( 1 2 3)")))
+  (should (equal '(12.1 ?a foo :bar) (parseedn-read-str "(12.1 \\a foo 
:bar)")))
+  (should (equal '((:foo bar :bar 12)) (parseedn-read-str "( (:foo bar :bar 
12))")))
+  (should (equal
+           '(defproject com\.thortech/data\.edn "0.1.0-SNAPSHOT")
+           (parseedn-read-str "(defproject com.thortech/data.edn 
\"0.1.0-SNAPSHOT\")"))))
+
+(ert-deftest vectors ()
+  :tags '(edn vectors)
+  (should (equal [] (parseedn-read-str "[]")))
+  (should (equal [] (parseedn-read-str "[ ]")))
+  (should (equal '[1 2 3] (parseedn-read-str "[ 1 2 3 ]")))
+  (should (equal '[12.1 ?a foo :bar] (parseedn-read-str "[ 12.1 \\a foo 
:bar]")))
+  (should (equal '[[:foo bar :bar 12]] (parseedn-read-str "[[:foo bar :bar 
12]]")))
+  (should (equal '[( :foo bar :bar 12 ) "foo"]
+                 (parseedn-read-str "[(:foo bar :bar 12) \"foo\"]")))
+  (should (equal '[/ \. * ! _ \? $ % & = - +]
+                 (parseedn-read-str "[/ . * ! _ ? $ % & = - +]")))
+  (should (equal
+           ;;[99 newline return space tab]
+           [99 10 13 32 9]
+           (parseedn-read-str "[\\c \\newline \\return \\space \\tab]"))))
+
+(defun map-equal (m1 m2)
+  (and (and (hash-table-p m1) (hash-table-p m2))
+       (eq (hash-table-test m1) (hash-table-test m2))
+       (= (hash-table-count m1) (hash-table-count m2))
+       (equal (hash-table-keys m1) (hash-table-keys m2))
+       (equal (hash-table-values m1) (hash-table-values m2))))
+
+(defun make-seeded-hash-table (&rest keys-and-values)
+  (let ((m (make-hash-table :test #'equal)))
+    (while keys-and-values
+      (puthash (pop keys-and-values) (pop keys-and-values) m))
+    m))
+
+(ert-deftest maps ()
+  :tags '(edn maps)
+  (should (hash-table-p (parseedn-read-str "{ }")))
+  (should (hash-table-p (parseedn-read-str "{}")))
+  (should (map-equal (make-seeded-hash-table :foo :bar :baz :qux)
+                     (parseedn-read-str "{ :foo :bar :baz :qux}")))
+  (should (map-equal (make-seeded-hash-table 1 "123" 'vector [1 2 3])
+                     (parseedn-read-str "{ 1 \"123\" vector [1 2 3]}")))
+  (should (map-equal (make-seeded-hash-table [1 2 3] "some numbers")
+                     (parseedn-read-str "{[1 2 3] \"some numbers\"}"))))
+
+(ert-deftest sets ()
+  :tags '(edn sets)
+  (should (eq 'edn-set (car (parseedn-read-str "#{}"))))
+  (should (eq 'edn-set (car (parseedn-read-str "#{ }"))))
+  (should (equal '(edn-set (1 2 3)) (parseedn-read-str "#{1 2 3}")))
+  (should (equal '(edn-set (1 [1 2 3] 3)) (parseedn-read-str "#{1 [1 2 3] 
3}"))))
+
+(ert-deftest comment ()
+  :tags '(edn comments)
+  (should-not (parseedn-read-str ";nada"))
+  (should (equal 1 (parseedn-read-str ";; comment
+1")))
+  (should (equal [1 2 3] (parseedn-read-str "[1 2 ;comment to eol
+3]")))
+  (should (equal '[valid more items] (parseedn-read-str "[valid;touching 
trailing comment
+ more items]")))
+  (should (equal [valid vector more vector items] (parseedn-read-str "[valid 
vector
+ ;;comment in vector
+ more vector items]"))))
+
+(defun test-val-passed-to-handler (val)
+  (should (listp val))
+  (should (= (length val) 2))
+  (should (= 1 (car val)))
+  1)
+
+(setq parseedn-test-extra-handlers
+      (a-list
+       'my/type #'test-val-passed-to-handler
+       'my/other-type (lambda (val) 2)))
+
+(ert-deftest tags ()
+  :tags '(edn tags)
+  (should-error (parseedn-read-str "#my/type value" 
parseedn-test-extra-handlers))
+  (should (= 1 (parseedn-read-str "#my/type (1 2)" 
parseedn-test-extra-handlers)))
+  (should (= 2 (parseedn-read-str "#my/other-type {:foo :bar}" 
parseedn-test-extra-handlers)))
+  (should-error (parseedn-read-str "#myapp/Person {:first \"Fred\" :last 
\"Mertz\"}")))
+
+(ert-deftest roundtrip ()
+  :tags '(edn roundtrip)
+  (let ((data [1 2 3 :foo (4 5) qux "quux"]))
+    (should (equal data (parseedn-read-str (parseedn-print-str data))))
+    (should (map-equal (make-seeded-hash-table :foo :bar)
+                       (parseedn-read-str (parseedn-print-str 
(make-seeded-hash-table :foo :bar)))))
+    (should (equal '(edn-set (1 2 3 [3 1.11]))
+                   (parseedn-read-str (parseedn-print-str '(edn-set (1 2 3 [3 
1.11]))))))))
+
+(ert-deftest inst ()
+  :tags '(edn inst)
+  (let* ((inst-str "#inst \"1985-04-12T23:20:50.52Z\"")
+         (inst (parseedn-read-str inst-str))
+         (time (date-to-time "1985-04-12T23:20:50.52Z")))
+    (should (eq 'edn-inst (car inst)))
+    (should (equal time (cdr inst)))))
+
+(ert-deftest uuid ()
+  :tags '(edn uuid)
+  (let* ((str "f81d4fae-7dec-11d0-a765-00a0c91e6bf6")
+         (uuid (parseedn-read-str (concat "#uuid \"" str "\""))))
+    (should (eq 'edn-uuid (car uuid)))))
+
+;; (ert-deftest invalid-edn ()
+;;   (should-error (parseedn-read-str "///"))
+;;   (should-error (parseedn-read-str "~cat"))
+;;   (should-error (parseedn-read-str "foo/bar/baz/qux/quux"))
+;;   (should-error (parseedn-read-str "#foo/"))
+;;   (should-error (parseedn-read-str "foo/"))
+;;   (should-error (parseedn-read-str ":foo/"))
+;;   (should-error (parseedn-read-str "#/foo"))
+;;   (should-error (parseedn-read-str "/symbol"))
+;;   (should-error (parseedn-read-str ":/foo"))
+;;   (should-error (parseedn-read-str "+5symbol"))
+;;   (should-error (parseedn-read-str ".\\newline"))
+;;   (should-error (parseedn-read-str "0cat"))
+;;   (should-error (parseedn-read-str "-4cats"))
+;;   (should-error (parseedn-read-str ".9"))
+;;   (should-error (parseedn-read-str ":keyword/with/too/many/slashes"))
+;;   (should-error (parseedn-read-str ":a.b.c/"))
+;;   (should-error (parseedn-read-str "\\itstoolong"))
+;;   (should-error (parseedn-read-str ":#/:"))
+;;   (should-error (parseedn-read-str "/foo//"))
+;;   (should-error (parseedn-read-str "///foo"))
+;;   (should-error (parseedn-read-str ":{}"))
+;;   (should-error (parseedn-read-str "//"))
+;;   (should-error (parseedn-read-str "##"))
+;;   (should-error (parseedn-read-str "::"))
+;;   (should-error (parseedn-read-str "::a"))
+;;   (should-error (parseedn-read-str ".5symbol"))
+;;   (should-error (parseedn-read-str "{ \"foo\""))
+;;   (should-error (parseedn-read-str "{ \"foo\" :bar"))
+;;   (should-error (parseedn-read-str "{"))
+;;   (should-error (parseedn-read-str ":{"))
+;;   (should-error (parseedn-read-str "{{"))
+;;   (should-error (parseedn-read-str "}"))
+;;   (should-error (parseedn-read-str ":}"))
+;;   (should-error (parseedn-read-str "}}"))
+;;   (should-error (parseedn-read-str "#:foo"))
+;;   (should-error (parseedn-read-str "\\newline."))
+;;   (should-error (parseedn-read-str "\\newline0.1"))
+;;   (should-error (parseedn-read-str "^"))
+;;   (should-error (parseedn-read-str ":^"))
+;;   (should-error (parseedn-read-str "_:^"))
+;;   (should-error (parseedn-read-str "#{{[}}"))
+;;   (should-error (parseedn-read-str "[}"))
+;;   (should-error (parseedn-read-str "@cat")))
+
+;;; edn-el-parity-test.el ends here
diff --git a/test/clj-edn-test.el b/test/parseedn-test.el
similarity index 61%
rename from test/clj-edn-test.el
rename to test/parseedn-test.el
index dba7e7fb95..c63d139509 100644
--- a/test/clj-edn-test.el
+++ b/test/parseedn-test.el
@@ -1,4 +1,4 @@
-;;; clj-edn-test.el --- Unit tests for EDN reading/printing
+;;; parseedn-test.el --- Unit tests for EDN reading/printing
 
 ;; Copyright (C) 2017  Arne Brasseur
 
@@ -32,46 +32,46 @@
 
 (load "test/parseclj-test-data.el")
 
-(ert-deftest clj-edn-print-test ()
-  (should (equal (clj-edn-print-str nil) "nil"))
-  (should (equal (clj-edn-print-str 100) "100"))
-  (should (equal (clj-edn-print-str 1.2) "1.2"))
-  (should (equal (clj-edn-print-str [1 2 3]) "[1 2 3]"))
-  (should (equal (clj-edn-print-str t) "true")))
+(ert-deftest parseedn-print-test ()
+  (should (equal (parseedn-print-str nil) "nil"))
+  (should (equal (parseedn-print-str 100) "100"))
+  (should (equal (parseedn-print-str 1.2) "1.2"))
+  (should (equal (parseedn-print-str [1 2 3]) "[1 2 3]"))
+  (should (equal (parseedn-print-str t) "true")))
 
-(ert-deftest clj-edn-read-test ()
-  (should (equal (clj-edn-read-str "true") t)))
+(ert-deftest parseedn-read-test ()
+  (should (equal (parseedn-read-str "true") t)))
 
-(defmacro define-clj-edn-read-tests ()
+(defmacro define-parseedn-read-tests ()
   `(progn
      ,@(mapcar
         (lambda (pair)
           (let ((name (car pair))
                 (data (cdr pair)))
             (if (and (a-get data :edn) (a-get data :source))
-                (let ((test-name (intern (concat "clj-edn-read:" name))))
+                (let ((test-name (intern (concat "parseedn-read:" name))))
                   `(ert-deftest ,test-name ()
-                     :tags '(clj-edn)
+                     :tags '(parseedn)
                      (with-temp-buffer
                        (insert ,(a-get data :source))
                        (goto-char 1)
-                       (should (a-equal (clj-edn-read) ',(a-get data 
:edn)))))))))
+                       (should (a-equal (parseedn-read) ',(a-get data 
:edn)))))))))
         parseclj-test-data)))
 
-(defmacro define-clj-edn-roundtrip-tests ()
+(defmacro define-parseedn-roundtrip-tests ()
   `(progn
      ,@(mapcar
         (lambda (pair)
           (let ((name (car pair))
                 (data (cdr pair)))
             (if (and (a-get data :edn) (a-get data :source) (member 
:edn-roundtrip (a-get data :tags)))
-                (let ((test-name (intern (concat "clj-edn-rountrip:" name))))
+                (let ((test-name (intern (concat "parseedn-rountrip:" name))))
                   `(ert-deftest ,test-name ()
-                     :tags '(clj-edn-rountrip)
-                     (should (equal (clj-edn-print-str (car ',(a-get data 
:edn))) ,(a-get data :source))))))))
+                     :tags '(parseedn-rountrip)
+                     (should (equal (parseedn-print-str (car ',(a-get data 
:edn))) ,(a-get data :source))))))))
         parseclj-test-data)))
 
-(define-clj-edn-read-tests)
-(define-clj-edn-roundtrip-tests)
+(define-parseedn-read-tests)
+(define-parseedn-roundtrip-tests)
 
-;;; clj-edn-test.el
+;;; parseedn-test.el



reply via email to

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