@@ -1215,27 +1215,79 @@ describe("unicode flag", () => {
1215
1215
describe ( 'ignoreCase flag' , ( ) => {
1216
1216
1217
1217
test ( "allows all rules to be /i" , ( ) => {
1218
- expect ( ( ) => compile ( { a : / f o o / i, b : / b a r / i, c : "quxx" } ) ) . not . toThrow ( )
1219
- expect ( ( ) => compile ( { a : / f o o / i, b : / b a r / , c : "quxx" } ) ) . toThrow ( "If one rule is /i then all must be" )
1220
- expect ( ( ) => compile ( { a : / f o o / , b : / b a r / i, c : "quxx" } ) ) . toThrow ( "If one rule is /i then all must be" )
1218
+ expect ( ( ) => compile ( { a : / f o o / i, b : / b a r / i } ) ) . not . toThrow ( )
1219
+ expect ( ( ) => compile ( { a : / f o o / i, b : / b a r / } ) ) . toThrow ( "If one rule is /i then all must be" )
1220
+ expect ( ( ) => compile ( { a : / f o o / , b : / b a r / i } ) ) . toThrow ( "If one rule is /i then all must be" )
1221
1221
} )
1222
1222
1223
1223
test ( "allows all rules to be /ui" , ( ) => {
1224
- expect ( ( ) => compile ( { a : / f o o / ui, b : / b a r / ui, c : "quxx" } ) ) . not . toThrow ( )
1225
- expect ( ( ) => compile ( { a : / f o o / u, b : / b a r / i, c : "quxx" } ) ) . toThrow ( "If one rule is /i then all must be" )
1226
- expect ( ( ) => compile ( { a : / f o o / i, b : / b a r / u, c : "quxx" } ) ) . toThrow ( "If one rule is /i then all must be" )
1227
- expect ( ( ) => compile ( { a : / f o o / ui, b : / b a r / i, c : "quxx" } ) ) . toThrow ( "If one rule is /u then all must be" )
1228
- expect ( ( ) => compile ( { a : / f o o / ui, b : / b a r / u, c : "quxx" } ) ) . toThrow ( "If one rule is /i then all must be" )
1229
- expect ( ( ) => compile ( { a : / f o o / i, b : / b a r / ui, c : "quxx" } ) ) . toThrow ( "If one rule is /u then all must be" )
1230
- expect ( ( ) => compile ( { a : / f o o / u, b : / b a r / ui, c : "quxx" } ) ) . toThrow ( "If one rule is /i then all must be" )
1224
+ expect ( ( ) => compile ( { a : / f o o / ui, b : / b a r / ui } ) ) . not . toThrow ( )
1225
+ expect ( ( ) => compile ( { a : / f o o / u, b : / b a r / i } ) ) . toThrow ( "If one rule is /u then all must be" )
1226
+ expect ( ( ) => compile ( { a : / f o o / i, b : / b a r / u } ) ) . toThrow ( "If one rule is /u then all must be" )
1227
+ expect ( ( ) => compile ( { a : / f o o / ui, b : / b a r / i } ) ) . toThrow ( "If one rule is /u then all must be" )
1228
+ expect ( ( ) => compile ( { a : / f o o / ui, b : / b a r / u } ) ) . toThrow ( "If one rule is /i then all must be" )
1229
+ expect ( ( ) => compile ( { a : / f o o / i, b : / b a r / ui } ) ) . toThrow ( "If one rule is /u then all must be" )
1230
+ expect ( ( ) => compile ( { a : / f o o / u, b : / b a r / ui } ) ) . toThrow ( "If one rule is /i then all must be" )
1231
+ } )
1232
+
1233
+ test ( "allow literals to be marked ignoreCase" , ( ) => {
1234
+ expect ( ( ) => compile ( {
1235
+ a : / f o o / i,
1236
+ lit : { match : "quxx" , ignoreCase : true } ,
1237
+ } ) ) . not . toThrow ( )
1238
+ expect ( ( ) => compile ( [
1239
+ { type : "a" , match : / f o o / i } ,
1240
+ { type : "lit" , match : "quxx" , ignoreCase : true } ,
1241
+ ] ) ) . not . toThrow ( )
1242
+ } )
1243
+
1244
+ test ( "require literals to be marked ignoreCase" , ( ) => {
1245
+ expect ( ( ) => compile ( {
1246
+ a : / f o o / i,
1247
+ lit : "quxx" ,
1248
+ } ) ) . toThrow ( "Literal must be marked with {ignoreCase: true} (in token 'lit')" )
1249
+ expect ( ( ) => compile ( [
1250
+ { type : "a" , match : / f o o / i } ,
1251
+ { type : "lit" , match : "quxx" } ,
1252
+ ] ) ) . toThrow ( "Literal must be marked with {ignoreCase: true} (in token 'lit')" )
1253
+ } )
1254
+
1255
+ test ( "ignoreCase is only required when case is relevant" , ( ) => {
1256
+ expect ( ( ) => compile ( {
1257
+ cat : { match : "cat" , ignoreCase : true } ,
1258
+ bat : { match : "BAT" , ignoreCase : true } ,
1259
+ comma : ',' ,
1260
+ semi : ';' ,
1261
+ lparen : '(' ,
1262
+ rparen : ')' ,
1263
+ lbrace : '{' ,
1264
+ rbrace : '}' ,
1265
+ lbracket : '[' ,
1266
+ rbracket : ']' ,
1267
+ and : '&&' ,
1268
+ or : '||' ,
1269
+ bitand : '&' ,
1270
+ bitor : '|' ,
1271
+ } ) ) . not . toThrow ( )
1272
+ } )
1273
+
1274
+ test ( "require ignoreCase option to be match RegExp flags" , ( ) => {
1275
+ expect ( ( ) => compile ( {
1276
+ word : { match : / [ a - z ] + / , ignoreCase : true } ,
1277
+ } ) ) . toThrow ( "ignoreCase option must match RegExp flags" )
1278
+ expect ( ( ) => compile ( {
1279
+ word : { match : [ "foo" , / [ a - z ] + / ] , ignoreCase : true } ,
1280
+ } ) ) . toThrow ( "ignoreCase option must match RegExp flags" )
1281
+ expect ( ( ) => compile ( {
1282
+ word : { match : / [ a - z ] + / i, ignoreCase : false } ,
1283
+ } ) ) . toThrow ( "ignoreCase option must match RegExp flags" )
1231
1284
} )
1232
1285
1233
1286
test ( "supports ignoreCase" , ( ) => {
1234
- const lexer = compile ( { a : / f o o / i, b : / b a r / i, c : "quxx" } )
1235
- lexer . reset ( "FoObArQuXx " )
1287
+ const lexer = compile ( { a : / f o o / i, b : / b a r / i, } )
1288
+ lexer . reset ( "FoObAr " )
1236
1289
expect ( lexer . next ( ) ) . toMatchObject ( { value : "FoO" } )
1237
1290
expect ( lexer . next ( ) ) . toMatchObject ( { value : "bAr" } )
1238
- expect ( lexer . next ( ) ) . toMatchObject ( { value : "QuXx" } )
1239
1291
} )
1240
1292
1241
1293
} )
0 commit comments