@@ -116,5 +116,111 @@ describe("shared ast-utils", () => {
116116 assert . isNotNull ( match ) ;
117117 assert . strictEqual ( match [ 1 ] , "/usr/bin/env node" ) ;
118118 } ) ;
119+
120+ it ( "should match a shebang before CR" , ( ) => {
121+ const match = astUtils . shebangPattern . exec (
122+ "#!/usr/bin/env node\rconst x = 1;" ,
123+ ) ;
124+
125+ assert . isNotNull ( match ) ;
126+ assert . strictEqual ( match [ 0 ] , "#!/usr/bin/env node" ) ;
127+ assert . strictEqual ( match [ 1 ] , "/usr/bin/env node" ) ;
128+ } ) ;
129+
130+ it ( "should match an empty shebang before CR" , ( ) => {
131+ const match = astUtils . shebangPattern . exec ( "#!\rconst x = 1;" ) ;
132+
133+ assert . isNotNull ( match ) ;
134+ assert . strictEqual ( match [ 0 ] , "#!" ) ;
135+ assert . strictEqual ( match [ 1 ] , "" ) ;
136+ } ) ;
137+
138+ it ( "should match a shebang before LF" , ( ) => {
139+ const match = astUtils . shebangPattern . exec (
140+ "#!/usr/bin/env node\nconst x = 1;" ,
141+ ) ;
142+
143+ assert . isNotNull ( match ) ;
144+ assert . strictEqual ( match [ 0 ] , "#!/usr/bin/env node" ) ;
145+ assert . strictEqual ( match [ 1 ] , "/usr/bin/env node" ) ;
146+ } ) ;
147+
148+ it ( "should match an empty shebang before LF" , ( ) => {
149+ const match = astUtils . shebangPattern . exec ( "#!\nconst x = 1;" ) ;
150+
151+ assert . isNotNull ( match ) ;
152+ assert . strictEqual ( match [ 0 ] , "#!" ) ;
153+ assert . strictEqual ( match [ 1 ] , "" ) ;
154+ } ) ;
155+
156+ it ( "should match a shebang before CRLF" , ( ) => {
157+ const match = astUtils . shebangPattern . exec (
158+ "#!/usr/bin/env node\r\nconst x = 1;" ,
159+ ) ;
160+
161+ assert . isNotNull ( match ) ;
162+ assert . strictEqual ( match [ 0 ] , "#!/usr/bin/env node" ) ;
163+ assert . strictEqual ( match [ 1 ] , "/usr/bin/env node" ) ;
164+ } ) ;
165+
166+ it ( "should match an empty shebang before CRLF" , ( ) => {
167+ const match = astUtils . shebangPattern . exec ( "#!\r\nconst x = 1;" ) ;
168+
169+ assert . isNotNull ( match ) ;
170+ assert . strictEqual ( match [ 0 ] , "#!" ) ;
171+ assert . strictEqual ( match [ 1 ] , "" ) ;
172+ } ) ;
173+
174+ it ( "should match a shebang before LS" , ( ) => {
175+ const match = astUtils . shebangPattern . exec (
176+ "#!/usr/bin/env node\u2028const x = 1;" ,
177+ ) ;
178+
179+ assert . isNotNull ( match ) ;
180+ assert . strictEqual ( match [ 0 ] , "#!/usr/bin/env node" ) ;
181+ assert . strictEqual ( match [ 1 ] , "/usr/bin/env node" ) ;
182+ } ) ;
183+
184+ it ( "should match an empty shebang before LS" , ( ) => {
185+ const match = astUtils . shebangPattern . exec ( "#!\u2028const x = 1;" ) ;
186+
187+ assert . isNotNull ( match ) ;
188+ assert . strictEqual ( match [ 0 ] , "#!" ) ;
189+ assert . strictEqual ( match [ 1 ] , "" ) ;
190+ } ) ;
191+
192+ it ( "should match a shebang before PS" , ( ) => {
193+ const match = astUtils . shebangPattern . exec (
194+ "#!/usr/bin/env node\u2029const x = 1;" ,
195+ ) ;
196+
197+ assert . isNotNull ( match ) ;
198+ assert . strictEqual ( match [ 0 ] , "#!/usr/bin/env node" ) ;
199+ assert . strictEqual ( match [ 1 ] , "/usr/bin/env node" ) ;
200+ } ) ;
201+
202+ it ( "should match an empty shebang before PS" , ( ) => {
203+ const match = astUtils . shebangPattern . exec ( "#!\u2029const x = 1;" ) ;
204+
205+ assert . isNotNull ( match ) ;
206+ assert . strictEqual ( match [ 0 ] , "#!" ) ;
207+ assert . strictEqual ( match [ 1 ] , "" ) ;
208+ } ) ;
209+
210+ it ( "should match a shebang at EOF" , ( ) => {
211+ const match = astUtils . shebangPattern . exec ( "#!/usr/bin/env node" ) ;
212+
213+ assert . isNotNull ( match ) ;
214+ assert . strictEqual ( match [ 0 ] , "#!/usr/bin/env node" ) ;
215+ assert . strictEqual ( match [ 1 ] , "/usr/bin/env node" ) ;
216+ } ) ;
217+
218+ it ( "should match an empty shebang at EOF" , ( ) => {
219+ const match = astUtils . shebangPattern . exec ( "#!" ) ;
220+
221+ assert . isNotNull ( match ) ;
222+ assert . strictEqual ( match [ 0 ] , "#!" ) ;
223+ assert . strictEqual ( match [ 1 ] , "" ) ;
224+ } ) ;
119225 } ) ;
120226} ) ;
0 commit comments