@@ -317,6 +317,22 @@ describe 'PHP grammar', ->
317
317
expect (tokens[9 ]).toEqual value : ' :' , scopes : [" source.php" , " keyword.operator.ternary.php" ]
318
318
expect (tokens[12 ]).toEqual value : ' ::' , scopes : [" source.php" , " keyword.operator.class.php" ]
319
319
320
+ it ' should NOT tokenize a ternary statement as a goto label' , ->
321
+ # See https://github.com/atom/language-php/issues/386
322
+ lines = grammar .tokenizeLines '''
323
+ $a ?
324
+ null :
325
+ $b
326
+ '''
327
+
328
+ expect (lines[0 ][0 ]).toEqual value : ' $' , scopes : [' source.php' , ' variable.other.php' , ' punctuation.definition.variable.php' ]
329
+ expect (lines[0 ][1 ]).toEqual value : ' a' , scopes : [' source.php' , ' variable.other.php' ]
330
+ expect (lines[0 ][3 ]).toEqual value : ' ?' , scopes : [' source.php' , ' keyword.operator.ternary.php' ]
331
+ expect (lines[1 ][1 ]).toEqual value : ' null' , scopes : [' source.php' , ' constant.language.php' ]
332
+ expect (lines[1 ][3 ]).toEqual value : ' :' , scopes : [' source.php' , ' keyword.operator.ternary.php' ]
333
+ expect (lines[2 ][1 ]).toEqual value : ' $' , scopes : [' source.php' , ' variable.other.php' , ' punctuation.definition.variable.php' ]
334
+ expect (lines[2 ][2 ]).toEqual value : ' b' , scopes : [' source.php' , ' variable.other.php' ]
335
+
320
336
describe ' identifiers' , ->
321
337
it ' tokenizes identifiers with only letters' , ->
322
338
{tokens } = grammar .tokenizeLine ' $abc'
@@ -1152,6 +1168,33 @@ describe 'PHP grammar', ->
1152
1168
expect (tokens[8 ]).toEqual value : " '" , scopes : [' source.php' , ' meta.function-call.php' , ' string.quoted.single.php' , ' punctuation.definition.string.end.php' ]
1153
1169
expect (tokens[9 ]).toEqual value : ' )' , scopes : [' source.php' , ' meta.function-call.php' , ' punctuation.definition.arguments.end.bracket.round.php' ]
1154
1170
1171
+ it ' tokenizes function calls with named arguments' , ->
1172
+ {tokens } = grammar .tokenizeLine ' doSomething($a ? null : true, b: $b);'
1173
+
1174
+ expect (tokens[0 ]).toEqual value : ' doSomething' , scopes : [' source.php' , ' meta.function-call.php' , ' entity.name.function.php' ]
1175
+ expect (tokens[14 ]).toEqual value : ' b' , scopes : [' source.php' , ' meta.function-call.php' , ' entity.name.variable.parameter.php' ]
1176
+ expect (tokens[15 ]).toEqual value : ' :' , scopes : [' source.php' , ' meta.function-call.php' , ' punctuation.separator.colon.php' ]
1177
+ # ternary should be still tokenized
1178
+ expect (tokens[7 ]).toEqual value : ' null' , scopes : [' source.php' , ' meta.function-call.php' , ' constant.language.php' ]
1179
+ expect (tokens[9 ]).toEqual value : ' :' , scopes : [' source.php' , ' meta.function-call.php' , ' keyword.operator.ternary.php' ]
1180
+
1181
+ it ' tokenizes multiline function calls with named arguments' , ->
1182
+ lines = grammar .tokenizeLines '''
1183
+ doSomething(
1184
+ x: $a ?
1185
+ null : true,
1186
+ a: $b);
1187
+ '''
1188
+
1189
+ expect (lines[0 ][0 ]).toEqual value : ' doSomething' , scopes : [' source.php' , ' meta.function-call.php' , ' entity.name.function.php' ]
1190
+ expect (lines[1 ][1 ]).toEqual value : ' x' , scopes : [' source.php' , ' meta.function-call.php' , ' entity.name.variable.parameter.php' ]
1191
+ expect (lines[1 ][2 ]).toEqual value : ' :' , scopes : [' source.php' , ' meta.function-call.php' , ' punctuation.separator.colon.php' ]
1192
+ expect (lines[3 ][1 ]).toEqual value : ' a' , scopes : [' source.php' , ' meta.function-call.php' , ' entity.name.variable.parameter.php' ]
1193
+ expect (lines[3 ][2 ]).toEqual value : ' :' , scopes : [' source.php' , ' meta.function-call.php' , ' punctuation.separator.colon.php' ]
1194
+ # ternary should be still tokenized
1195
+ expect (lines[2 ][1 ]).toEqual value : ' null' , scopes : [' source.php' , ' meta.function-call.php' , ' constant.language.php' ]
1196
+ expect (lines[2 ][3 ]).toEqual value : ' :' , scopes : [' source.php' , ' meta.function-call.php' , ' keyword.operator.ternary.php' ]
1197
+
1155
1198
it ' tokenizes builtin function calls' , ->
1156
1199
{tokens } = grammar .tokenizeLine " echo('Hi!')"
1157
1200
0 commit comments