[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/parseclj 6ae14f26ce 070/185: Work on tests and EDN printer
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/parseclj 6ae14f26ce 070/185: Work on tests and EDN printer + other things |
Date: |
Tue, 28 Dec 2021 14:05:18 -0500 (EST) |
branch: elpa/parseclj
commit 6ae14f26ce2388aba9ef1d339dbe558984d3376d
Author: Arne Brasseur <arne@arnebrasseur.net>
Commit: Arne Brasseur <arne@arnebrasseur.net>
Work on tests and EDN printer + other things
Sorry for not splitting this up properly, I might revisit this commit to
pull apart a bit later.
- introduce Cask + ert-runner as test runner (WIP)
- add test_helper.el to set up the right load path (borrowed and adapted
from clojure-mode)
- ast parse: handle tagged literals
- rewrite clj-ast-unparse to work on buffer
- start work on EDN printer (mostly there?)
- add string variants: clj-ast-parse-str, clj-ast-unparse-str,
clj-edn-print-str
- rework tests based on data
- add roundtrip tests for the EDN printer
- rename edn-el-test-suite.el to edn-el-parity-test.el
- drop dependency on edn.el in the test suite
---
.gitignore | 1 +
Cask | 14 +
clj-ast.el | 57 ++--
clj-edn.el | 57 ++++
test/clj-ast-test.el | 49 ++++
.../clj-edn-el-parity-test.el | 43 +--
test/clj-edn-test.el | 73 +++++
{tests => test}/clj-lex-test.el | 8 +-
test/clj-parse-test-data.el | 293 +++++++++++++++++++++
test/clj-parse-test.el | 63 +++++
test/clj-unparse-test.el | 163 ++++++++++++
test/test-helper.el | 38 +++
tests/clj-parse-test.el | 276 -------------------
tests/clj-unparse-test.el | 162 ------------
14 files changed, 822 insertions(+), 475 deletions(-)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000..d4691b73a4
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.cask
diff --git a/Cask b/Cask
new file mode 100644
index 0000000000..528cd303fd
--- /dev/null
+++ b/Cask
@@ -0,0 +1,14 @@
+(source gnu)
+(source melpa)
+(source lambdaisland "https://lambdaisland.github.io/elpa/")
+
+(package-file "clj-parse.el")
+
+(files "clj-lex.el"
+ "clj-edn.el"
+ "clj-ast.el")
+
+(development
+ (depends-on "a")
+;; (depends-on "edn") ;; the edn.el parity tests require some edn.el functions
+ (depends-on "ert-runner"))
diff --git a/clj-ast.el b/clj-ast.el
index 301aacedaa..8f97a7f400 100644
--- a/clj-ast.el
+++ b/clj-ast.el
@@ -44,42 +44,65 @@
(defun clj-ast--reduce-node (stack opener-token children)
(let* ((pos (a-get opener-token 'pos))
- (type (cl-case (clj-lex-token-type opener-token)
- (:root :root)
+ (type (clj-lex-token-type opener-token))
+ (type (cl-case type
(:lparen :list)
(:lbracket :vector)
- (:set :set)
(:lbrace :map)
- (:discard :discard))))
+ (t type))))
(cl-case type
- (:root (clj-parse--make-node :root 0 ':children children))
+ (:root (clj-parse--make-node :root 0 :children children))
(:discard stack)
+ (:tag (clj-parse--make-node :tag
+ pos
+ :tag (intern (substring (a-get opener-token
'form) 1))
+ :children children))
(t (cons
- (clj-parse--make-node type pos
- ':children children)
+ (clj-parse--make-node type pos :children children)
stack)))))
(defun clj-ast-parse ()
+ "Parse Clojure code in buffer to AST.
+
+Parses code in the current buffer, starting from the current
+position of (point)."
(clj-parse-reduce #'clj-ast--reduce-leaf #'clj-ast--reduce-node))
+(defun clj-ast-parse-str (s)
+ "Parse Clojure code in string S to AST."
+ (with-temp-buffer
+ (insert s)
+ (goto-char 1)
+ (clj-ast-parse)))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Unparser
-(defun clj-parse--string-with-delimiters (nodes ld rd)
- (concat ld (mapconcat #'clj-ast-unparse nodes " ") rd))
+(defun clj-ast-unparse-collection (nodes ld rd)
+ (insert ld)
+ (when-let (node (car nodes))
+ (clj-ast-unparse node))
+ (seq-doseq (node (cdr nodes))
+ (insert " ")
+ (clj-ast-unparse node))
+ (insert rd))
(defun clj-ast-unparse (node)
(if (clj-parse--is-leaf? node)
- (alist-get ':form node)
+ (insert (alist-get ':form node))
(let ((subnodes (alist-get ':children node)))
(cl-case (a-get node ':node-type)
- (:root (clj-parse--string-with-delimiters subnodes "" ""))
- (:list (clj-parse--string-with-delimiters subnodes "(" ")"))
- (:vector (clj-parse--string-with-delimiters subnodes "[" "]"))
- (:set (clj-parse--string-with-delimiters subnodes "#{" "}"))
- (:map (clj-parse--string-with-delimiters subnodes "{" "}"))
- (:tag )
- ))))
+ (:root (clj-ast-unparse-collection subnodes "" ""))
+ (:list (clj-ast-unparse-collection subnodes "(" ")"))
+ (:vector (clj-ast-unparse-collection subnodes "[" "]"))
+ (:set (clj-ast-unparse-collection subnodes "#{" "}"))
+ (:map (clj-ast-unparse-collection subnodes "{" "}"))
+ (:tag )))))
+
+(defun clj-ast-unparse-str (data)
+ (with-temp-buffer
+ (clj-ast-unparse data)
+ (buffer-substring-no-properties (point-min) (point-max))))
(provide 'clj-ast)
diff --git a/clj-edn.el b/clj-edn.el
index 24e858eccc..0a147d31e7 100644
--- a/clj-edn.el
+++ b/clj-edn.el
@@ -83,6 +83,63 @@ handlers as an optional argument to the reader functions.")
;; Printer
+(defun clj-edn-print-seq (coll)
+ (clj-edn-print (elt coll 0))
+ (let ((next (seq-drop coll 1)))
+ (when (not (seq-empty-p next))
+ (insert " ")
+ (clj-edn-print-seq next))))
+
+(defun clj-edn-print-kvs (map)
+ (let ((keys (a-keys map)))
+ (clj-edn-print (car keys))
+ (insert " ")
+ (clj-edn-print (a-get map (car keys)))
+ (let ((next (cdr keys)))
+ (when (not (seq-empty-p next))
+ (insert ", ")
+ (clj-edn-print-kvs next)))))
+
+(defun clj-edn-print (datum)
+ (cond
+ ((or (null datum) (numberp datum))
+ (prin1 datum (current-buffer)))
+
+ ((stringp datum)
+ (insert "\"")
+ (seq-doseq (char datum)
+ (insert (cl-case char
+ (?\t "\\t")
+ (?\f "\\f")
+ (?\" "\\\"")
+ (?\r "\\r")
+ (?\n"foo\t" "\\n")
+ (?\\ "\\\\")
+ (t (char-to-string char)))))
+ (insert "\""))
+
+ ((symbolp datum)
+ (insert (symbol-name datum)))
+
+ ((eq t datum)
+ (insert "true"))
+
+ ((vectorp datum) (insert "[") (clj-edn-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 ")"))))
+
+ ((hash-table-p datum)
+ (insert "{") (clj-edn-print-kvs datum) (insert "}"))))
+
+(defun clj-edn-print-str (datum)
+ (with-temp-buffer
+ (clj-edn-print datum)
+ (buffer-substring-no-properties (point-min) (point-max))))
+
(provide 'clj-edn)
;;; clj-edn.el ends here
diff --git a/test/clj-ast-test.el b/test/clj-ast-test.el
new file mode 100644
index 0000000000..da12f26cd1
--- /dev/null
+++ b/test/clj-ast-test.el
@@ -0,0 +1,49 @@
+;;; clj-ast-test.el --- Unit tests for AST parsing/unparsing
+
+;; Copyright (C) 2017 Arne Brasseur
+
+;; Author: Arne Brasseur <arne@arnebrasseur.net>
+
+;; 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
+
+;; Unit tests for AST parsing/unparsing
+
+;;; Code
+
+(defmacro define-clj-ast-parse-tests ()
+ `(progn
+ ,@(mapcar
+ (lambda (pair)
+ (let ((name (car pair))
+ (data (cdr pair)))
+ (if (and (a-get data :source) (a-get data :ast))
+ (let ((test-name (intern (concat "clj-ast-parse:" name))))
+ `(ert-deftest ,test-name ()
+ :tags '(clj-ast)
+ (with-temp-buffer
+ (insert ,(a-get data :source))
+ (goto-char 1)
+ (should (a-equal (clj-ast-parse) ',(a-get data
:ast)))))))))
+ clj-parse-test-data)))
+
+
+(define-clj-ast-parse-tests)
+
+;;; clj-ast-test.el ends here
diff --git a/tests/edn-el-test-suite.el b/test/clj-edn-el-parity-test.el
similarity index 90%
rename from tests/edn-el-test-suite.el
rename to test/clj-edn-el-parity-test.el
index 8aacb168b4..a7f9446d97 100644
--- a/tests/edn-el-test-suite.el
+++ b/test/clj-edn-el-parity-test.el
@@ -1,4 +1,4 @@
-;;; edn-el-test-suite.el --- Tests from edn.el
+;;; edn-el-parity.el --- Tests from edn.el
;; Author: Lars Andersen <expez@expez.com>, Arne Brasseur
<arne@arnebrasseur.net>
@@ -21,10 +21,17 @@
;; 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 clj-parse can act as a drop-in replacement
+;; for edn.el.
+
;;; Code:
+(require 'clj-parse)
(require 'ert)
-(require 'edn)
+(eval-when-compile (require 'subr-x)) ;; for things like hash-table-keys
(ert-deftest whitespace ()
(should (null (clj-edn-read-str "")))
@@ -34,10 +41,8 @@
(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 ()
@@ -81,7 +86,7 @@
(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-list-to-set '(1 2 3 4))
+ (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]"))))
@@ -174,10 +179,10 @@
(ert-deftest sets ()
:tags '(edn sets)
- (should (edn-set-p (clj-edn-read-str "#{}")))
- (should (edn-set-p (clj-edn-read-str "#{ }")))
- (should (equal (edn-list-to-set '(1 2 3)) (clj-edn-read-str "#{1 2 3}")))
- (should (equal (edn-list-to-set '(1 [1 2 3] 3)) (clj-edn-read-str "#{1 [1 2
3] 3}"))))
+ (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)
@@ -212,11 +217,11 @@
(ert-deftest roundtrip ()
:tags '(edn roundtrip)
(let ((data [1 2 3 :foo (4 5) qux "quux"]))
- (should (equal data (clj-edn-read-str (edn-print-string data))))
+ (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 (edn-print-string
(make-seeded-hash-table :foo :bar)))))
- (should (equal (edn-list-to-set '(1 2 3 [3 1.11]))
- (clj-edn-read-str (edn-print-string (edn-list-to-set '(1 2
3 [3 1.11]))))))
+ (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]))))))
(should-error (clj-edn-read-str "#myapp/Person {:first \"Fred\" :last
\"Mertz\"}"))))
(ert-deftest inst ()
@@ -224,14 +229,14 @@
(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 (edn-inst-p inst))
- (should (equal time (edn-inst-to-time inst)))))
+ (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 (edn-uuid-p uuid))))
+ (should (eq 'edn-uuid (car uuid)))))
;; (ert-deftest invalid-edn ()
;; (should-error (clj-edn-read-str "///"))
@@ -278,4 +283,4 @@
;; (should-error (clj-edn-read-str "[}"))
;; (should-error (clj-edn-read-str "@cat")))
-;;; edn-el-test-suite.el ends here
+;;; edn-el-parity-test.el ends here
diff --git a/test/clj-edn-test.el b/test/clj-edn-test.el
new file mode 100644
index 0000000000..76e8ac54b7
--- /dev/null
+++ b/test/clj-edn-test.el
@@ -0,0 +1,73 @@
+;;; clj-edn-test.el --- Unit tests for EDN reading/printing
+
+;; Copyright (C) 2017 Arne Brasseur
+
+;; Author: Arne Brasseur <arne@arnebrasseur.net>
+
+;; 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
+
+;; Unit tests for EDN reading/printing
+
+;;; Code
+
+(require 'ert)
+(require 'clj-parse)
+
+(load "test/clj-parse-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]")))
+
+(defmacro define-clj-edn-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))))
+ `(ert-deftest ,test-name ()
+ :tags '(clj-edn)
+ (with-temp-buffer
+ (insert ,(a-get data :source))
+ (goto-char 1)
+ (should (a-equal (clj-edn-read) ',(a-get data
:edn)))))))))
+ clj-parse-test-data)))
+
+(defmacro define-clj-edn-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))))
+ `(ert-deftest ,test-name ()
+ :tags '(clj-edn-rountrip)
+ (should (equal (clj-edn-print-str (car ',(a-get data
:edn))) ,(a-get data :source))))))))
+ clj-parse-test-data)))
+
+(define-clj-edn-read-tests)
+(define-clj-edn-roundtrip-tests)
+
+;;; clj-edn-test.el
diff --git a/tests/clj-lex-test.el b/test/clj-lex-test.el
similarity index 99%
rename from tests/clj-lex-test.el
rename to test/clj-lex-test.el
index b50de580f2..72bb734d63 100644
--- a/tests/clj-lex-test.el
+++ b/test/clj-lex-test.el
@@ -1,4 +1,4 @@
-;;; clj-lex-test.el --- Clojure/EDN parser
+;;; clj-lex-test.el --- Unit tests for the lexer
;; Copyright (C) 2017 Arne Brasseur
@@ -21,6 +21,12 @@
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
+;;; Commentary
+
+;; Unit tests for the lexer
+
+;;; Code
+
(require 'clj-lex)
(require 'ert)
diff --git a/test/clj-parse-test-data.el b/test/clj-parse-test-data.el
new file mode 100644
index 0000000000..7dff657f5a
--- /dev/null
+++ b/test/clj-parse-test-data.el
@@ -0,0 +1,293 @@
+;;; clj-parse-test-data.el --- Clojure/EDN parser - test data
+
+;; Copyright (C) 2017 Arne Brasseur
+
+;; Author: Arne Brasseur <arne@arnebrasseur.net>
+
+;; 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:
+
+;; Test data for reader / parser / printer / unparser
+
+;;; Code:
+
+(setq clj-parse-test-data
+ (a-list
+
+ "simple-list"
+ (a-list
+ :tags '(:edn-roundtrip)
+ :source "(1 2 3)"
+ :edn '((1 2 3))
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :list)
+ (:position . 1)
+ (:children . (((:node-type . :number)
+ (:position . 2)
+ (:form . "1")
+ (:value . 1))
+ ((:node-type . :number)
+ (:position . 4)
+ (:form . "2")
+ (:value . 2))
+ ((:node-type . :number)
+ (:position . 6)
+ (:form . "3")
+ (:value . 3)))))))))
+
+
+ "empty-list"
+ (a-list
+ :source "()"
+ :edn '(())
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :list)
+ (:position . 1)
+ (:children . nil))))))
+
+ "size-1"
+ (a-list
+ :tags '(:edn-roundtrip)
+ :source "(1)"
+ :edn '((1))
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :list)
+ (:position . 1)
+ (:children . (((:node-type . :number)
+ (:position . 2)
+ (:form . "1")
+ (:value . 1)))))))))
+
+ "leafs"
+ (a-list
+ :source "(nil true false hello-world)"
+ :edn '((nil t nil hello-world))
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :list)
+ (:position . 1)
+ (:children . (((:node-type . :nil)
+ (:position . 2)
+ (:form . "nil")
+ (:value . nil))
+ ((:node-type . :true)
+ (:position . 6)
+ (:form . "true")
+ (:value . t))
+ ((:node-type . :false)
+ (:position . 11)
+ (:form . "false")
+ (:value . nil))
+ ((:node-type . :symbol)
+ (:position . 17)
+ (:form . "hello-world")
+ (:value . hello-world)))))))))
+
+ "qualified-symbol"
+ (a-list
+ :tags '(:edn-roundtrip)
+ :source "clojure.string/join"
+ :edn '(clojure.string/join)
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :symbol)
+ (:position . 1)
+ (:form . "clojure.string/join")
+ (:value . clojure.string/join))))))
+
+ "nested-lists"
+ (a-list
+ :source "((.9 abc (true) (hello)))"
+ :edn '(((0.9 abc (t) (hello))))
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :list)
+ (:position . 1)
+ (:children . (((:node-type . :list)
+ (:position . 2)
+ (:children ((:node-type . :number)
+ (:position . 3)
+ (:form . ".9")
+ (:value . 0.9))
+ ((:node-type . :symbol)
+ (:position . 6)
+ (:form . "abc")
+ (:value . abc))
+ ((:node-type . :list)
+ (:position . 10)
+ (:children ((:node-type .
:true)
+ (:position .
11)
+ (:form .
"true")
+ (:value .
t))))
+ ((:node-type . :list)
+ (:position . 17)
+ (:children ((:node-type .
:symbol)
+ (:position .
18)
+ (:form .
"hello")
+ (:value .
hello)))))))))))))
+
+ "strings-1"
+ (a-list
+ :tags '(:edn-roundtrip)
+ :source "\"abc hello \\t\\\"x\""
+ :edn '("abc hello \t\"x")
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :string)
+ (:position . 1)
+ (:form . "\"abc hello \\t\\\"x\"")
+ (:value . "abc hello \t\"x"))))))
+
+ "strings-2"
+ (a-list
+ :source "(\"---\\f---\\\"-'\\'-\\\\-\\r\\n\")"
+ :edn '(("---\f---\"-''-\\-\r\n"))
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :list)
+ (:position . 1)
+ (:children . (((:node-type . :string)
+ (:position . 2)
+ (:form .
"\"---\\f---\\\"-'\\'-\\\\-\\r\\n\"")
+ (:value .
"---\f---\"-''-\\-\r\n")))))))))
+
+ "chars-1"
+ (a-list
+ :source "(\\newline \\return \\space \\tab \\a \\b \\c \\u0078 \\o171)"
+ :edn '((?\n ?\r ?\ ?\t ?a ?b ?c ?x ?y))
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :list)
+ (:position . 1)
+ (:children . (((:node-type . :character) (:position
. 2) (:form . "\\newline") (:value . ?\n))
+ ((:node-type . :character) (:position
. 11) (:form . "\\return") (:value . ?\r))
+ ((:node-type . :character) (:position
. 19) (:form . "\\space") (:value . 32))
+ ((:node-type . :character) (:position
. 26) (:form . "\\tab") (:value . ?\t))
+ ((:node-type . :character) (:position
. 31) (:form . "\\a") (:value . ?a))
+ ((:node-type . :character) (:position
. 34) (:form . "\\b") (:value . ?b))
+ ((:node-type . :character) (:position
. 37) (:form . "\\c") (:value . ?c))
+ ((:node-type . :character) (:position
. 40) (:form . "\\u0078") (:value . ?x))
+ ((:node-type . :character) (:position
. 47) (:form . "\\o171") (:value . ?y)))))))))
+
+ "chars-2"
+ (a-list
+ :source "\"\\u0078 \\o171\""
+ :edn '("x y")
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :string)
+ (:position . 1)
+ (:form . "\"\\u0078 \\o171\"")
+ (:value . "x y"))))))
+
+ "keywords"
+ (a-list
+ :tags '(:edn-roundtrip)
+ :source ":foo-bar"
+ :edn '(:foo-bar)
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :keyword)
+ (:position . 1)
+ (:form . ":foo-bar")
+ (:value . :foo-bar))))))
+
+ "vector"
+ (a-list
+ :tags '(:edn-roundtrip)
+ :source "[123]"
+ :edn '([123])
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :vector)
+ (:position . 1)
+ (:children . (((:node-type . :number)
+ (:position . 2)
+ (:form . "123")
+ (:value . 123)))))))))
+
+ "map"
+ (a-list
+ :tags '(:edn-roundtrip)
+ :source "{:count 123}"
+ :edn (list (a-hash-table :count 123))
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :map)
+ (:position . 1)
+ (:children . (((:node-type . :keyword)
+ (:position . 2)
+ (:form . ":count")
+ (:value . :count))
+ ((:node-type . :number)
+ (:position . 9)
+ (:form . "123")
+ (:value . 123)))))))))
+
+ "set"
+ (a-list
+ :tags '(:edn-roundtrip)
+ :source "#{:x}"
+ :edn '((edn-set (:x)))
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :set)
+ (:position . 1)
+ (:children . (((:node-type . :keyword)
+ (:position . 3)
+ (:form . ":x")
+ (:value . :x)))))))))
+
+ "discard"
+ (a-list
+ :source "(10 #_11 12 #_#_ 13 14)"
+ :edn '((10 12))
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :list)
+ (:position . 1)
+ (:children . (((:node-type . :number)
+ (:position . 2)
+ (:form . "10")
+ (:value . 10))
+ ((:node-type . :number)
+ (:position . 10)
+ (:form . "12")
+ (:value . 12)))))))))
+
+
+ "tag"
+ (a-list
+ :source "#foo/bar [1]"
+ :ast '((:node-type . :root)
+ (:position . 0)
+ (:children . ((:node-type . :tag)
+ (:position . 1)
+ (:tag . foo/bar)
+ (:children . (((:node-type . :vector)
+ (:position . 10)
+ (:children . (((:node-type . :number)
+ (:position . 11)
+ (:form . "1")
+ (:value . 1)))))))))))))
+
+;;; clj-parse-test-data.el ends here
diff --git a/test/clj-parse-test.el b/test/clj-parse-test.el
new file mode 100644
index 0000000000..ea3bd9b4ac
--- /dev/null
+++ b/test/clj-parse-test.el
@@ -0,0 +1,63 @@
+;;; clj-parse-test.el --- Clojure/EDN parser - tests
+
+;; Copyright (C) 2017 Arne Brasseur
+
+;; Author: Arne Brasseur <arne@arnebrasseur.net>
+
+;; 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:
+
+;; A reader for EDN data files and parser for Clojure source files - tests
+
+;;; Code:
+
+(require 'ert)
+(require 'clj-parse)
+
+(defun clj-parse--deftest-mode (mode test-name test-string expected)
+ (let* ((parse-fn (if (equal mode "edn")
+ #'clj-edn-read
+ #'clj-ast-parse))
+ (test-name (intern (concat (symbol-name parse-fn) "-" (symbol-name
test-name)))))
+ `(ert-deftest ,test-name ()
+ (with-temp-buffer
+ (insert ,test-string)
+ (goto-char 1)
+ (should (a-equal (,parse-fn) (backquote ,expected)))))))
+
+(defmacro clj-parse-deftest (test-name test-string mode-vs-expected-alist)
+ (declare (indent defun))
+ `(progn
+ ,@(let ((edn (a-get mode-vs-expected-alist "edn")))
+ (when (eq (length edn) 1)
+ `((ert-deftest ,(intern (concat "edn-print-" (symbol-name
test-name))) ()
+ (should (equal (clj-edn-print-str (backquote ,(car edn)))
,test-string))))))
+ ,@(mapcar (lambda (vs) (clj-parse--deftest-mode (car vs)
+ test-name
+ test-string
+ (cdr vs)))
+ mode-vs-expected-alist)))
+
+
+;;; Parser modes
+;; ----------------------------------------------------------------------------
+
+(provide 'clj-parse-test)
+
+;;; clj-parse-test.el ends here
diff --git a/test/clj-unparse-test.el b/test/clj-unparse-test.el
new file mode 100644
index 0000000000..47b0cf1225
--- /dev/null
+++ b/test/clj-unparse-test.el
@@ -0,0 +1,163 @@
+;;; clj-unparse-test.el --- Print Clojure AST back to code - tests
+
+;; Copyright (C) 2017 Arne Brasseur
+
+;; Author: Arne Brasseur <arne@arnebrasseur.net>
+
+;; 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:
+
+;; Print Clojure AST back to code - tests
+
+;;; Code:
+
+;;; Printer modes
+;; ----------------------------------------------------------------------------
+
+(ert-deftest clj-ast-unparse-list ()
+ (should (equal "(0 1 2)"
+ (clj-ast-unparse-str '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :list)
+ (:position . 1)
+ (:children .
(((:node-type . :number)
+
(:position . 2)
+ (:form .
"0")
+ (:value
. 0))
+
((:node-type . :number)
+
(:position . 4)
+ (:form .
"1")
+ (:value
. 1))
+
((:node-type . :number)
+
(:position . 6)
+ (:form .
"2")
+ (:value
. 2))))))))))))
+
+(ert-deftest clj-ast-unparse-empty-list ()
+ (should (equal "()"
+ (clj-ast-unparse-str '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :list)
+ (:position . 1)
+ (:children .
nil)))))))))
+
+(ert-deftest clj-ast-unparse-nested-list ()
+ (should (equal "((.9 abc (true) (hello)))"
+ (clj-ast-unparse-str '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :list)
+ (:position . 1)
+ (:children .
(((:node-type . :list)
+
(:position . 2)
+
(:children ((:node-type . :number)
+
(:position . 3)
+
(:form . ".9")
+
(:value . 0.9))
+
((:node-type . :symbol)
+
(:position . 6)
+
(:form . "abc")
+
(:value . abc))
+
((:node-type . :list)
+
(:position . 10)
+
(:children ((:node-type . :true)
+
(:position . 11)
+
(:form . "true")
+
(:value . t))))
+
((:node-type . :list)
+
(:position . 17)
+
(:children ((:node-type . :symbol)
+
(:position . 18)
+
(:form . "hello")
+
(:value . hello))))))))))))))))
+
+(ert-deftest clj-ast-unparse-string ()
+ (should (equal "\"abc hello \\t\\\"x\""
+ (clj-ast-unparse-str '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :string)
+ (:position . 1)
+ (:form . "\"abc hello
\\t\\\"x\"")
+ (:value . "abc hello
\t\"x")))))))))
+
+(ert-deftest clj-ast-unparse-chars ()
+ (should (equal "(\\newline \\return \\space \\tab \\a \\b \\c \\u0078
\\o171)"
+ (clj-ast-unparse-str '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :list)
+ (:position . 1)
+ (:children .
(((:node-type . :character) (:position . 2) (:form . "\\newline") (:value .
?\n))
+
((:node-type . :character) (:position . 11) (:form . "\\return") (:value . ?\r))
+
((:node-type . :character) (:position . 19) (:form . "\\space") (:value . 32))
+
((:node-type . :character) (:position . 26) (:form . "\\tab") (:value . ?\t))
+
((:node-type . :character) (:position . 31) (:form . "\\a") (:value . ?a))
+
((:node-type . :character) (:position . 34) (:form . "\\b") (:value . ?b))
+
((:node-type . :character) (:position . 37) (:form . "\\c") (:value . ?c))
+
((:node-type . :character) (:position . 40) (:form . "\\u0078") (:value . ?x))
+
((:node-type . :character) (:position . 47) (:form . "\\o171") (:value .
?y)))))))))
+ )))
+
+(ert-deftest clj-ast-unparse-keyword ()
+ (should (equal ":foo-bar"
+ (clj-ast-unparse-str '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :keyword)
+ (:position . 1)
+ (:form . ":foo-bar")
+ (:value .
:foo-bar)))))))))
+
+(ert-deftest clj-ast-unparse-vector ()
+ (should (equal "[123]"
+ (clj-ast-unparse-str '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :vector)
+ (:position . 1)
+ (:children .
(((:node-type . :number)
+
(:position . 2)
+ (:form .
"123")
+ (:value
. 123))))))))))))
+
+(ert-deftest clj-ast-unparse-map ()
+ (should (equal "{:count 123}"
+ (clj-ast-unparse-str '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :map)
+ (:position . 1)
+ (:children .
(((:node-type . :keyword)
+
(:position . 2)
+ (:form .
":count")
+ (:value
. :count))
+
((:node-type . :number)
+
(:position . 9)
+ (:form .
"123")
+ (:value
. 123))))))))))))
+
+(ert-deftest clj-ast-unparse-set ()
+ (should (equal "#{:x}"
+ (clj-ast-unparse-str '((:node-type . :root)
+ (:position . 0)
+ (:children . (((:node-type . :set)
+ (:position . 1)
+ (:children .
(((:node-type . :keyword)
+
(:position . 3)
+ (:form .
":x")
+ (:value
. :x))))))))))))
+
+(provide 'clj-unparse-test)
+
+;;; clj-unparse-test.el ends here
diff --git a/test/test-helper.el b/test/test-helper.el
new file mode 100644
index 0000000000..ebc4a58ac2
--- /dev/null
+++ b/test/test-helper.el
@@ -0,0 +1,38 @@
+;;; test-helper.el --- unit test helper functions -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2017 Arne Brasseur
+
+;; Author: Arne Brasseur <arne@arnebrasseur.net>
+
+;; 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:
+
+;; Unit Test setup and helper functions
+
+;;; Code:
+
+(message "Running tests on Emacs %s" emacs-version)
+
+(let* ((current-file (if load-in-progress load-file-name (buffer-file-name)))
+ (source-directory (locate-dominating-file current-file "Cask"))
+ ;; Do not load outdated byte code for tests
+ (load-prefer-newer t))
+ (add-to-list 'load-path source-directory))
+
+;; test-helper.el ends here
diff --git a/tests/clj-parse-test.el b/tests/clj-parse-test.el
deleted file mode 100644
index bfae6fa22b..0000000000
--- a/tests/clj-parse-test.el
+++ /dev/null
@@ -1,276 +0,0 @@
-;;; clj-parse-test.el --- Clojure/EDN parser - tests
-
-;; Copyright (C) 2017 Arne Brasseur
-
-;; Author: Arne Brasseur <arne@arnebrasseur.net>
-
-;; 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:
-
-;; A reader for EDN data files and parser for Clojure source files - tests
-
-;;; Code:
-
-(require 'a)
-(require 'ert)
-(require 'clj-parse)
-
-(defun clj-parse--equal (a b)
- (cond
- ((and (hash-table-p a) (hash-table-p b))
- (a-equal a b))
- ((and (consp a) (consp b))
- (and (clj-parse--equal (car a) (car b))
- (clj-parse--equal (cdr a) (cdr b))))
- (t (equal a b))))
-
-(defun clj-parse--deftest-mode (mode test-name test-string expected)
- (let* ((parse-fn (if (equal mode "edn")
- #'clj-edn-read
- #'clj-ast-parse))
- (test-name (intern (concat (symbol-name parse-fn) "-" (symbol-name
test-name)))))
- `(ert-deftest ,test-name ()
- (with-temp-buffer
- (insert ,test-string)
- (goto-char 1)
- (should (clj-parse--equal (,parse-fn) ,expected))))))
-
-(defmacro clj-parse-deftest (test-name test-string mode-vs-expected-alist)
- (declare (indent defun))
- `(progn
- ,@(mapcar (lambda (vs) (clj-parse--deftest-mode (car vs)
- test-name
- test-string
- (cadr vs)))
- mode-vs-expected-alist)))
-
-
-;;; Parser modes
-;; ----------------------------------------------------------------------------
-
-(clj-parse-deftest simple-list "(1 2 3)"
- (("edn" '((1 2 3)))
- ("ast" '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :list)
- (:position . 1)
- (:children . (((:node-type . :number)
- (:position . 2)
- (:form . "1")
- (:value . 1))
- ((:node-type . :number)
- (:position . 4)
- (:form . "2")
- (:value . 2))
- ((:node-type . :number)
- (:position . 6)
- (:form . "3")
- (:value . 3)))))))))))
-
-
-(clj-parse-deftest empty-list "()"
- (("edn" '(()))
- ("ast" '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :list)
- (:position . 1)
- (:children . nil))))))))
-
-(clj-parse-deftest size-1 "(1)"
- (("edn" '((1)))
- ("ast" '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :list)
- (:position . 1)
- (:children . (((:node-type . :number)
- (:position . 2)
- (:form . "1")
- (:value . 1)))))))))))
-
-(clj-parse-deftest leafs "(nil true false hello-world)"
- (("edn" '((nil t nil hello-world)))
- ("ast" '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :list)
- (:position . 1)
- (:children . (((:node-type . :nil)
- (:position . 2)
- (:form . "nil")
- (:value . nil))
- ((:node-type . :true)
- (:position . 6)
- (:form . "true")
- (:value . t))
- ((:node-type . :false)
- (:position . 11)
- (:form . "false")
- (:value . nil))
- ((:node-type . :symbol)
- (:position . 17)
- (:form . "hello-world")
- (:value . hello-world)))))))))))
-
-(clj-parse-deftest qualified-symbol "clojure.string/join"
- (("edn" '(clojure.string/join))
- ("ast" '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :symbol)
- (:position . 1)
- (:form . "clojure.string/join")
- (:value . clojure.string/join))))))))
-
-(clj-parse-deftest nested-lists "((.9 abc (true) (hello)))"
- (("edn" '(((0.9 abc (t) (hello)))))
- ("ast" '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :list)
- (:position . 1)
- (:children . (((:node-type . :list)
- (:position . 2)
- (:children ((:node-type . :number)
- (:position . 3)
- (:form . ".9")
- (:value . 0.9))
- ((:node-type . :symbol)
- (:position . 6)
- (:form . "abc")
- (:value . abc))
- ((:node-type . :list)
- (:position . 10)
- (:children ((:node-type
. :true)
- (:position .
11)
- (:form .
"true")
- (:value .
t))))
- ((:node-type . :list)
- (:position . 17)
- (:children ((:node-type
. :symbol)
- (:position .
18)
- (:form .
"hello")
- (:value .
hello)))))))))))))))
-
-(clj-parse-deftest strings-1 "\"abc hello \\t\\\"x\""
- (("edn" '("abc hello \t\"x"))
- ("ast" '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :string)
- (:position . 1)
- (:form . "\"abc hello \\t\\\"x\"")
- (:value . "abc hello \t\"x"))))))))
-
-(clj-parse-deftest strings-2 "(\"---\\f---\\\"-'\\'-\\\\-\\r\\n\")"
- (("edn" '(("---\f---\"-''-\\-\r\n")))
- ("ast" '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :list)
- (:position . 1)
- (:children . (((:node-type . :string)
- (:position . 2)
- (:form .
"\"---\\f---\\\"-'\\'-\\\\-\\r\\n\"")
- (:value .
"---\f---\"-''-\\-\r\n")))))))))))
-
-(clj-parse-deftest chars-1 "(\\newline \\return \\space \\tab \\a \\b \\c
\\u0078 \\o171)"
- (("edn" '((?\n ?\r ?\ ?\t ?a ?b ?c ?x ?y)))
- ("ast" '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :list)
- (:position . 1)
- (:children . (((:node-type . :character) (:position
. 2) (:form . "\\newline") (:value . ?\n))
- ((:node-type . :character) (:position
. 11) (:form . "\\return") (:value . ?\r))
- ((:node-type . :character) (:position
. 19) (:form . "\\space") (:value . 32))
- ((:node-type . :character) (:position
. 26) (:form . "\\tab") (:value . ?\t))
- ((:node-type . :character) (:position
. 31) (:form . "\\a") (:value . ?a))
- ((:node-type . :character) (:position
. 34) (:form . "\\b") (:value . ?b))
- ((:node-type . :character) (:position
. 37) (:form . "\\c") (:value . ?c))
- ((:node-type . :character) (:position
. 40) (:form . "\\u0078") (:value . ?x))
- ((:node-type . :character) (:position
. 47) (:form . "\\o171") (:value . ?y)))))))))))
-
-(clj-parse-deftest chars-2 "\"\\u0078 \\o171\""
- (("edn" '("x y"))
- ("ast" '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :string)
- (:position . 1)
- (:form . "\"\\u0078 \\o171\"")
- (:value . "x y"))))))))
-
-(clj-parse-deftest keywords ":foo-bar"
- (("edn" '(:foo-bar))
- ("ast" '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :keyword)
- (:position . 1)
- (:form . ":foo-bar")
- (:value . :foo-bar))))))))
-
-(clj-parse-deftest vector "[123]"
- (("edn" '([123]))
- ("ast" '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :vector)
- (:position . 1)
- (:children . (((:node-type . :number)
- (:position . 2)
- (:form . "123")
- (:value . 123)))))))))))
-
-(clj-parse-deftest map "{:count 123}"
- (("edn" (list (a-hash-table :count 123)))
- ("ast" '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :map)
- (:position . 1)
- (:children . (((:node-type . :keyword)
- (:position . 2)
- (:form . ":count")
- (:value . :count))
- ((:node-type . :number)
- (:position . 9)
- (:form . "123")
- (:value . 123)))))))))))
-
-(clj-parse-deftest set "#{:x}"
- (("edn" '((edn-set (:x))))
- ("ast" '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :set)
- (:position . 1)
- (:children . (((:node-type . :keyword)
- (:position . 3)
- (:form . ":x")
- (:value . :x)))))))))))
-
-(clj-parse-deftest discard "(10 #_11 12 #_#_ 13 14)"
- (("edn" '((10 12)))
- ("ast" '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :list)
- (:position . 1)
- (:children . (((:node-type . :number)
- (:position . 2)
- (:form . "10")
- (:value . 10))
- ((:node-type . :number)
- (:position . 10)
- (:form . "12")
- (:value . 12)))))))))))
-
-
-(provide 'clj-parse-test)
-
-;;; clj-parse-test.el ends here
diff --git a/tests/clj-unparse-test.el b/tests/clj-unparse-test.el
deleted file mode 100644
index 60cf658e73..0000000000
--- a/tests/clj-unparse-test.el
+++ /dev/null
@@ -1,162 +0,0 @@
-;;; clj-unparse-test.el --- Print Clojure AST back to code - tests
-
-;; Copyright (C) 2017 Arne Brasseur
-
-;; Author: Arne Brasseur <arne@arnebrasseur.net>
-
-;; 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:
-
-;; Print Clojure AST back to code - tests
-
-;;; Code:
-
-;;; Printer modes
-;; ----------------------------------------------------------------------------
-
-(ert-deftest clj-ast-unparse-list ()
- (should (equal "(0 1 2)"
- (clj-ast-unparse '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :list)
- (:position . 1)
- (:children . (((:node-type
. :number)
- (:position .
2)
- (:form . "0")
- (:value . 0))
- ((:node-type
. :number)
- (:position .
4)
- (:form . "1")
- (:value . 1))
- ((:node-type
. :number)
- (:position .
6)
- (:form . "2")
- (:value .
2))))))))))))
-
-(ert-deftest clj-ast-unparse-empty-list ()
- (should (equal "()"
- (clj-ast-unparse '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :list)
- (:position . 1)
- (:children . nil)))))))))
-
-(ert-deftest clj-ast-unparse-nested-list ()
- (should (equal "((.9 abc (true) (hello)))"
- (clj-ast-unparse '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :list)
- (:position . 1)
- (:children . (((:node-type
. :list)
- (:position .
2)
- (:children
((:node-type . :number)
-
(:position . 3)
-
(:form . ".9")
-
(:value . 0.9))
-
((:node-type . :symbol)
-
(:position . 6)
-
(:form . "abc")
-
(:value . abc))
-
((:node-type . :list)
-
(:position . 10)
-
(:children ((:node-type . :true)
-
(:position . 11)
-
(:form . "true")
-
(:value . t))))
-
((:node-type . :list)
-
(:position . 17)
-
(:children ((:node-type . :symbol)
-
(:position . 18)
-
(:form . "hello")
-
(:value . hello))))))))))))))))
-
-(ert-deftest clj-ast-unparse-string ()
- (should (equal "\"abc hello \\t\\\"x\""
- (clj-ast-unparse '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :string)
- (:position . 1)
- (:form . "\"abc hello
\\t\\\"x\"")
- (:value . "abc hello
\t\"x")))))))))
-
-(ert-deftest clj-ast-unparse-chars ()
- (should (equal "(\\newline \\return \\space \\tab \\a \\b \\c \\u0078
\\o171)"
- (clj-ast-unparse '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :list)
- (:position . 1)
- (:children . (((:node-type
. :character) (:position . 2) (:form . "\\newline") (:value . ?\n))
- ((:node-type
. :character) (:position . 11) (:form . "\\return") (:value . ?\r))
- ((:node-type
. :character) (:position . 19) (:form . "\\space") (:value . 32))
- ((:node-type
. :character) (:position . 26) (:form . "\\tab") (:value . ?\t))
- ((:node-type
. :character) (:position . 31) (:form . "\\a") (:value . ?a))
- ((:node-type
. :character) (:position . 34) (:form . "\\b") (:value . ?b))
- ((:node-type
. :character) (:position . 37) (:form . "\\c") (:value . ?c))
- ((:node-type
. :character) (:position . 40) (:form . "\\u0078") (:value . ?x))
- ((:node-type
. :character) (:position . 47) (:form . "\\o171") (:value . ?y))))))))))))
-
-(ert-deftest clj-ast-unparse-keyword ()
- (should (equal ":foo-bar"
- (clj-ast-unparse '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :keyword)
- (:position . 1)
- (:form . ":foo-bar")
- (:value . :foo-bar)))))))))
-
-(ert-deftest clj-ast-unparse-vector ()
- (should (equal "[123]"
- (clj-ast-unparse '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :vector)
- (:position . 1)
- (:children . (((:node-type
. :number)
- (:position .
2)
- (:form .
"123")
- (:value .
123))))))))))))
-
-(ert-deftest clj-ast-unparse-map ()
- (should (equal "{:count 123}"
- (clj-ast-unparse '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :map)
- (:position . 1)
- (:children . (((:node-type
. :keyword)
- (:position .
2)
- (:form .
":count")
- (:value .
:count))
- ((:node-type
. :number)
- (:position .
9)
- (:form .
"123")
- (:value .
123))))))))))))
-
-(ert-deftest clj-ast-unparse-set ()
- (should (equal "#{:x}"
- (clj-ast-unparse '((:node-type . :root)
- (:position . 0)
- (:children . (((:node-type . :set)
- (:position . 1)
- (:children . (((:node-type
. :keyword)
- (:position .
3)
- (:form .
":x")
- (:value .
:x))))))))))))
-
-(provide 'clj-unparse-test)
-
-;;; clj-unparse-test.el ends here
- [nongnu] elpa/parseclj ff0443c27c 151/185: Add :read-one option, (continued)
- [nongnu] elpa/parseclj ff0443c27c 151/185: Add :read-one option, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 40e36c41eb 006/185: alist-get was only introduced in 25.1? :sadpanda:, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 6f36bbf6b4 009/185: Try to set up a build matrix, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj d4286f9071 010/185: Give README the right extension, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj ce7ad0e427 025/185: implement strings, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj a08b85ffa8 032/185: Implement parsing maps, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 60fd8eb965 053/185: Copy tests from edn.el, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 212e0dc42b 063/185: silly typo, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 96b8180987 087/185: Unparse ASTs that have lexical preservation., ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj da0c877940 069/185: Remove dash, using seq is good enough, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 6ae14f26ce 070/185: Work on tests and EDN printer + other things,
ELPA Syncer <=
- [nongnu] elpa/parseclj 496a7356bb 064/185: Add edn.el as a dependency, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 87953e44ba 092/185: Parse options on to the reducers, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 496c965edc 074/185: Make t print as true - thanks @martinklepsch, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 1cf0fb9d3f 065/185: More build related fixes, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 0644bcdbf4 085/185: Implement :fail-fast, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 6d40b39cec 082/185: Rename clj-edn to parseedn, keep it in this package for now., ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 185ce6367b 090/185: Add :discard support for :lexical-preservation t, and show that it's broken, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 1be462e0f2 108/185: Move parser to its own module, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj f86a3be4bf 107/185: Add last rewordings, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 388bb2bde2 115/185: Fix test case for `\u` and `\o` characters, ELPA Syncer, 2021/12/28