@@ -1119,7 +1119,7 @@ it(`should use the cache argument`, async () => {
1119
1119
it ( `handles the regex operator without flags` , async ( ) => {
1120
1120
const needleStr = `/^The.*Wax/`
1121
1121
const needleRex = / ^ T h e .* W a x /
1122
- const [ result , allNodes ] = await runSlowFilter ( {
1122
+ const [ result , allNodes ] = await runFastFilter ( {
1123
1123
name : { regex : needleStr } ,
1124
1124
} )
1125
1125
@@ -1136,7 +1136,46 @@ it(`should use the cache argument`, async () => {
1136
1136
// Note: needle is different from checked because `new RegExp('/a/i')` does _not_ work
1137
1137
const needleRex = / ^ t h e .* w a x / i
1138
1138
const needleStr = `/^the.*wax/i`
1139
- const [ result , allNodes ] = await runSlowFilter ( {
1139
+ const [ result , allNodes ] = await runFastFilter ( {
1140
+ name : { regex : needleStr } ,
1141
+ } )
1142
+
1143
+ expect ( result ?. length ) . toEqual (
1144
+ allNodes . filter ( node => needleRex . test ( node . name ) ) . length
1145
+ )
1146
+ expect ( result ?. length ) . toBeGreaterThan ( 0 ) // Make sure there _are_ results, don't let this be zero
1147
+ result . forEach ( node =>
1148
+ expect ( needleRex . test ( node . name ) ) . toEqual ( true )
1149
+ )
1150
+ } )
1151
+
1152
+ it ( `rejects strings without forward slashes` , async ( ) => {
1153
+ await expect (
1154
+ runFastFilter ( {
1155
+ name : { regex : `^The.*Wax` } ,
1156
+ } )
1157
+ ) . rejects . toThrow ( )
1158
+ } )
1159
+
1160
+ it ( `rejects strings without trailing slash` , async ( ) => {
1161
+ await expect (
1162
+ runFastFilter ( {
1163
+ name : { regex : `/^The.*Wax` } ,
1164
+ } )
1165
+ ) . rejects . toThrow ( )
1166
+ } )
1167
+
1168
+ it ( `accepts strings without leading slash` , async ( ) => {
1169
+ // If this test starts failing, that might be okay and it should be dropped.
1170
+ // At the time of writing it, this was a status quo edge case for Sift
1171
+
1172
+ // Passes because the requirement is mostly about a .split() failing
1173
+ // for the other fail cases. As long as it passes a regex ultimately
1174
+ // we don't really have to care / validate.
1175
+
1176
+ const needleRex = / (?: ) / i // This was what it turned into
1177
+ const needleStr = `^the.*wax/i`
1178
+ const [ result , allNodes ] = await runFastFilter ( {
1140
1179
name : { regex : needleStr } ,
1141
1180
} )
1142
1181
@@ -1149,22 +1188,34 @@ it(`should use the cache argument`, async () => {
1149
1188
)
1150
1189
} )
1151
1190
1152
- it ( `handles the nested regex operator` , async ( ) => {
1191
+ it ( `rejects actual regex` , async ( ) => {
1192
+ await expect (
1193
+ runFastFilter ( {
1194
+ name : { regex : / ^ T h e .* W a x / } ,
1195
+ } )
1196
+ ) . rejects . toThrow ( )
1197
+ } )
1198
+
1199
+ it ( `handles the nested regex operator and ignores partial paths` , async ( ) => {
1153
1200
const needleStr = `/.*/`
1154
1201
const needleRex = / .* /
1155
- const [ result , allNodes ] = await runSlowFilter ( {
1202
+ const [ result , allNodes ] = await runFastFilter ( {
1156
1203
nestedRegex : { field : { regex : needleStr } } ,
1157
1204
} )
1158
1205
1159
1206
expect ( result ?. length ) . toEqual (
1160
1207
allNodes . filter (
1161
- node => node . nestedRegex && needleRex . test ( node . nestedRegex . field )
1208
+ node =>
1209
+ node . nestedRegex !== undefined &&
1210
+ node . nestedRegex . field !== undefined &&
1211
+ needleRex . test ( node . nestedRegex . field )
1162
1212
) . length
1163
1213
)
1164
1214
expect ( result ?. length ) . toBeGreaterThan ( 0 ) // Make sure there _are_ results, don't let this be zero
1165
1215
result . forEach ( node =>
1166
1216
expect (
1167
- node . nestedRegex && needleRex . test ( node . nestedRegex . field )
1217
+ node . nestedRegex === undefined ||
1218
+ needleRex . test ( node . nestedRegex . field )
1168
1219
) . toEqual ( true )
1169
1220
)
1170
1221
} )
@@ -1726,8 +1777,10 @@ it(`should use the cache argument`, async () => {
1726
1777
} )
1727
1778
1728
1779
describe ( `$glob` , ( ) => {
1780
+ // Note: glob internally uses $regex
1781
+
1729
1782
it ( `handles the glob operator` , async ( ) => {
1730
- const [ result ] = await runSlowFilter ( { name : { glob : `*Wax` } } )
1783
+ const [ result ] = await runFastFilter ( { name : { glob : `*Wax` } } )
1731
1784
1732
1785
expect ( result . length ) . toEqual ( 2 )
1733
1786
expect ( result [ 0 ] . name ) . toEqual ( `The Mad Wax` )
0 commit comments