1
- BodyParser = require ' ../lib/snippet-body-parser'
1
+ const BodyParser = require ( '../lib/snippet-body-parser' ) ;
2
2
3
- describe " Snippet Body Parser" , ->
4
- it " breaks a snippet body into lines, with each line containing tab stops at the appropriate position" , ->
5
- bodyTree = BodyParser .parse """
6
- the quick brown $1fox ${2:jumped ${3:over}
7
- }the ${4:lazy} dog
8
- """
3
+ describe ( "Snippet Body Parser" , ( ) => {
4
+ it ( "breaks a snippet body into lines, with each line containing tab stops at the appropriate position" , ( ) => {
5
+ const bodyTree = BodyParser . parse ( `\
6
+ the quick brown $1fox \${2:jumped \${3:over}
7
+ }the \${4:lazy} dog\
8
+ `
9
+ ) ;
9
10
10
- expect (bodyTree).toEqual [
11
+ expect ( bodyTree ) . toEqual ( [
11
12
"the quick brown " ,
12
13
{ index : 1 , content : [ ] } ,
13
14
"fox " ,
@@ -18,31 +19,27 @@ describe "Snippet Body Parser", ->
18
19
{ index : 3 , content : [ "over" ] } ,
19
20
"\n"
20
21
] ,
21
- }
22
- " the "
22
+ } ,
23
+ "the " ,
23
24
{ index : 4 , content : [ "lazy" ] } ,
24
25
" dog"
25
- ]
26
-
27
- it " removes interpolated variables in placeholder text (we don't currently support it)" , ->
28
- bodyTree = BodyParser .parse """
29
- module ${1:ActiveRecord::${TM_FILENAME/(?:\\ A|_)([A-Za-z0-9]+)(?:\\ .rb)?/(?2::\\ u$1)/g}}
30
- """
26
+ ] ) ;
27
+ } ) ;
31
28
32
- expect (bodyTree).toEqual [
29
+ it ( "removes interpolated variables in placeholder text (we don't currently support it)" , ( ) => {
30
+ const bodyTree = BodyParser . parse ( "module ${1:ActiveRecord::${TM_FILENAME/(?:\\A|_)([A-Za-z0-9]+)(?:\\.rb)?/(?2::\\u$1)/g}}" ) ;
31
+ expect ( bodyTree ) . toEqual ( [
33
32
"module " ,
34
33
{
35
34
"index" : 1 ,
36
35
"content" : [ "ActiveRecord::" , "" ]
37
36
}
38
- ]
37
+ ] ) ;
38
+ } ) ;
39
39
40
- it " skips escaped tabstops" , ->
41
- bodyTree = BodyParser .parse """
42
- snippet $1 escaped \\ $2 \\\\ $3
43
- """
44
-
45
- expect (bodyTree).toEqual [
40
+ it ( "skips escaped tabstops" , ( ) => {
41
+ const bodyTree = BodyParser . parse ( "snippet $1 escaped \\$2 \\\\$3" ) ;
42
+ expect ( bodyTree ) . toEqual ( [
46
43
"snippet " ,
47
44
{
48
45
index : 1 ,
@@ -53,41 +50,36 @@ describe "Snippet Body Parser", ->
53
50
index : 3 ,
54
51
content : [ ]
55
52
}
56
- ]
57
-
58
- it " includes escaped right-braces" , ->
59
- bodyTree = BodyParser .parse """
60
- snippet ${1:{\\ }}
61
- """
53
+ ] ) ;
54
+ } ) ;
62
55
63
- expect (bodyTree).toEqual [
56
+ it ( "includes escaped right-braces" , ( ) => {
57
+ const bodyTree = BodyParser . parse ( "snippet ${1:{\\}}" ) ;
58
+ expect ( bodyTree ) . toEqual ( [
64
59
"snippet " ,
65
60
{
66
61
index : 1 ,
67
62
content : [ "{}" ]
68
63
}
69
- ]
64
+ ] ) ;
65
+ } ) ;
70
66
71
- it " parses a snippet with transformations" , ->
72
- bodyTree = BodyParser .parse """
73
- <${1:p}>$0</${1/f/F/}>
74
- """
75
- expect (bodyTree).toEqual [
67
+ it ( "parses a snippet with transformations" , ( ) => {
68
+ const bodyTree = BodyParser . parse ( "<${1:p}>$0</${1/f/F/}>" ) ;
69
+ expect ( bodyTree ) . toEqual ( [
76
70
'<' ,
77
71
{ index : 1 , content : [ 'p' ] } ,
78
72
'>' ,
79
73
{ index : 0 , content : [ ] } ,
80
74
'</' ,
81
75
{ index : 1 , content : [ ] , substitution : { find : / f / g, replace : [ 'F' ] } } ,
82
76
'>'
83
- ]
84
-
85
- it " parses a snippet with multiple tab stops with transformations" , ->
86
- bodyTree = BodyParser .parse """
87
- ${1:placeholder} ${1/(.)/\\ u$1/} $1 ${2:ANOTHER} ${2/^(.*)$/\\ L$1/} $2
88
- """
77
+ ] ) ;
78
+ } ) ;
89
79
90
- expect (bodyTree).toEqual [
80
+ it ( "parses a snippet with multiple tab stops with transformations" , ( ) => {
81
+ const bodyTree = BodyParser . parse ( "${1:placeholder} ${1/(.)/\\u$1/} $1 ${2:ANOTHER} ${2/^(.*)$/\\L$1/} $2" ) ;
82
+ expect ( bodyTree ) . toEqual ( [
91
83
{ index : 1 , content : [ 'placeholder' ] } ,
92
84
' ' ,
93
85
{
@@ -119,15 +111,13 @@ describe "Snippet Body Parser", ->
119
111
} ,
120
112
' ' ,
121
113
{ index : 2 , content : [ ] } ,
122
- ]
114
+ ] ) ;
115
+ } ) ;
123
116
124
117
125
- it " parses a snippet with transformations and mirrors" , ->
126
- bodyTree = BodyParser .parse """
127
- ${1:placeholder}\n ${1/(.)/\\ u$1/}\n $1
128
- """
129
-
130
- expect (bodyTree).toEqual [
118
+ it ( "parses a snippet with transformations and mirrors" , ( ) => {
119
+ const bodyTree = BodyParser . parse ( "${1:placeholder}\n${1/(.)/\\u$1/}\n$1" ) ;
120
+ expect ( bodyTree ) . toEqual ( [
131
121
{ index : 1 , content : [ 'placeholder' ] } ,
132
122
'\n' ,
133
123
{
@@ -143,14 +133,12 @@ describe "Snippet Body Parser", ->
143
133
} ,
144
134
'\n' ,
145
135
{ index : 1 , content : [ ] }
146
- ]
147
-
148
- it " parses a snippet with a format string and case-control flags" , ->
149
- bodyTree = BodyParser .parse """
150
- <${1:p}>$0</${1/(.)(.*)/\\ u$1$2/}>
151
- """
136
+ ] ) ;
137
+ } ) ;
152
138
153
- expect (bodyTree).toEqual [
139
+ it ( "parses a snippet with a format string and case-control flags" , ( ) => {
140
+ const bodyTree = BodyParser . parse ( "<${1:p}>$0</${1/(.)(.*)/\\u$1$2/}>" ) ;
141
+ expect ( bodyTree ) . toEqual ( [
154
142
'<' ,
155
143
{ index : 1 , content : [ 'p' ] } ,
156
144
'>' ,
@@ -169,16 +157,14 @@ describe "Snippet Body Parser", ->
169
157
}
170
158
} ,
171
159
'>'
172
- ]
173
-
174
- it " parses a snippet with an escaped forward slash in a transform" , ->
175
- # Annoyingly, a forward slash needs to be double-backslashed just like the
176
- # other escapes.
177
- bodyTree = BodyParser .parse """
178
- <${1:p}>$0</${1/(.)\\ /(.*)/\\ u$1$2/}>
179
- """
180
-
181
- expect (bodyTree).toEqual [
160
+ ] ) ;
161
+ } ) ;
162
+
163
+ it ( "parses a snippet with an escaped forward slash in a transform" , ( ) => {
164
+ // Annoyingly, a forward slash needs to be double-backslashed just like the
165
+ // other escapes.
166
+ const bodyTree = BodyParser . parse ( "<${1:p}>$0</${1/(.)\\/(.*)/\\u$1$2/}>" ) ;
167
+ expect ( bodyTree ) . toEqual ( [
182
168
'<' ,
183
169
{ index : 1 , content : [ 'p' ] } ,
184
170
'>' ,
@@ -197,14 +183,12 @@ describe "Snippet Body Parser", ->
197
183
}
198
184
} ,
199
185
'>'
200
- ]
201
-
202
- it " parses a snippet with a placeholder that mirrors another tab stop's content" , ->
203
- bodyTree = BodyParser .parse """
204
- $4console.${3:log}('${2:$1}', $1);$0
205
- """
186
+ ] ) ;
187
+ } ) ;
206
188
207
- expect (bodyTree).toEqual [
189
+ it ( "parses a snippet with a placeholder that mirrors another tab stop's content" , ( ) => {
190
+ const bodyTree = BodyParser . parse ( "$4console.${3:log}('${2:$1}', $1);$0" ) ;
191
+ expect ( bodyTree ) . toEqual ( [
208
192
{ index : 4 , content : [ ] } ,
209
193
'console.' ,
210
194
{ index : 3 , content : [ 'log' ] } ,
@@ -218,14 +202,12 @@ describe "Snippet Body Parser", ->
218
202
{ index : 1 , content : [ ] } ,
219
203
');' ,
220
204
{ index : 0 , content : [ ] }
221
- ]
222
-
223
- it " parses a snippet with a placeholder that mixes text and tab stop references" , ->
224
- bodyTree = BodyParser .parse """
225
- $4console.${3:log}('${2:uh $1}', $1);$0
226
- """
205
+ ] ) ;
206
+ } ) ;
227
207
228
- expect (bodyTree).toEqual [
208
+ it ( "parses a snippet with a placeholder that mixes text and tab stop references" , ( ) => {
209
+ const bodyTree = BodyParser . parse ( "$4console.${3:log}('${2:uh $1}', $1);$0" ) ;
210
+ expect ( bodyTree ) . toEqual ( [
229
211
{ index : 4 , content : [ ] } ,
230
212
'console.' ,
231
213
{ index : 3 , content : [ 'log' ] } ,
@@ -240,4 +222,6 @@ describe "Snippet Body Parser", ->
240
222
{ index : 1 , content : [ ] } ,
241
223
');' ,
242
224
{ index : 0 , content : [ ] }
243
- ]
225
+ ] ) ;
226
+ } ) ;
227
+ } ) ;
0 commit comments