@@ -7,7 +7,6 @@ const match = (payload, pattern) => {
77 Object . entries ( pattern ) . forEach ( ( [ key , value ] ) => {
88 if ( value instanceof RegExp ) {
99 const matcher = payload [ key ] . match ( value ) || [ ] ;
10-
1110 if ( matcher . length > 0 ) {
1211 result . groups = { ...result . groups , ...matcher . groups } ;
1312 current_node [ key ] = payload [ key ] ;
@@ -21,25 +20,25 @@ const match = (payload, pattern) => {
2120 if ( element instanceof RegExp ) {
2221 const matcher = payload [ key ] [ index ] . match ( element ) || [ ] ;
2322 if ( matcher . length > 0 ) {
24- result . groups = { ...result , ...matcher . groups } ;
23+ result . groups = { ...result . groups , ...matcher . groups } ;
24+ current_node [ key ] = payload [ key ] ;
25+ result . total += 1 ;
2526 } else {
2627 result . match = false ;
2728 }
2829 } else if ( element instanceof Object ) {
29- tester ( payload [ key ] [ index ] , element ) ;
30+ current_node [ key ] [ index ] = { } ;
31+ tester ( payload [ key ] [ index ] , element , current_node [ key ] [ index ] ) ;
3032 } else if ( payload [ key ] . includes ( element ) ) {
3133 current_node [ key ] [ index ] = element ;
3234 result . total += 1 ;
3335 } else {
3436 result . match = false ;
3537 }
3638 } ) ;
37-
3839 } else if ( value instanceof Object ) {
39-
4040 current_node [ key ] = { } ;
4141 tester ( payload [ key ] , value , current_node [ key ] ) ;
42-
4342 } else {
4443 if ( payload [ key ] != value ) {
4544 result . match = false ;
@@ -221,16 +220,16 @@ const test_leaf_array_values_regex = () => {
221220 const payload = {
222221 "type" : "message" ,
223222 "items" : [ 'ping ayman' , 'hi bassem' , 'sup yo' ]
224- }
223+ }
225224
226225 const result = match ( payload , {
227226 "type" : "message" ,
228227 "items" : [ / p i n g (?< name > \S + ) / , / h i (?< another > \S + ) / , / s u p y o / ]
229- } )
228+ } )
230229
231230 return JSON . stringify ( {
232231 match : true ,
233- total : 2 ,
232+ total : 4 ,
234233 matches : {
235234 "type" : "message" ,
236235 "items" : [ 'ping ayman' , 'hi bassem' , 'sup yo' ]
@@ -239,7 +238,7 @@ const test_leaf_array_values_regex = () => {
239238 name : 'ayman' ,
240239 another : 'bassem'
241240 }
242- } ) == JSON . stringify ( result ) ;
241+ } ) == JSON . stringify ( result ) ;
243242}
244243
245244const test_nested_objects_in_arrays = ( ) => {
@@ -252,7 +251,7 @@ const test_nested_objects_in_arrays = () => {
252251 "bool" : true ,
253252 "items" : [ 'ping ayman' , 'hi bassem' , 'sup yo' ]
254253 } , {
255- "number " : 1 ,
254+ "integer " : 1 ,
256255 "bool" : true ,
257256 "some" : "ping mafsoum"
258257 }
@@ -268,16 +267,16 @@ const test_nested_objects_in_arrays = () => {
268267 "bool" : true ,
269268 "items" : [ / p i n g (?< name_other > \S + ) / , / h i (?< another > \S + ) / , / s u p y o / ]
270269 } , {
271- "number " : 1 ,
270+ "integer " : 1 ,
272271 "bool" : true ,
273272 "some" : / p i n g (?< who > .* ) /
274273 }
275274 ]
276- } )
275+ } )
277276
278277 return JSON . stringify ( {
279278 match : true ,
280- total : 8 ,
279+ total : 10 ,
281280 matches : {
282281 "type" : "message" ,
283282 "text" : "invite (Omar) (o@o.o) (foo) (batata)" ,
@@ -287,7 +286,7 @@ const test_nested_objects_in_arrays = () => {
287286 "bool" : true ,
288287 "items" : [ 'ping ayman' , 'hi bassem' , 'sup yo' ]
289288 } , {
290- "number " : 1 ,
289+ "integer " : 1 ,
291290 "bool" : true ,
292291 "some" : "ping mafsoum"
293292 }
@@ -302,7 +301,7 @@ const test_nested_objects_in_arrays = () => {
302301 another : 'bassem' ,
303302 who : "mafsoum"
304303 }
305- } ) == JSON . stringify ( result ) ;
304+ } ) == JSON . stringify ( result ) ;
306305}
307306
308307module . exports = {
@@ -312,7 +311,7 @@ module.exports = {
312311 test_nested_objects,
313312 test_leaf_array_values,
314313 test_leaf_array_values_multi_type,
315- // test_leaf_array_values_regex,
316- // test_nested_objects_in_arrays,
314+ test_leaf_array_values_regex,
315+ test_nested_objects_in_arrays,
317316 }
318317}
0 commit comments