|
37 | 37 | (edn-mode) |
38 | 38 | ,@body)) |
39 | 39 |
|
| 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 | + |
40 | 57 | (describe "edn-mode indentation" |
41 | 58 |
|
42 | 59 | (describe "lists use aligned indentation (not function-call style)" |
43 | 60 |
|
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)") |
48 | 63 |
|
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))")) |
53 | 66 |
|
54 | 67 | (describe "forms that normally get special indentation are treated as plain data" |
55 | 68 |
|
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)") |
60 | 71 |
|
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)") |
65 | 74 |
|
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)") |
70 | 77 |
|
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)") |
75 | 80 |
|
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)")) |
80 | 83 |
|
81 | 84 | (describe "maps, vectors, and sets indent normally" |
82 | 85 |
|
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\"}}}")) |
102 | 97 |
|
103 | 98 | (describe "mode configuration" |
104 | 99 |
|
|
0 commit comments