-
-
Notifications
You must be signed in to change notification settings - Fork 194
/
Copy pathsmartparens-get-paired-expression-elisp-test.el
160 lines (126 loc) · 10.7 KB
/
smartparens-get-paired-expression-elisp-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
(defun sp-test--paired-expression-parse-in-elisp (initial result &optional back)
(sp-test-with-temp-elisp-buffer initial
(should (equal (sp-get-paired-expression back) result))))
(sp-ert-deftest sp-test-get-paired-expression-elisp
"Test basic paired expressions in `emacs-lisp-mode'."
(sp-test--paired-expression-parse-in-elisp "|(foo bar)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(foo bar|)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "|()" '(:beg 1 :end 3 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(|)" '(:beg 1 :end 3 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "|(foo (bar) (baz) ((quux) (quo)) qua)" '(:beg 1 :end 37 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(foo (bar) (baz) ((quux) (quo)) |qua)" '(:beg 1 :end 37 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "|\\{foo bar (baz) quux\\}" '(:beg 1 :end 23 :op "\\{" :cl "\\}" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "|\\{foo \\{bar baz\\} quux fux \\}" '(:beg 1 :end 30 :op "\\{" :cl "\\}" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "|[vector foo (bar) lolz]" '(:beg 1 :end 24 :op "[" :cl "]" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "[vector foo (bar) lolz|]" '(:beg 1 :end 24 :op "[" :cl "]" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "|'(foo)" '(:beg 2 :end 7 :op "(" :cl ")" :prefix "'" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "|`(foo)" '(:beg 2 :end 7 :op "(" :cl ")" :prefix "`" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "|,(foo)" '(:beg 2 :end 7 :op "(" :cl ")" :prefix "," :suffix ""))
(sp-test--paired-expression-parse-in-elisp "|,[vector foo (bar) lolz]" '(:beg 2 :end 25 :op "[" :cl "]" :prefix "," :suffix ""))
(sp-test--paired-expression-parse-in-elisp "|(foo (bar) (baz) ((quux) (quo)) qua);;asdasdasd" '(:beg 1 :end 37 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "|(foo (bar) (baz) ((quux) (quo)) qua) ;;asdasdasd" '(:beg 1 :end 37 :op "(" :cl ")" :prefix "" :suffix ""))
;; ? is used as character escape, but \\ escapes the escape.
;; Combinations of \ and ? can create "funny" effects
(sp-test--paired-expression-parse-in-elisp "|(#\\?)" '(:beg 1 :end 6 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "|(foo bar?)" '(:beg 1 :end 11 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "|(foo bar ?) baz)" '(:beg 1 :end 17 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "|(foo bar \\?)" '(:beg 1 :end 13 :op "(" :cl ")" :prefix "" :suffix ""))
)
(sp-ert-deftest sp-test-get-paired-expression-elisp-backward
"Test basic paired expressions in `emacs-lisp-mode' in backwards."
(sp-test--paired-expression-parse-in-elisp "(|foo bar)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "(foo bar|)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "()|" '(:beg 1 :end 3 :op "(" :cl ")" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "(|)" '(:beg 1 :end 3 :op "(" :cl ")" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "(foo (bar) (baz) ((quux) (quo)) qua)|" '(:beg 1 :end 37 :op "(" :cl ")" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "(foo| (bar) (baz) ((quux) (quo)) qua)" '(:beg 1 :end 37 :op "(" :cl ")" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "\\{foo bar (baz) quux\\}|" '(:beg 1 :end 23 :op "\\{" :cl "\\}" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "\\{foo \\{bar baz\\} quux fux \\}|" '(:beg 1 :end 30 :op "\\{" :cl "\\}" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "[vector foo (bar) lolz]|" '(:beg 1 :end 24 :op "[" :cl "]" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "[|vector foo (bar) lolz]" '(:beg 1 :end 24 :op "[" :cl "]" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "'(foo)|" '(:beg 2 :end 7 :op "(" :cl ")" :prefix "'" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "`(foo)|" '(:beg 2 :end 7 :op "(" :cl ")" :prefix "`" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp ",(foo)|" '(:beg 2 :end 7 :op "(" :cl ")" :prefix "," :suffix "") t)
(sp-test--paired-expression-parse-in-elisp ",[vector foo (bar) lolz]|" '(:beg 2 :end 25 :op "[" :cl "]" :prefix "," :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "(foo (bar) (baz) ((quux) (quo)) qua)|;;asdasdasd" '(:beg 1 :end 37 :op "(" :cl ")" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "(foo (bar) (baz) ((quux) (quo)) qua) |;;asdasdasd" '(:beg 1 :end 37 :op "(" :cl ")" :prefix "" :suffix "") t)
;; ? is used as character escape, but \\ escapes the escape.
;; Combinations of \ and ? can create "funny" effects
(sp-test--paired-expression-parse-in-elisp "(#\\?)|" '(:beg 1 :end 6 :op "(" :cl ")" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "(foo bar?)|" '(:beg 1 :end 11 :op "(" :cl ")" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "(foo bar ?) baz)|" '(:beg 1 :end 17 :op "(" :cl ")" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "(foo bar \\?)|" '(:beg 1 :end 13 :op "(" :cl ")" :prefix "" :suffix "") t)
)
(sp-ert-deftest sp-test-get-paired-expression-elisp-fail
"Test that we fail on incomplete pairs."
(sp-test--paired-expression-parse-in-elisp "|(foo bar" nil)
(sp-test--paired-expression-parse-in-elisp "(foo |bar" nil)
(sp-test--paired-expression-parse-in-elisp "(foo bar|" nil)
(sp-test--paired-expression-parse-in-elisp "|(" nil)
(sp-test--paired-expression-parse-in-elisp "(|" nil)
(sp-test--paired-expression-parse-in-elisp "|(()" nil)
(sp-test--paired-expression-parse-in-elisp "|(foo (bar) (baz) ((quux) (quo)) qua" nil)
;; prefixes
(sp-test--paired-expression-parse-in-elisp "|'(foo" nil)
(sp-test--paired-expression-parse-in-elisp "|`(foo" nil)
(sp-test--paired-expression-parse-in-elisp "|,@(foo" nil)
(sp-test--paired-expression-parse-in-elisp "|'foo)" nil)
(sp-test--paired-expression-parse-in-elisp "|`foo)" nil)
(sp-test--paired-expression-parse-in-elisp "|,@foo)" nil)
)
(sp-ert-deftest sp-test-get-paired-expression-elisp-backward-fail
"Test that we fail on incomplete pairs parsing backwards."
(sp-test--paired-expression-parse-in-elisp "foo| bar)" nil t)
(sp-test--paired-expression-parse-in-elisp "foo bar)|" nil t)
(sp-test--paired-expression-parse-in-elisp ")|" nil t)
(sp-test--paired-expression-parse-in-elisp "|)" nil t)
(sp-test--paired-expression-parse-in-elisp "())|" nil t)
(sp-test--paired-expression-parse-in-elisp "foo| (bar) (baz) ((quux) (quo)) qua)" nil t)
(sp-test--paired-expression-parse-in-elisp "foo (bar) (baz) ((quux) (quo)) qua)|" nil t)
;; prefixes
(sp-test--paired-expression-parse-in-elisp "'(foo|" nil t)
(sp-test--paired-expression-parse-in-elisp "`(foo|" nil t)
(sp-test--paired-expression-parse-in-elisp ",@(foo|" nil t)
(sp-test--paired-expression-parse-in-elisp "'foo)|" nil t)
(sp-test--paired-expression-parse-in-elisp "`foo)|" nil t)
(sp-test--paired-expression-parse-in-elisp ",@foo)|" nil t)
)
;; Regression tests
(sp-ert-deftest sp-test-get-paired-expression-505
"Test https://github.com/Fuco1/smartparens/issues/505"
(sp-test--paired-expression-parse-in-elisp "(foo (|bar \"baz(\"))" '(:beg 6 :end 18 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(foo (|bar \"baz(\" ))" '(:beg 6 :end 19 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(|\"(asd\") (foo)" '(:beg 1 :end 9 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(| \"(asd\") (foo)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(|\"(asd\" ) (foo)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(\"(asd\"|) (foo)" '(:beg 1 :end 9 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(\"(asd\"| ) (foo)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(\"(asd\" |) (foo)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(foo) (\"(asd\"|)" '(:beg 7 :end 15 :op "(" :cl ")" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "(foo) ( \"(asd\"|)" '(:beg 7 :end 16 :op "(" :cl ")" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "(foo) ( \"(asd\" |)" '(:beg 7 :end 17 :op "(" :cl ")" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "(foo) ( \"(asd\" | )" '(:beg 7 :end 18 :op "(" :cl ")" :prefix "" :suffix "") t)
;; also check boundary case with a comment
(sp-test--paired-expression-parse-in-elisp "(foo (|bar ;baz(\n ))" '(:beg 6 :end 24 :op "(" :cl ")" :prefix "" :suffix ""))
)
(sp-ert-deftest sp-test-get-paired-expression-556
"Test https://github.com/Fuco1/smartparens/issues/556"
(sp-test--paired-expression-parse-in-elisp "(f| ; ()\n 'x)" '(:beg 1 :end 14 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(f ; ()\n |'x)" '(:beg 1 :end 14 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(f ; ()\n '|x)" '(:beg 1 :end 14 :op "(" :cl ")" :prefix "" :suffix ""))
)
(sp-ert-deftest sp-test-get-paired-expression-653
"If the point is in a multi-line comment, we should be able to
parse a multi-line sexp.
Test https://github.com/Fuco1/smartparens/issues/653"
;; nothing in front
(sp-test--paired-expression-parse-in-elisp " ;; asd |(as d\n ;; asd\n ;; asd) as\n" '(:beg 10 :end 34 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp " ;; asd (as d\n ;; asd\n ;; asd)| as\n" '(:beg 10 :end 34 :op "(" :cl ")" :prefix "" :suffix "") t)
;; with sexp in front
(sp-test--paired-expression-parse-in-elisp "(defun true () t)\n ;; asd |(as d\n ;; asd\n ;; asd) as\n" '(:beg 28 :end 52 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(defun true () t)\n ;; asd (as d\n ;; asd\n ;; asd)| as\n" '(:beg 28 :end 52 :op "(" :cl ")" :prefix "" :suffix "") t))
;; #786
(ert-deftest sp-test-get-paired-expression-valid-hyperlink ()
(sp-test--paired-expression-parse-in-elisp
";; |`foo-bar'."
(list :beg 4 :end 13 :op "`" :cl "'" :prefix "" :suffix "")))