forked from ananthakumaran/tide
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tide-tests.el
66 lines (51 loc) · 2.33 KB
/
tide-tests.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
;;; tide-tests --- This file contains automated tests for tide.el
;;; Commentary:
;; Run tests using (ert-run-tests-interactively t).
;;; Code:
;; Test setuup:
(require 'ert)
;; development only packages, not declared as a package-dependency
(package-initialize)
(add-to-list 'package-archives '("melpa" . "https://stable.melpa.org/packages/"))
;; tide depends on typescript-mode
(dolist (p '(dash s flycheck typescript-mode))
(when (not (package-installed-p p))
(package-refresh-contents)
(package-install p)))
(require 'tide)
(require 'dash)
;; actual tests:
(ert-deftest strings-get-normalized ()
"Tests that incoming strings (like in codefixes) get normalized properly."
(should (equal "this\nis\nfour\nlines"
(tide-normalize-lineshift "this\nis\r\nfour\nlines"))))
(ert-deftest completions-get-sorted ()
"Tests that completion candidates get sorted by kind."
(let ((mock-completions
'(
(:name "DOMError" :kind "interface" :kindModifiers "declare")
(:name "data" :kind "var" :kindModifiers)
(:name "debugger" :kind "keyword" :kindModifiers)
(:name "declare" :kind "keyword" :kindModifiers)
(:name "decodeURI" :kind "function" :kindModifiers "declare")
(:name "decodeURIComponent" :kind "function" :kindModifiers "declare")
(:name "deleteText" :kind "local function" :kindModifiers)
(:name "dimensions" :kind "parameter" :kindModifiers)
(:name "document" :kind "var" :kindModifiers "declare")))
(sorted-completions
'(
(:name "dimensions" :kind "parameter" :kindModifiers)
(:name "data" :kind "var" :kindModifiers)
(:name "deleteText" :kind "local function" :kindModifiers)
(:name "debugger" :kind "keyword" :kindModifiers)
(:name "declare" :kind "keyword" :kindModifiers)
(:name "document" :kind "var" :kindModifiers "declare")
(:name "decodeURI" :kind "function" :kindModifiers "declare")
(:name "decodeURIComponent" :kind "function" :kindModifiers "declare")
(:name "DOMError" :kind "interface" :kindModifiers "declare"))
))
(should (-same-items?
(-sort 'tide-compare-completions mock-completions)
sorted-completions))))
(provide 'tide-tests)
;;; tide-tests.el ends here