1- BodyParser = require ' ../lib/snippet-body-parser'
1+ const BodyParser = require ( '../lib/snippet-body-parser' ) ;
22
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+ ) ;
910
10- expect (bodyTree).toEqual [
11+ expect ( bodyTree ) . toEqual ( [
1112 "the quick brown " ,
1213 { index : 1 , content : [ ] } ,
1314 "fox " ,
@@ -18,31 +19,27 @@ describe "Snippet Body Parser", ->
1819 { index : 3 , content : [ "over" ] } ,
1920 "\n"
2021 ] ,
21- }
22- " the "
22+ } ,
23+ "the " ,
2324 { index : 4 , content : [ "lazy" ] } ,
2425 " 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+ } ) ;
3128
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 ( [
3332 "module " ,
3433 {
3534 "index" : 1 ,
3635 "content" : [ "ActiveRecord::" , "" ]
3736 }
38- ]
37+ ] ) ;
38+ } ) ;
3939
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 ( [
4643 "snippet " ,
4744 {
4845 index : 1 ,
@@ -53,41 +50,36 @@ describe "Snippet Body Parser", ->
5350 index : 3 ,
5451 content : [ ]
5552 }
56- ]
57-
58- it " includes escaped right-braces" , ->
59- bodyTree = BodyParser .parse """
60- snippet ${1:{\\ }}
61- """
53+ ] ) ;
54+ } ) ;
6255
63- expect (bodyTree).toEqual [
56+ it ( "includes escaped right-braces" , ( ) => {
57+ const bodyTree = BodyParser . parse ( "snippet ${1:{\\}}" ) ;
58+ expect ( bodyTree ) . toEqual ( [
6459 "snippet " ,
6560 {
6661 index : 1 ,
6762 content : [ "{}" ]
6863 }
69- ]
64+ ] ) ;
65+ } ) ;
7066
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 ( [
7670 '<' ,
7771 { index : 1 , content : [ 'p' ] } ,
7872 '>' ,
7973 { index : 0 , content : [ ] } ,
8074 '</' ,
8175 { index : 1 , content : [ ] , substitution : { find : / f / g, replace : [ 'F' ] } } ,
8276 '>'
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+ } ) ;
8979
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 ( [
9183 { index : 1 , content : [ 'placeholder' ] } ,
9284 ' ' ,
9385 {
@@ -119,15 +111,13 @@ describe "Snippet Body Parser", ->
119111 } ,
120112 ' ' ,
121113 { index : 2 , content : [ ] } ,
122- ]
114+ ] ) ;
115+ } ) ;
123116
124117
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 ( [
131121 { index : 1 , content : [ 'placeholder' ] } ,
132122 '\n' ,
133123 {
@@ -143,14 +133,12 @@ describe "Snippet Body Parser", ->
143133 } ,
144134 '\n' ,
145135 { 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+ } ) ;
152138
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 ( [
154142 '<' ,
155143 { index : 1 , content : [ 'p' ] } ,
156144 '>' ,
@@ -169,16 +157,14 @@ describe "Snippet Body Parser", ->
169157 }
170158 } ,
171159 '>'
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 ( [
182168 '<' ,
183169 { index : 1 , content : [ 'p' ] } ,
184170 '>' ,
@@ -197,14 +183,12 @@ describe "Snippet Body Parser", ->
197183 }
198184 } ,
199185 '>'
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+ } ) ;
206188
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 ( [
208192 { index : 4 , content : [ ] } ,
209193 'console.' ,
210194 { index : 3 , content : [ 'log' ] } ,
@@ -218,14 +202,12 @@ describe "Snippet Body Parser", ->
218202 { index : 1 , content : [ ] } ,
219203 ');' ,
220204 { 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+ } ) ;
227207
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 ( [
229211 { index : 4 , content : [ ] } ,
230212 'console.' ,
231213 { index : 3 , content : [ 'log' ] } ,
@@ -240,4 +222,6 @@ describe "Snippet Body Parser", ->
240222 { index : 1 , content : [ ] } ,
241223 ');' ,
242224 { index : 0 , content : [ ] }
243- ]
225+ ] ) ;
226+ } ) ;
227+ } ) ;
0 commit comments