-
Notifications
You must be signed in to change notification settings - Fork 48
/
racer-test.el
231 lines (202 loc) · 7.16 KB
/
racer-test.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
(require 'racer)
(require 'ert)
(ert-deftest racer--file-and-parent ()
(should
(equal
(racer--file-and-parent "/foo/bar/baz/q.txt")
"baz/q.txt")))
(ert-deftest racer--goto-func-name ()
(with-temp-buffer
;; Insert a function call.
(insert "foo(bar, baz);")
;; Move to the start of the second argument.
(goto-char (point-min))
(while (not (looking-at "baz"))
(forward-char 1))
;; We should be at the end of foo.
(racer--goto-func-name)
(should (equal (point) 4))))
(ert-deftest racer--read-rust-string ()
(should
(equal
(racer--read-rust-string "\"foo \\n \\\" \\' \\; bar")
"foo \n \" ' ; bar")))
(ert-deftest racer--help-buf ()
(should
(bufferp
(racer--help-buf "foo bar."))))
(ert-deftest racer--propertize-all-inline-code ()
(should
(equal-including-properties
(racer--propertize-all-inline-code "foo `bar` [`baz`] biz")
#("foo bar baz biz" 4 7 (face font-lock-variable-name-face) 8 11 (face font-lock-variable-name-face)))))
(ert-deftest racer--propertize-docstring-code ()
"Ensure we render code blocks with indents."
(should
(equal
(racer--propertize-docstring "foo
```rust
func();
```
bar.
```text
1
2
```
")
"foo
func();
bar.
1
2
")))
(ert-deftest racer--propertize-docstring-newlines ()
"Ensure we still handle links that have been split over two lines."
(should
(equal
(racer--propertize-docstring "[foo\nbar](baz)")
"foo\nbar")))
(ert-deftest racer--propertize-docstring-links ()
"Ensure we discard footnote links."
(should
(equal
(racer--propertize-docstring "foo [`str`] bar
[`str`]: ../../std/primitive.str.html
baz.")
"foo str bar
baz.")))
(ert-deftest racer--propertize-docstring-urls ()
"Ensure we render buttons for links with urls."
(let ((result (racer--propertize-docstring "[foo](http://example.com)")))
(should (equal result "foo"))
(should (equal (get-text-property 0 'button result) '(t))))
(should
(equal-including-properties
(racer--propertize-docstring "[foo](#bar)")
"foo")))
(ert-deftest racer--propertize-docstring-heading ()
"Ensure we render markdown headings correctly."
(should
(equal-including-properties
(racer--propertize-docstring "# foo")
#("foo" 0 3 (face racer-help-heading-face)))))
(ert-deftest racer--split-parts ()
"Ensure we correctly parse racer CSV."
(should
(equal (racer--split-parts "foo;bar")
'("foo" "bar")))
(should
(equal (racer--split-parts "foo;\"bar\"")
'("foo" "bar")))
(should
(equal (racer--split-parts "foo\\;bar;baz")
'("foo;bar" "baz"))))
(ert-deftest racer--describe-at-point-name ()
"Ensure we extract the correct name in `racer--describe-at-point'."
(cl-letf (((symbol-function 'racer--call)
(lambda (&rest _)
(s-join
"\n"
(list
"PREFIX 36,37,n"
"MATCH new;new();294;11;/home/user/src/rustc-1.10.0/src/libstd/../libcollections/vec.rs;Function;pub fn new() -> Vec<T>;\"Constructs a new, empty `Vec<T>`.\""
"END")))))
(should
(equal (plist-get (racer--describe-at-point "new") :name)
"new"))))
(ert-deftest racer--describe-at-point-nil-docstring ()
"If there's no docstring, racer--describe-at-point should use nil."
(cl-letf (((symbol-function 'racer--call)
(lambda (&rest _)
(s-join
"\n"
(list
"PREFIX 36,37,n"
"MATCH new;new();294;11;/home/user/src/rustc-1.10.0/src/libstd/../libcollections/vec.rs;Function;pub fn new() -> Vec<T>;\"\""
"END")))))
(should
(null (plist-get (racer--describe-at-point "new") :docstring)))))
(ert-deftest racer--describe-at-point-shortest ()
"If there are multiple matches, we want the shortest.
Since we've moved point to the end of symbol, the other functions just happen to have the same prefix."
(cl-letf (((symbol-function 'racer--call)
(lambda (&rest _)
(s-join
"\n"
(list
"PREFIX 36,37,n"
"MATCH new_bar;new_bar();294;11;/home/user/src/rustc-1.10.0/src/libstd/../libcollections/vec.rs;Function;pub fn new() -> Vec<T>;\"\""
"MATCH new;new();294;11;/home/user/src/rustc-1.10.0/src/libstd/../libcollections/vec.rs;Function;pub fn new() -> Vec<T>;\"\""
"MATCH new_foo;new_foo();294;11;/home/user/src/rustc-1.10.0/src/libstd/../libcollections/vec.rs;Function;pub fn new() -> Vec<T>;\"\""
"END")))))
(should
(equal (plist-get (racer--describe-at-point "new") :name)
"new"))))
(ert-deftest racer--syntax-highlight ()
"Ensure we highlight code blocks and snippets correctly."
;; Highlighting types should always use the type face.
(should
(equal-including-properties
(racer--syntax-highlight "Foo")
#("Foo" 0 3 (face font-lock-type-face))))
;; Highlighting keywords.
(should
(equal-including-properties
(racer--syntax-highlight "false")
#("false" 0 5 (face font-lock-keyword-face))))
;; Simple variables should be highlighted, even when standalone.
(should
(equal-including-properties
(racer--syntax-highlight "foo")
#("foo" 0 3 (face font-lock-variable-name-face)))))
(ert-deftest racer-describe ()
"Smoke test for `racer-describe'."
(cl-letf (((symbol-function 'racer--call)
(lambda (&rest _)
(s-join
"\n"
(list
"PREFIX 36,37,n"
"MATCH foo;foo();294;11;/home/user/src/rustc-1.10.0/src/libstd/../libcollections/vec.rs;Function;pub fn new() -> Vec<T>;\"\""
"END")))))
(with-temp-buffer
(rust-mode)
(insert "foo();")
(goto-char (point-min))
(racer-describe))))
(ert-deftest racer-describe-uses-whole-symbol ()
"Racer uses the symbol *before* point, so make sure we move point to
the end of the current symbol.
Otherwise, if the point is at the start of the symbol, we don't find anything."
(let (point-during-call)
(cl-letf (((symbol-function 'racer--call)
(lambda (&rest _)
(setq point-during-call (point))
(s-join
"\n"
(list
"PREFIX 36,37,n"
"MATCH foo;foo();294;11;/home/user/src/rustc-1.10.0/src/libstd/../libcollections/vec.rs;Function;pub fn new() -> Vec<T>;\"\""
"END")))))
(with-temp-buffer
(rust-mode)
(insert "foo();")
(goto-char (point-min))
;; This should move point to the end of 'foo' before calling
;; racer--call.
(racer-describe))
(should (equal point-during-call 4)))))
(ert-deftest racer-debug ()
"Smoke test for `racer-debug'."
(let ((racer--prev-state
(list
:program "racer"
:args '("complete" "1" "2")
:exit-code 0
:stdout "PREFIX 1,2,Ok\nMATCH FOO\nEND\n"
:stderr ""
:default-directory "/"
:process-environment
'("RUST_SRC_PATH=/home/user/src/rustc-1.10.0/src"
"CARGO_HOME=/home/user/.cargo"))))
(racer-debug)))