Skip to content

Commit aba82db

Browse files
committed
Add when-indenting-edn-it macro to reduce EDN test boilerplate
Replace repetitive with-edn-buffer + indent-region + expect patterns with a declarative macro matching the style of when-indenting-it in the Clojure indentation tests.
1 parent de898ed commit aba82db

1 file changed

Lines changed: 42 additions & 47 deletions

File tree

test/edn-mode-indentation-test.el

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -37,68 +37,63 @@
3737
(edn-mode)
3838
,@body))
3939

40+
(defmacro when-indenting-edn-it (description &rest forms)
41+
"Return a buttercup spec.
42+
43+
Check that all FORMS correspond to properly indented sexps in `edn-mode'.
44+
45+
DESCRIPTION is a string with the description of the spec."
46+
(declare (indent 1))
47+
`(it ,description
48+
(progn
49+
,@(mapcar (lambda (form)
50+
`(with-temp-buffer
51+
(edn-mode)
52+
(insert "\n" ,form)
53+
(indent-region (point-min) (point-max))
54+
(expect (buffer-string) :to-equal ,(concat "\n" form))))
55+
forms))))
56+
4057
(describe "edn-mode indentation"
4158

4259
(describe "lists use aligned indentation (not function-call style)"
4360

44-
(it "should align list elements uniformly"
45-
(with-edn-buffer "\n(foo\nbar\nbaz)"
46-
(indent-region (point-min) (point-max))
47-
(expect (buffer-string) :to-equal "\n(foo\n bar\n baz)")))
61+
(when-indenting-edn-it "should align list elements uniformly"
62+
"(foo\n bar\n baz)")
4863

49-
(it "should align nested lists uniformly"
50-
(with-edn-buffer "\n(foo\n(bar\nbaz))"
51-
(indent-region (point-min) (point-max))
52-
(expect (buffer-string) :to-equal "\n(foo\n (bar\n baz))"))))
64+
(when-indenting-edn-it "should align nested lists uniformly"
65+
"(foo\n (bar\n baz))"))
5366

5467
(describe "forms that normally get special indentation are treated as plain data"
5568

56-
(it "should align let arguments instead of using body indentation"
57-
(with-edn-buffer "\n(let [x 1]\nx)"
58-
(indent-region (point-min) (point-max))
59-
(expect (buffer-string) :to-equal "\n(let [x 1]\n x)")))
69+
(when-indenting-edn-it "should align let arguments instead of using body indentation"
70+
"(let [x 1]\n x)")
6071

61-
(it "should align if arguments instead of using body indentation"
62-
(with-edn-buffer "\n(if true\n1\n2)"
63-
(indent-region (point-min) (point-max))
64-
(expect (buffer-string) :to-equal "\n(if true\n 1\n 2)")))
72+
(when-indenting-edn-it "should align if arguments instead of using body indentation"
73+
"(if true\n 1\n 2)")
6574

66-
(it "should align cond arguments instead of using body indentation"
67-
(with-edn-buffer "\n(cond a\nb)"
68-
(indent-region (point-min) (point-max))
69-
(expect (buffer-string) :to-equal "\n(cond a\n b)")))
75+
(when-indenting-edn-it "should align cond arguments instead of using body indentation"
76+
"(cond a\n b)")
7077

71-
(it "should align do arguments instead of using body indentation"
72-
(with-edn-buffer "\n(do a\nb)"
73-
(indent-region (point-min) (point-max))
74-
(expect (buffer-string) :to-equal "\n(do a\n b)")))
78+
(when-indenting-edn-it "should align do arguments instead of using body indentation"
79+
"(do a\n b)")
7580

76-
(it "should align keyword lists as data (issue #610)"
77-
(with-edn-buffer "\n(:key1 :value1\n:key2 :value2)"
78-
(indent-region (point-min) (point-max))
79-
(expect (buffer-string) :to-equal "\n(:key1 :value1\n :key2 :value2)"))))
81+
(when-indenting-edn-it "should align keyword lists as data (issue #610)"
82+
"(:key1 :value1\n :key2 :value2)"))
8083

8184
(describe "maps, vectors, and sets indent normally"
8285

83-
(it "should indent map values"
84-
(with-edn-buffer "\n{:a 1\n:b 2}"
85-
(indent-region (point-min) (point-max))
86-
(expect (buffer-string) :to-equal "\n{:a 1\n :b 2}")))
87-
88-
(it "should indent vectors"
89-
(with-edn-buffer "\n[1\n2\n3]"
90-
(indent-region (point-min) (point-max))
91-
(expect (buffer-string) :to-equal "\n[1\n 2\n 3]")))
92-
93-
(it "should indent sets"
94-
(with-edn-buffer "\n#{:a\n:b\n:c}"
95-
(indent-region (point-min) (point-max))
96-
(expect (buffer-string) :to-equal "\n#{:a\n :b\n :c}")))
97-
98-
(it "should indent nested data structures"
99-
(with-edn-buffer "\n{:deps\n{org.clojure/clojure\n{:mvn/version \"1.11.1\"}}}"
100-
(indent-region (point-min) (point-max))
101-
(expect (buffer-string) :to-equal "\n{:deps\n {org.clojure/clojure\n {:mvn/version \"1.11.1\"}}}"))))
86+
(when-indenting-edn-it "should indent map values"
87+
"{:a 1\n :b 2}")
88+
89+
(when-indenting-edn-it "should indent vectors"
90+
"[1\n 2\n 3]")
91+
92+
(when-indenting-edn-it "should indent sets"
93+
"#{:a\n :b\n :c}")
94+
95+
(when-indenting-edn-it "should indent nested data structures"
96+
"{:deps\n {org.clojure/clojure\n {:mvn/version \"1.11.1\"}}}"))
10297

10398
(describe "mode configuration"
10499

0 commit comments

Comments
 (0)