Skip to content

Commit c4cbd61

Browse files
committed
Added tests for haskell-ident-at-point & friends
As gracjan requested in #603, I > * add[ed] a test case for haskell-ident-at-point really returning nil when it should > * add[ed] a test case for haskell-ident-pos-at-point returning non-nil > * add[ed] a test case for haskell-ident-pos-at-point returning nil > * add[ed] a test case for haskell-spanable-pos-at-point returning non-nil > * add[ed] a test case for haskell-spanable-pos-at-point returning nil I added some somewhat detailed `nil`-checking, a couple quick tests for `haskell-{ident,spanable}-pos-at-point` that just try the same unicode identifiers, and then some tests to distinguish `haskell-spanable-pos-at-point` by using an identifier in backticks. Any test for `haskell-ident-at-point` could also be a test for the other two, so that's a potential source of more tests; however, the definitions of the functions in terms of `haskell-ident-pos-at-point` are so simple that this didn't seem to add much (especially given the sheer amount of test duplication).
1 parent 6a3257c commit c4cbd61

File tree

1 file changed

+92
-1
lines changed

1 file changed

+92
-1
lines changed

tests/haskell-mode-tests.el

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,49 @@
2525
(haskell-mode)
2626
(eq nil (haskell-ident-at-point)))))
2727

28+
(ert-deftest empty-pos ()
29+
(should (with-temp-buffer
30+
(haskell-mode)
31+
(eq nil (haskell-ident-pos-at-point)))))
32+
33+
(ert-deftest empty-spanable ()
34+
(should (with-temp-buffer
35+
(haskell-mode)
36+
(eq nil (haskell-spanable-pos-at-point)))))
37+
38+
(ert-deftest aftercolons ()
39+
(should (with-temp-buffer
40+
(haskell-mode)
41+
(insert "foo ::")
42+
(eq nil (haskell-ident-at-point)))))
43+
44+
(ert-deftest aftercolons-pos ()
45+
(should (with-temp-buffer
46+
(haskell-mode)
47+
(insert "foo ::")
48+
(eq nil (haskell-ident-pos-at-point)))))
49+
50+
(ert-deftest beforetype ()
51+
(should (with-temp-buffer
52+
(haskell-mode)
53+
(insert "foo ::")
54+
(save-excursion (insert " bar -> baz"))
55+
(eq nil (haskell-ident-at-point)))))
56+
57+
(ert-deftest beforetype-pos ()
58+
(should (with-temp-buffer
59+
(haskell-mode)
60+
(insert "foo ::")
61+
(save-excursion (insert " bar -> baz"))
62+
(eq nil (haskell-ident-pos-at-point)))))
63+
64+
(ert-deftest beforetype-spanable ()
65+
(should (with-temp-buffer
66+
(haskell-mode)
67+
(insert "foo ::")
68+
(save-excursion (insert " bar -> baz"))
69+
(eq nil (haskell-spanable-pos-at-point)))))
70+
2871
(ert-deftest single ()
2972
(should (with-temp-buffer
3073
(haskell-mode)
@@ -127,7 +170,55 @@
127170
(should (with-temp-buffer
128171
(haskell-mode)
129172
(insert "Äöèąċōïá")
130-
(string= "Äöèąċōïá" (haskell-ident-at-point)))))
173+
(string= "Äöèąċōïá" (haskell-ident-at-point)))))
174+
175+
(ert-deftest unicode-pos ()
176+
(should (with-temp-buffer
177+
(haskell-mode)
178+
(insert "åöèą5ċōïá")
179+
(equal (cons (point-min) (point-max)) (haskell-ident-pos-at-point)))))
180+
181+
(ert-deftest unicode2-pos ()
182+
(should (with-temp-buffer
183+
(haskell-mode)
184+
(insert "Äöèąċōïá")
185+
(equal (cons (point-min) (point-max)) (haskell-ident-pos-at-point)))))
186+
187+
(ert-deftest unicode-spanable ()
188+
(should (with-temp-buffer
189+
(haskell-mode)
190+
(insert "åöèą5ċōïá")
191+
(equal (cons (point-min) (point-max)) (haskell-spanable-pos-at-point)))))
192+
193+
(ert-deftest unicode2-spanable ()
194+
(should (with-temp-buffer
195+
(haskell-mode)
196+
(insert "Äöèąċōïá")
197+
(equal (cons (point-min) (point-max)) (haskell-spanable-pos-at-point)))))
198+
199+
(ert-deftest ident-in-backticks ()
200+
(should (with-temp-buffer
201+
(haskell-mode)
202+
(insert "`foo`")
203+
(backward-char 2)
204+
(string= "foo" (haskell-ident-at-point)))))
205+
206+
(ert-deftest ident-pos-in-backticks ()
207+
(should (with-temp-buffer
208+
(haskell-mode)
209+
(insert "`foo`")
210+
(backward-char 2)
211+
(equal (cons (1+ (point-min)) (1- (point-max)))
212+
(haskell-ident-pos-at-point)))))
213+
214+
(ert-deftest spanable-pos-in-backticks ()
215+
(should (with-temp-buffer
216+
(haskell-mode)
217+
(insert "`foo`")
218+
(backward-char 2)
219+
(equal (cons (point-min) (point-max))
220+
(haskell-spanable-pos-at-point)))))
221+
131222

132223
(defun check-fill (expected initial)
133224
"Check using ERT if `fill-paragraph' over `initial' gives

0 commit comments

Comments
 (0)