Skip to content

Commit af04936

Browse files
author
Yannick Scherer
committed
Prepare for automatic transformation to clojure.test
1 parent 39c0a63 commit af04936

File tree

4 files changed

+49
-42
lines changed

4 files changed

+49
-42
lines changed

test/rewrite_clj/examples/cljx_test.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
(tabular
2020
(fact "about cljx macro detection."
2121
(let [loc (z/of-string ?data)]
22-
(cljx-macro? loc) => ?result))
23-
?data ?result
22+
(cljx-macro? loc) => ?pred))
23+
?data ?pred
2424
"#+clj 123" truthy
2525
"#-clj 123" truthy
2626
"#clj 123" falsey

test/rewrite_clj/node/coerce_test.clj

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
(tabular
99
(fact "about sexpr -> node -> sexpr roundtrip."
1010
(let [n (coerce ?sexpr)]
11-
n => #(satisfies? node/Node %)
11+
(satisfies? node/Node n) => true
1212
(node/string n) => string?
1313
(node/sexpr n) => ?sexpr
1414
(class (node/sexpr n)) => (class ?sexpr)))
@@ -31,7 +31,6 @@
3131
:namespace/keyword
3232
""
3333
"hello, over there!"
34-
#"abc"
3534

3635
;; seqs
3736
[]
@@ -48,14 +47,22 @@
4847
(hash-map)
4948
(hash-map :a 0, :b 1))
5049

50+
(fact "about sexpr -> node -> sexpr roundtrip for regex"
51+
(let [sexpr #"abc"
52+
n (coerce sexpr)]
53+
(satisfies? node/Node n) => true
54+
(node/string n) => string?
55+
(str (node/sexpr n)) => (str sexpr)
56+
(class (node/sexpr n)) => (class sexpr)))
57+
5158
(fact "about vars."
5259
(let [n (coerce #'identity)]
53-
n => #(satisfies? node/Node %)
60+
(satisfies? node/Node n) => true
5461
(node/sexpr n) => '(var clojure.core/identity)))
5562

5663
(fact "about nil."
5764
(let [n (coerce nil)]
58-
n => #(satisfies? node/Node %)
65+
(satisfies? node/Node n) => true
5966
(node/sexpr n) => nil
6067
(p/parse-string "nil") => n))
6168

@@ -64,6 +71,6 @@
6471
(fact "about records."
6572
(let [v (Foo-Bar. 0)
6673
n (coerce v)]
67-
n => #(satisfies? node/Node %)
74+
(satisfies? node/Node n) => true
6875
(node/tag n) => :reader-macro
6976
(node/string n) => (pr-str v)))

test/rewrite_clj/parser_test.clj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232

3333
(tabular
3434
(fact "about parsing simple data"
35-
(let [n (p/parse-string ?s)]
36-
(node/tag n) => :token
37-
(node/string n) => ?s
38-
(node/sexpr n) => ?r))
35+
(binding [*ns* (find-ns 'rewrite-clj.parser-test)]
36+
(let [n (p/parse-string ?s)]
37+
(node/tag n) => :token
38+
(node/string n) => ?s
39+
(node/sexpr n) => ?r)))
3940
?s ?r
4041
"0" 0
4142
"0.1" 0.1

test/rewrite_clj/zip/base_test.clj

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,36 @@
2323

2424
(let [f (java.io.File/createTempFile "rewrite" ".clj")
2525
s " [[1 2] 3]"]
26-
(with-state-changes [(before :facts (spit f s))
27-
(after :facts (.delete f))]
28-
(tabular
29-
(fact "about zipper creation (with movement to first non-ws node)."
30-
(let [loc ?loc
31-
[_ a b c d] (iterate z/next loc)]
32-
(base/tag loc) => :vector
33-
(base/sexpr loc) => [[1 2] 3]
34-
(base/tag a) => :vector
35-
(base/tag b) => :token
36-
(base/tag c) => :whitespace
37-
(base/tag d) => :token
38-
(base/string loc) => "[[1 2] 3]"
39-
(base/string a) => "[1 2]"
40-
(map base/root-string [loc a b c d]) => (has every? #{s})
41-
(with-out-str (base/print loc)) => "[[1 2] 3]"
42-
(with-out-str (base/print-root loc)) => " [[1 2] 3]"
43-
(with-open [w (java.io.StringWriter.)]
44-
(base/print loc w)
45-
(str w)) => "[[1 2] 3]"
46-
(with-open [w (java.io.StringWriter.)]
47-
(base/print-root loc w)
48-
(str w)) => " [[1 2] 3]"))
49-
?loc
50-
(base/edn
51-
(node/forms-node
52-
[(node/spaces 3)
53-
(node/coerce [[1 2] 3])]))
54-
(base/of-string s)
55-
(base/of-file f)
56-
(base/of-file (.getPath f)))))
26+
(spit f s)
27+
(tabular
28+
(fact "about zipper creation (with movement to first non-ws node)."
29+
(let [loc ?loc
30+
[_ a b c d] (iterate z/next loc)]
31+
(base/tag loc) => :vector
32+
(base/sexpr loc) => [[1 2] 3]
33+
(base/tag a) => :vector
34+
(base/tag b) => :token
35+
(base/tag c) => :whitespace
36+
(base/tag d) => :token
37+
(base/string loc) => "[[1 2] 3]"
38+
(base/string a) => "[1 2]"
39+
(map base/root-string [loc a b c d]) => (has every? #{s})
40+
(with-out-str (base/print loc)) => "[[1 2] 3]"
41+
(with-out-str (base/print-root loc)) => " [[1 2] 3]"
42+
(with-open [w (java.io.StringWriter.)]
43+
(base/print loc w)
44+
(str w)) => "[[1 2] 3]"
45+
(with-open [w (java.io.StringWriter.)]
46+
(base/print-root loc w)
47+
(str w)) => " [[1 2] 3]"))
48+
?loc
49+
(base/edn
50+
(node/forms-node
51+
[(node/spaces 3)
52+
(node/coerce [[1 2] 3])]))
53+
(base/of-string s)
54+
(base/of-file f)
55+
(base/of-file (.getPath f))))
5756

5857
(tabular
5958
(fact "about zipper creation for whitespace-only nodes."

0 commit comments

Comments
 (0)