Skip to content

Commit decdf8a

Browse files
committed
Add unit tests for moving defun commands
1 parent 8e77a84 commit decdf8a

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

test/elixir-mode-moving-test.el

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
;;; elixir-mode-moving-test.el --- Tests for moving cursor functions
2+
3+
;;; Code:
4+
5+
(require 'test-helper)
6+
7+
(ert-deftest beginning-of-defun ()
8+
:tags '(moving)
9+
(elixir-test-with-temp-buffer
10+
"def foo do
11+
:bar
12+
end
13+
"
14+
(search-forward ":bar")
15+
(call-interactively 'beginning-of-defun)
16+
(should (= (point) (point-min)))))
17+
18+
(ert-deftest beginning-of-defun-nested ()
19+
:tags '(moving)
20+
(elixir-test-with-temp-buffer
21+
"
22+
defmodule Foo do
23+
def bar do
24+
:baz
25+
end
26+
end
27+
"
28+
(search-forward ":baz")
29+
(call-interactively 'beginning-of-defun)
30+
(should (and (= (line-number-at-pos) 3) (bolp)))))
31+
32+
(ert-deftest end-of-defun ()
33+
:tags '(moving)
34+
(elixir-test-with-temp-buffer
35+
"def foo do
36+
:bar
37+
end
38+
"
39+
(search-forward ":bar")
40+
(call-interactively 'end-of-defun)
41+
(should (= (point) (point-max)))))
42+
43+
(ert-deftest end-of-defun-oneline ()
44+
:tags '(moving)
45+
(elixir-test-with-temp-buffer
46+
"def foo do: :bar"
47+
(search-forward ":bar")
48+
(call-interactively 'end-of-defun)
49+
(should (= (point) (line-end-position)))))
50+
51+
(ert-deftest end-of-defun-nested ()
52+
:tags '(moving)
53+
(elixir-test-with-temp-buffer
54+
"
55+
defmodule Foo do
56+
def bar do
57+
:baz
58+
end
59+
end
60+
"
61+
(forward-line 1)
62+
(call-interactively 'end-of-defun)
63+
(should (= (point) (point-max)))
64+
65+
(goto-char (point-min))
66+
(search-forward ":baz")
67+
(call-interactively 'end-of-defun)
68+
(should (and (= (line-number-at-pos) 6) (bolp)))))
69+
70+
(ert-deftest end-of-mark-defun ()
71+
:tags '(moving)
72+
(elixir-test-with-temp-buffer
73+
"
74+
defmodule Foo do
75+
def bar do
76+
:baz
77+
end
78+
end
79+
"
80+
(goto-char (point-min))
81+
(search-forward ":baz")
82+
(call-interactively 'mark-defun)
83+
(should (= (count-lines (region-beginning) (region-end)) 3))))
84+
85+
(provide 'elixir-mode-moving-test)
86+
87+
;;; elixir-mode-helper-test.el ends here

0 commit comments

Comments
 (0)