Skip to content

Commit 177e8e1

Browse files
authored
Merge pull request #57 from kommen/add-clojure-mode-tests
Merge clojure-mode tests into clojure-ts-mode
2 parents e69b0ac + 1d7f84d commit 177e8e1

16 files changed

+4495
-0
lines changed

Eldev

+9
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,12 @@
2525
enable-local-variables :safe))
2626

2727
(setq eldev-project-main-file "clojure-ts-mode.el")
28+
29+
;; Exclude tests merged from clojure-mode from running, linting and byte compiling
30+
(setf eldev-test-fileset
31+
`(:and ,eldev-test-fileset
32+
(:not "./clojure-mode-tests/*")))
33+
(setf eldev-standard-excludes
34+
`(:or ,eldev-standard-excludes "./clojure-mode-tests/*"))
35+
(setf eldev-lint-ignored-fileset
36+
`(:or ,eldev-lint-ignored-fileset "./clojure-mode-tests/*"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
;;; clojure-mode-convert-collection-test.el --- Clojure Mode: convert collection type -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2016-2021 Benedek Fazekas <[email protected]>
4+
5+
;; This file is not part of GNU Emacs.
6+
7+
;; This program is free software; you can redistribute it and/or modify
8+
;; it under the terms of the GNU General Public License as published by
9+
;; the Free Software Foundation, either version 3 of the License, or
10+
;; (at your option) any later version.
11+
12+
;; This program is distributed in the hope that it will be useful,
13+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
;; GNU General Public License for more details.
16+
17+
;; You should have received a copy of the GNU General Public License
18+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
20+
;;; Commentary:
21+
22+
;; The convert collection code originally was implemented
23+
;; as cycling collection type in clj-refactor.el and is the work
24+
;; of the clj-reafctor.el team.
25+
26+
;;; Code:
27+
28+
(require 'clojure-mode)
29+
(require 'buttercup)
30+
(require 'test-helper "test/utils/test-helper")
31+
32+
(describe "clojure-convert-collection-to-map"
33+
(when-refactoring-it "should convert a list to a map"
34+
"(:a 1 :b 2)"
35+
"{:a 1 :b 2}"
36+
(backward-sexp)
37+
(down-list)
38+
(clojure-convert-collection-to-map)))
39+
40+
(describe "clojure-convert-collection-to-vector"
41+
(when-refactoring-it "should convert a map to a vector"
42+
"{:a 1 :b 2}"
43+
"[:a 1 :b 2]"
44+
(backward-sexp)
45+
(down-list)
46+
(clojure-convert-collection-to-vector)))
47+
48+
(describe "clojure-convert-collection-to-set"
49+
(when-refactoring-it "should convert a vector to a set"
50+
"[1 2 3]"
51+
"#{1 2 3}"
52+
(backward-sexp)
53+
(down-list)
54+
(clojure-convert-collection-to-set)))
55+
56+
(describe "clojure-convert-collection-to-list"
57+
(when-refactoring-it "should convert a set to a list"
58+
"#{1 2 3}"
59+
"(1 2 3)"
60+
(backward-sexp)
61+
(down-list)
62+
(clojure-convert-collection-to-list)))
63+
64+
(describe "clojure-convert-collection-to-quoted-list"
65+
(when-refactoring-it "should convert a set to a quoted list"
66+
"#{1 2 3}"
67+
"'(1 2 3)"
68+
(backward-sexp)
69+
(down-list)
70+
(clojure-convert-collection-to-quoted-list)))
71+
72+
(describe "clojure-convert-collection-to-set"
73+
(when-refactoring-it "should convert a quoted list to a set"
74+
"'(1 2 3)"
75+
"#{1 2 3}"
76+
(backward-sexp)
77+
(down-list)
78+
(clojure-convert-collection-to-set)))
79+
80+
(provide 'clojure-mode-convert-collection-test)
81+
82+
;;; clojure-mode-convert-collection-test.el ends here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
;;; clojure-mode-cycling-test.el --- Clojure Mode: cycling things tests -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2016-2021 Benedek Fazekas <[email protected]>
4+
5+
;; This file is not part of GNU Emacs.
6+
7+
;; This program is free software; you can redistribute it and/or modify
8+
;; it under the terms of the GNU General Public License as published by
9+
;; the Free Software Foundation, either version 3 of the License, or
10+
;; (at your option) any later version.
11+
12+
;; This program is distributed in the hope that it will be useful,
13+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
;; GNU General Public License for more details.
16+
17+
;; You should have received a copy of the GNU General Public License
18+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
20+
;;; Commentary:
21+
22+
;; The cycling privacy and if/if-not code is ported from
23+
;; clj-refactor.el and the work of the clj-reafctor.el team.
24+
25+
;;; Code:
26+
27+
(require 'clojure-mode)
28+
(require 'buttercup)
29+
30+
(describe "clojure-cycle-privacy"
31+
32+
(when-refactoring-it "should turn a public defn into a private defn"
33+
"(defn add [a b]
34+
(+ a b))"
35+
36+
"(defn- add [a b]
37+
(+ a b))"
38+
39+
(clojure-cycle-privacy))
40+
41+
(when-refactoring-it "should also work from the beginning of a sexp"
42+
"(defn- add [a b]
43+
(+ a b))"
44+
45+
"(defn add [a b]
46+
(+ a b))"
47+
48+
(backward-sexp)
49+
(clojure-cycle-privacy))
50+
51+
(when-refactoring-it "should use metadata when clojure-use-metadata-for-privacy is set to true"
52+
"(defn add [a b]
53+
(+ a b))"
54+
55+
"(defn ^:private add [a b]
56+
(+ a b))"
57+
58+
(let ((clojure-use-metadata-for-privacy t))
59+
(clojure-cycle-privacy)))
60+
61+
(when-refactoring-it "should turn a private defn into a public defn"
62+
"(defn- add [a b]
63+
(+ a b))"
64+
65+
"(defn add [a b]
66+
(+ a b))"
67+
68+
(clojure-cycle-privacy))
69+
70+
(when-refactoring-it "should turn a private defn with metadata into a public defn"
71+
"(defn ^:private add [a b]
72+
(+ a b))"
73+
74+
"(defn add [a b]
75+
(+ a b))"
76+
77+
(let ((clojure-use-metadata-for-privacy t))
78+
(clojure-cycle-privacy)))
79+
80+
(when-refactoring-it "should also work with pre-existing metadata"
81+
"(def ^:dynamic config
82+
\"docs\"
83+
{:env \"staging\"})"
84+
85+
"(def ^:private ^:dynamic config
86+
\"docs\"
87+
{:env \"staging\"})"
88+
89+
(clojure-cycle-privacy))
90+
91+
(when-refactoring-it "should turn a private def with metadata into a public def"
92+
"(def ^:private config
93+
\"docs\"
94+
{:env \"staging\"})"
95+
96+
"(def config
97+
\"docs\"
98+
{:env \"staging\"})"
99+
100+
(clojure-cycle-privacy)))
101+
102+
(describe "clojure-cycle-if"
103+
104+
(when-refactoring-it "should cycle inner if"
105+
"(if this
106+
(if that
107+
(then AAA)
108+
(else BBB))
109+
(otherwise CCC))"
110+
111+
"(if this
112+
(if-not that
113+
(else BBB)
114+
(then AAA))
115+
(otherwise CCC))"
116+
117+
(beginning-of-buffer)
118+
(search-forward "BBB)")
119+
(clojure-cycle-if))
120+
121+
(when-refactoring-it "should cycle outer if"
122+
"(if-not this
123+
(if that
124+
(then AAA)
125+
(else BBB))
126+
(otherwise CCC))"
127+
128+
"(if this
129+
(otherwise CCC)
130+
(if that
131+
(then AAA)
132+
(else BBB)))"
133+
134+
(beginning-of-buffer)
135+
(search-forward "BBB))")
136+
(clojure-cycle-if)))
137+
138+
(describe "clojure-cycle-when"
139+
140+
(when-refactoring-it "should cycle inner when"
141+
"(when this
142+
(when that
143+
(aaa)
144+
(bbb))
145+
(ccc))"
146+
147+
"(when this
148+
(when-not that
149+
(aaa)
150+
(bbb))
151+
(ccc))"
152+
153+
(beginning-of-buffer)
154+
(search-forward "bbb)")
155+
(clojure-cycle-when))
156+
157+
(when-refactoring-it "should cycle outer when"
158+
"(when-not this
159+
(when that
160+
(aaa)
161+
(bbb))
162+
(ccc))"
163+
164+
"(when this
165+
(when that
166+
(aaa)
167+
(bbb))
168+
(ccc))"
169+
170+
(beginning-of-buffer)
171+
(search-forward "bbb))")
172+
(clojure-cycle-when)))
173+
174+
(describe "clojure-cycle-not"
175+
176+
(when-refactoring-it "should add a not when missing"
177+
"(ala bala portokala)"
178+
"(not (ala bala portokala))"
179+
180+
(beginning-of-buffer)
181+
(search-forward "bala")
182+
(clojure-cycle-not))
183+
184+
(when-refactoring-it "should remove a not when present"
185+
"(not (ala bala portokala))"
186+
"(ala bala portokala)"
187+
188+
(beginning-of-buffer)
189+
(search-forward "bala")
190+
(clojure-cycle-not)))
191+
192+
(provide 'clojure-mode-cycling-test)
193+
194+
;;; clojure-mode-cycling-test.el ends here

0 commit comments

Comments
 (0)