-
-
Notifications
You must be signed in to change notification settings - Fork 195
/
smartparens-get-expression-test.el
75 lines (66 loc) · 3.83 KB
/
smartparens-get-expression-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
(sp-ert-deftest sp-test-skip-forward-to-symbol
;; check that the syntax property is observed when determining
;; syntax #851 #1195
(sp-test-with-temp-elisp-buffer "| -foo-bar"
(put-text-property 2 3 'syntax-table '(1))
(sp-skip-forward-to-symbol)
(sp-buffer-equals " -|foo-bar")))
(defun sp-test--get-expression-skip-before-arrow (ms mb me)
(save-excursion
(goto-char me)
(looking-at-p "<")))
(ert-deftest sp-test-get-expression-string-when-there-is-ignored-regular-before-it-and-valid-after-it ()
"In case there is a non-string delimiter before a
string-delimiter but it turns out it is invalid and we return a
regular expression which starts after the string one, try to
reparse the string expression because it might be valid and
closer.
foo | [<-thisisignored \"bar\" [we got this instead of the string]"
(let ((sp-pairs '((t . ((:open "\"" :close "\"" :actions (insert wrap autoskip navigate))
(:open "[" :close "]" :actions (insert wrap autoskip navigate)
:skip-match sp-test--get-expression-skip-before-arrow))))))
(sp-test-with-temp-elisp-buffer "foo | [<-thisisignored \"bar\" [we got this instead of the string]"
(sp-get (sp-get-expression)
(should (equal :op "\""))
(should (equal :beg 23))))))
(ert-deftest sp-test-get-expression-regular-when-there-is-ignored-string-before-it-and-valid-after-it ()
"In case there is a string delimiter before a
non-string-delimiter but it turns out it is invalid and we return
a string expression which starts after the regular one, try to
reparse the regular expression because it might be valid and
closer.
foo | '<-thisisignored [brackets] `we got this instead of the brackets'"
(let ((sp-pairs '((t . ((:open "'" :close "'" :actions (insert wrap autoskip navigate)
:skip-match sp-test--get-expression-skip-before-arrow)
(:open "[" :close "]" :actions (insert wrap autoskip navigate)))))))
(sp-test-with-temp-buffer "foo | '<-thisisignored [brackets] 'we got this instead of the brackets'"
(fundamental-mode)
(sp-get (sp-get-expression)
(should (equal :op "["))
(should (equal :beg 23))))))
(ert-deftest sp-test-get-expression-regular-when-there-is-ignored-string-before-it-and-no-after-it ()
"If the first delimiter we've found was skipped and then there
were no more string delimiters any following regular pair was
ignored as well.
We should only consider valid delimiters to start parsing."
(let ((sp-pairs '((t . ((:open "'" :close "'" :actions (insert wrap autoskip navigate)
:skip-match sp-test--get-expression-skip-before-arrow)
(:open "[" :close "]" :actions (insert wrap autoskip navigate)))))))
(sp-test-with-temp-buffer "skip this '< and [pick up this]"
(fundamental-mode)
(sp-get (sp-get-expression)
(should (equal :op "["))))))
(ert-deftest sp-test-get-expression-regular-when-there-are-multiple-ignored-strings-before-it-and-no-after-it ()
"If the first delimiter we've found was skipped and then there
were no more string delimiters any following regular pair was
ignored as well.
We should only consider valid delimiters to start parsing."
(let ((sp-pairs '((t . ((:open "'" :close "'" :actions (insert wrap autoskip navigate)
:skip-match sp-test--get-expression-skip-before-arrow)
(:open "*" :close "*" :actions (insert wrap autoskip navigate)
:skip-match sp-test--get-expression-skip-before-arrow)
(:open "[" :close "]" :actions (insert wrap autoskip navigate)))))))
(sp-test-with-temp-buffer "skip this '< and also *< this and [pick up this]"
(fundamental-mode)
(sp-get (sp-get-expression)
(should (equal :op "["))))))