[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/parseclj 60fd8eb965 053/185: Copy tests from edn.el
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/parseclj 60fd8eb965 053/185: Copy tests from edn.el |
Date: |
Tue, 28 Dec 2021 14:05:16 -0500 (EST) |
branch: elpa/parseclj
commit 60fd8eb9654d98b832de4666e341b3679f4b9ed5
Author: Arne Brasseur <arne@arnebrasseur.net>
Commit: Arne Brasseur <arne@arnebrasseur.net>
Copy tests from edn.el
---
tests/edn-el-test-suite.el | 251 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 251 insertions(+)
diff --git a/tests/edn-el-test-suite.el b/tests/edn-el-test-suite.el
new file mode 100644
index 0000000000..d42e021fd4
--- /dev/null
+++ b/tests/edn-el-test-suite.el
@@ -0,0 +1,251 @@
+(require 'ert)
+
+(ert-deftest whitespace ()
+ (should (null (clj-parse-edn-str "")))
+ (should (null (clj-parse-edn-str " ")))
+ (should (null (clj-parse-edn-str " ")))
+ (should (null (clj-parse-edn-str " ")))
+ (should (null (clj-parse-edn-str " ")))
+ (should (null (clj-parse-edn-str ",")))
+ (should (null (clj-parse-edn-str ",,,,")))
+ (should (null (clj-parse-edn-str " , ,
+")))
+ (should (null (clj-parse-edn-str"
+ ,, ")))
+ (should (equal [a b c d] (clj-parse-edn-str "[a ,,,,,, b,,,,,c ,d]"))))
+
+(ert-deftest symbols ()
+ :tags '(edn symbol)
+ (should (equal 'foo (clj-parse-edn-str "foo")))
+ (should (equal 'foo\. (clj-parse-edn-str "foo.")))
+ (should (equal '%foo\. (clj-parse-edn-str "%foo.")))
+ (should (equal 'foo/bar (clj-parse-edn-str "foo/bar")))
+ (equal 'some\#sort\#of\#symbol (clj-parse-edn-str "some#sort#of#symbol"))
+ (equal 'truefalse (clj-parse-edn-str "truefalse"))
+ (equal 'true. (clj-parse-edn-str "true."))
+ (equal '/ (clj-parse-edn-str "/"))
+ (should (equal '.true (clj-parse-edn-str ".true")))
+ (should (equal 'some:sort:of:symbol (clj-parse-edn-str
"some:sort:of:symbol")))
+ (equal 'foo-bar (clj-parse-edn-str "foo-bar"))
+ (should (equal '+some-symbol (clj-parse-edn-str "+some-symbol")))
+ (should (equal '-symbol (clj-parse-edn-str "-symbol"))))
+
+(ert-deftest booleans ()
+ :tags '(edn boolean)
+ (should (equal t (clj-parse-edn-str "true")))
+ (should (equal nil (clj-parse-edn-str "false "))))
+
+(ert-deftest characters ()
+ :tags '(edn characters)
+ (should (equal 97 (clj-parse-edn-str "\\a")))
+ (should (equal 960 (clj-parse-edn-str "\\u03C0")))
+ ;;(should (equal 'newline (clj-parse-edn-str "\\newline")))
+ )
+
+(ert-deftest elision ()
+ :tags '(edn elision)
+ (should-not (clj-parse-edn-str "#_foo"))
+ (should-not (clj-parse-edn-str "#_ 123"))
+ (should-not (clj-parse-edn-str "#_:foo"))
+ (should-not (clj-parse-edn-str "#_ \\a"))
+ (should-not (clj-parse-edn-str "#_
+\"foo\""))
+ (should-not (clj-parse-edn-str "#_ (1 2 3)"))
+ (should (equal '(1 3) (clj-parse-edn-str "(1 #_ 2 3)")))
+ (should (equal '[1 2 3 4] (clj-parse-edn-str "[1 2 #_[4 5 6] 3 4]")))
+ (should (map-equal (make-seeded-hash-table :foo :bar)
+ (clj-parse-edn-str "{:foo #_elided :bar}")))
+ (should (equal (edn-list-to-set '(1 2 3 4))
+ (clj-parse-edn-str "#{1 2 #_[1 2 3] 3 #_ (1 2) 4}")))
+ (should (equal [a d] (clj-parse-edn-str "[a #_ ;we are discarding what comes
next
+ c d]"))))
+
+;; (ert-deftest string ()
+;; :tags '(edn string)
+;; (should (equal "this is a string" (clj-parse-edn-str "\"this is a
string\"")))
+;; (should (equal "this has an escaped \"quote in it"
+;; (clj-parse-edn-str "\"this has an escaped \\\"quote in
it\"")))
+;; (should (equal "foo\tbar" (clj-parse-edn-str "\"foo\\tbar\"")))
+;; (should (equal "foo\nbar" (clj-parse-edn-str "\"foo\\nbar\"")))
+;; (should (equal "this is a string \\ that has an escaped backslash"
+;; (clj-parse-edn-str "\"this is a string \\\\ that has an
escaped backslash\"")))
+;; (should (equal "[" (clj-parse-edn-str "\"[\""))))
+
+;; (ert-deftest keywords ()
+;; :tags '(edn keywords)
+;; (should (equal :namespace\.of\.some\.length/keyword-name
+;; (clj-parse-edn-str
":namespace.of.some.length/keyword-name")))
+;; (should (equal :\#/\# (clj-parse-edn-str ":#/#")))
+;; (should (equal :\#/:a (clj-parse-edn-str ":#/:a")))
+;; (should (equal :\#foo (clj-parse-edn-str ":#foo"))))
+
+;; (ert-deftest integers ()
+;; :tags '(edn integers)
+;; (should (= 0 (clj-parse-edn-str "0")))
+;; (should (= 0 (clj-parse-edn-str "+0")))
+;; (should (= 0 (clj-parse-edn-str "-0")))
+;; (should (= 100 (clj-parse-edn-str "100")))
+;; (should (= -100 (clj-parse-edn-str "-100"))))
+
+;; (ert-deftest floats ()
+;; :tags '(edn floats)
+;; (should (= 12.32 (clj-parse-edn-str "12.32")))
+;; (should (= -12.32 (clj-parse-edn-str "-12.32")))
+;; (should (= 9923.23 (clj-parse-edn-str "+9923.23")))
+;; (should (= 4.5e+044 (clj-parse-edn-str "45e+43")))
+;; (should (= -4.5e-042 (clj-parse-edn-str "-45e-43")))
+;; (should (= 4.5e+044 (clj-parse-edn-str "45E+43"))))
+
+;; (ert-deftest lists ()
+;; :tags '(edn lists)
+;; (should-not (clj-parse-edn-str "()"))
+;; (should (equal '(1 2 3) (clj-parse-edn-str "( 1 2 3)")))
+;; (should (equal '(12.1 ?a foo :bar) (clj-parse-edn-str "(12.1 \\a foo
:bar)")))
+;; (should (equal '((:foo bar :bar 12)) (clj-parse-edn-str "( (:foo bar :bar
12))")))
+;; (should (equal
+;; '(defproject com\.thortech/data\.edn "0.1.0-SNAPSHOT")
+;; (clj-parse-edn-str "(defproject com.thortech/data.edn
\"0.1.0-SNAPSHOT\")"))))
+
+;; (ert-deftest vectors ()
+;; :tags '(edn vectors)
+;; (should (equal [] (clj-parse-edn-str "[]")))
+;; (should (equal [] (clj-parse-edn-str "[ ]")))
+;; (should (equal '[1 2 3] (clj-parse-edn-str "[ 1 2 3 ]")))
+;; (should (equal '[12.1 ?a foo :bar] (clj-parse-edn-str "[ 12.1 \\a foo
:bar]")))
+;; (should (equal '[[:foo bar :bar 12]] (clj-parse-edn-str "[[:foo bar :bar
12]]")))
+;; (should (equal '[( :foo bar :bar 12 ) "foo"]
+;; (clj-parse-edn-str "[(:foo bar :bar 12) \"foo\"]")))
+;; (should (equal '[/ \. * ! _ \? $ % & = - +]
+;; (clj-parse-edn-str "[/ . * ! _ ? $ % & = - +]")))
+;; (should (equal [99 newline return space tab]
+;; (clj-parse-edn-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-parse-edn-str "{ }")))
+;; (should (hash-table-p (clj-parse-edn-str "{}")))
+;; (should (map-equal (make-seeded-hash-table :foo :bar :baz :qux)
+;; (clj-parse-edn-str "{ :foo :bar :baz :qux}")))
+;; (should (map-equal (make-seeded-hash-table 1 "123" 'vector [1 2 3])
+;; (clj-parse-edn-str "{ 1 \"123\" vector [1 2 3]}")))
+;; (should (map-equal (make-seeded-hash-table [1 2 3] "some numbers")
+;; (clj-parse-edn-str "{[1 2 3] \"some numbers\"}"))))
+
+;; (ert-deftest sets ()
+;; :tags '(edn sets)
+;; (should (edn-set-p (clj-parse-edn-str "#{}")))
+;; (should (edn-set-p (clj-parse-edn-str "#{ }")))
+;; (should (equal (edn-list-to-set '(1 2 3)) (clj-parse-edn-str "#{1 2 3}")))
+;; (should (equal (edn-list-to-set '(1 [1 2 3] 3)) (clj-parse-edn-str "#{1
[1 2 3] 3}"))))
+
+;; (ert-deftest comment ()
+;; :tags '(edn comments)
+;; (should-not (clj-parse-edn-str ";nada"))
+;; (should (equal 1 (clj-parse-edn-str ";; comment
+;; 1")))
+;; (should (equal [1 2 3] (clj-parse-edn-str "[1 2 ;comment to eol
+;; 3]")))
+;; (should (equal '[valid more items] (clj-parse-edn-str "[valid;touching
trailing comment
+;; more items]")))
+;; (should (equal [valid vector more vector items] (clj-parse-edn-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)
+
+;; (edn-add-reader "my/type" #'test-val-passed-to-handler)
+;; (edn-add-reader :my/other-type (lambda (val) 2))
+
+;; (ert-deftest tags ()
+;; :tags '(edn tags)
+;; (should-error (clj-parse-edn-str "#my/type value"))
+;; (should (= 1 (clj-parse-edn-str "#my/type (1 2)")))
+;; (should (= 2 (clj-parse-edn-str "#my/other-type {:foo :bar}"))))
+
+;; (ert-deftest roundtrip ()
+;; :tags '(edn roundtrip)
+;; (let ((data [1 2 3 :foo (4 5) qux "quux"]))
+;; (should (equal data (clj-parse-edn-str (edn-print-string data))))
+;; (should (map-equal (make-seeded-hash-table :foo :bar)
+;; (clj-parse-edn-str (edn-print-string
(make-seeded-hash-table :foo :bar)))))
+;; (should (equal (edn-list-to-set '(1 2 3 [3 1.11]))
+;; (clj-parse-edn-str (edn-print-string (edn-list-to-set
'(1 2 3 [3 1.11]))))))
+;; (should-error (clj-parse-edn-str "#myapp/Person {:first \"Fred\" :last
\"Mertz\"}"))))
+
+;; (ert-deftest inst ()
+;; :tags '(edn inst)
+;; (let* ((inst-str "#inst \"1985-04-12T23:20:50.52Z\"")
+;; (inst (clj-parse-edn-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 (equal inst-str (edn-print-string inst)))))
+
+;; (ert-deftest uuid ()
+;; :tags '(edn uuid)
+;; (let* ((str "f81d4fae-7dec-11d0-a765-00a0c91e6bf6")
+;; (uuid (clj-parse-edn-str (concat "#uuid \"" str "\""))))
+;; (should (edn-uuid-p uuid))
+;; (should (equal str (edn-uuid-to-string uuid)))))
+
+;; (ert-deftest invalid-edn ()
+;; (should-error (clj-parse-edn-str "///"))
+;; (should-error (clj-parse-edn-str "~cat"))
+;; (should-error (clj-parse-edn-str "foo/bar/baz/qux/quux"))
+;; (should-error (clj-parse-edn-str "#foo/"))
+;; (should-error (clj-parse-edn-str "foo/"))
+;; (should-error (clj-parse-edn-str ":foo/"))
+;; (should-error (clj-parse-edn-str "#/foo"))
+;; (should-error (clj-parse-edn-str "/symbol"))
+;; (should-error (clj-parse-edn-str ":/foo"))
+;; (should-error (clj-parse-edn-str "+5symbol"))
+;; (should-error (clj-parse-edn-str ".\\newline"))
+;; (should-error (clj-parse-edn-str "0cat"))
+;; (should-error (clj-parse-edn-str "-4cats"))
+;; (should-error (clj-parse-edn-str ".9"))
+;; (should-error (clj-parse-edn-str ":keyword/with/too/many/slashes"))
+;; (should-error (clj-parse-edn-str ":a.b.c/"))
+;; (should-error (clj-parse-edn-str "\\itstoolong"))
+;; (should-error (clj-parse-edn-str ":#/:"))
+;; (should-error (clj-parse-edn-str "/foo//"))
+;; (should-error (clj-parse-edn-str "///foo"))
+;; (should-error (clj-parse-edn-str ":{}"))
+;; (should-error (clj-parse-edn-str "//"))
+;; (should-error (clj-parse-edn-str "##"))
+;; (should-error (clj-parse-edn-str "::"))
+;; (should-error (clj-parse-edn-str "::a"))
+;; (should-error (clj-parse-edn-str ".5symbol"))
+;; (should-error (clj-parse-edn-str "{ \"foo\""))
+;; (should-error (clj-parse-edn-str "{ \"foo\" :bar"))
+;; (should-error (clj-parse-edn-str "{"))
+;; (should-error (clj-parse-edn-str ":{"))
+;; (should-error (clj-parse-edn-str "{{"))
+;; (should-error (clj-parse-edn-str "}"))
+;; (should-error (clj-parse-edn-str ":}"))
+;; (should-error (clj-parse-edn-str "}}"))
+;; (should-error (clj-parse-edn-str "#:foo"))
+;; (should-error (clj-parse-edn-str "\\newline."))
+;; (should-error (clj-parse-edn-str "\\newline0.1"))
+;; (should-error (clj-parse-edn-str "^"))
+;; (should-error (clj-parse-edn-str ":^"))
+;; (should-error (clj-parse-edn-str "_:^"))
+;; (should-error (clj-parse-edn-str "#{{[}}"))
+;; (should-error (clj-parse-edn-str "[}"))
+;; (should-error (clj-parse-edn-str "@cat")))
- [nongnu] elpa/parseclj 3693dd148f 145/185: Fix Cask file, (continued)
- [nongnu] elpa/parseclj 3693dd148f 145/185: Fix Cask file, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj af6102c4a8 146/185: Minor fix to README file, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 91c2ad82af 147/185: Add enough feature to be able to parse clojure.core, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj b40670a561 149/185: Add namespaced maps, fix backquote implementation, ELPA Syncer, 2021/12/28
- [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 <=
- [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, 2021/12/28
- [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