-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathinit-test.el
More file actions
94 lines (73 loc) · 3.38 KB
/
init-test.el
File metadata and controls
94 lines (73 loc) · 3.38 KB
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
(ert-deftest company-works-as-expected-in-text-mode ()
:tags '(company)
(switch-to-buffer "*TESTING COMPANY MODE ~ Text*")
;; Ensure we have a clear buffer, and enter some text. (Namely, Python code).
(erase-buffer)
(insert "\n def first(x): pass")
(insert "\n def fierce(a, b): pass")
;; Completion anything mode is enabled by default.
(should company-mode)
;; There are 2 completion candidates: The two we wrote.
(insert "\n fi")
(company-manual-begin) ;; i.e., C-/
(should (equal company-candidates '("fierce" "first")))
;; [fi ↦ fierce] Default option is the most recently matching written word.
(insert "\n fi")
(execute-kbd-macro (kbd "C-/ <return>"))
(should (looking-back "fierce"))
;; [fi ↦ first] We can use M-2 to select the candidate “first”
(insert "\n fi")
(execute-kbd-macro (kbd "C-/ M-2"))
(should (looking-back "first"))
(kill-buffer))
;; Let's enter Python mode and see how things change
(ert-deftest company-shows-keywords-alongside-completions-alphabetically ()
:tags '(company)
(switch-to-buffer "*TESTING COMPANY MODE ~ Python*")
(python-mode)
;; Ensure we have a clear buffer, and enter some text. (Namely, Python code).
(erase-buffer)
(insert "\n def first(x): pass")
(insert "\n def fierce(a, b): pass")
;; There are 3 completion candidates: The two we wrote, & the third being a Python keyword.
(insert "\n fi")
(company-manual-begin)
(should (equal company-candidates '("fierce" "first" #("finally" 0 7 (company-backend company-keywords)))))
;; Candidates are shown alphabetically: M-2 yields “finally”.
(execute-kbd-macro (kbd "C-g C-/ M-2")) ;; Quit and restart the completion, to get to starting position, then M-2.
(should (looking-back "finally"))
(kill-buffer))
;; [[file:init.org::#E2E-Test][E2E Test:1]]
(ert-deftest hideshow-is-enabled-and-folds-by-default ()
:tags '(hideshow)
;; Make a temporary scratch.js file with the given contents.
(let* ((contents "function fierce(name) { \n return `${name}: ROAR` \n }")
(scratch.js (make-temp-file "scratch" nil ".js" contents)))
;; Hideshow is enabled whenever we open a code file
(find-file scratch.js)
(should hs-minor-mode)
;; Function definition is a hidden block
(end-of-line)
(backward-char 2)
(should (hs-already-hidden-p))
;; Indeed, the hidden block starts at the first line break and ends just after the second.
(-let [ov (hs-already-hidden-p)]
(-let [(first\n second\n) (-elem-indices "\n" (s-split "" contents))]
(should (equal (overlay-start ov) first\n)) ;; ≈ 25
(should (equal (overlay-end ov) (+ second\n 2))))) ;; ≈ 52
(kill-buffer)))
;; E2E Test:1 ends here
(ert-deftest lsp-hover-shows-type-signature ()
;; Make a temporary scratch.js file with the given contents.
(-let [scratch.js (make-temp-file "scratch" nil ".js" "const first = (x, y) => 3")]
(find-file scratch.js)
(lsp-workspace-folders-add (f-parent scratch.js))
(lsp)
;; lsp-hover uses lsp--eldoc-message, so let's save the hover info.
(advice-add #'lsp--eldoc-message :before (lambda (&rest msg) (setq my/lsp-hover-message (substring-no-properties (car msg)))))
(end-of-buffer)
(insert "\n first")
(lsp-hover) ;; Alternatively: (lsp-describe-thing-at-point)
(should (equal "const first: (x: any, y: any) => number" my/lsp-hover-message))
(save-buffer)
(kill-buffer)))