@@ -55,135 +55,66 @@ const match = (payload, pattern) => {
5555 return result ;
5656}
5757
58+ const test_leaf_values = ( ) => {
5859
59- const test_nested_objects_in_arrays = ( ) => {
6060 const payload = {
6161 "type" : "message" ,
62- "text" : "invite (Omar) (o@o.o) (foo) (batata)" ,
63- "blocks" : [
64- {
65- "number" : 1 ,
66- "bool" : true ,
67- "items" : [ 'ping ayman' , 'hi bassem' , 'sup yo' ]
68- } , {
69- "number" : 1 ,
70- "bool" : true ,
71- "some" : "ping mafsoum"
72- }
73- ]
62+ "text" : "text" ,
63+ "int" : 1 ,
64+ "bool" : true ,
65+ "float" : 1.1 ,
7466 }
7567
7668 const result = match ( payload , {
7769 "type" : "message" ,
78- "text" : / i n v i t e \( (?< name > \S + ) \) \( (?< email > \S + ) \) \( (?< company > \S + ) \) \( (?< role > \S + ) \) / ,
79- "blocks" : [
80- {
81- "number" : 1 ,
82- "bool" : true ,
83- "items" : [ / p i n g (?< name_other > \S + ) / , / h i (?< another > \S + ) / , / s u p y o / ]
84- } , {
85- "number" : 1 ,
86- "bool" : true ,
87- "some" : / p i n g (?< who > .* ) /
88- }
89- ]
70+ "text" : "text" ,
71+ "int" : 1 ,
72+ "bool" : true ,
73+ "float" : 1.1 ,
9074 } )
9175
9276 return JSON . stringify ( {
9377 match : true ,
94- total : 8 ,
78+ total : 5 ,
9579 matches : {
9680 "type" : "message" ,
97- "text" : "invite (Omar) (o@o.o) (foo) (batata)" ,
98- "blocks" : [
99- {
100- "number" : 1 ,
101- "bool" : true ,
102- "items" : [ 'ping ayman' , 'hi bassem' , 'sup yo' ]
103- } , {
104- "number" : 1 ,
105- "bool" : true ,
106- "some" : "ping mafsoum"
107- }
108- ]
81+ "text" : "text" ,
82+ "int" : 1 ,
83+ "bool" : true ,
84+ "float" : 1.1 ,
10985 } ,
110- groups : {
111- name : 'Omar' ,
112- email : 'o@o.o' ,
113- company : 'foo' ,
114- role : 'batata' ,
115- name_other : 'ayman' ,
116- another : 'bassem' ,
117- who : "mafsoum"
118- }
86+ groups : { }
11987 } ) == JSON . stringify ( result ) ;
88+
12089}
12190
122- const test_leaf_array_values_regex = ( ) => {
91+ const test_leaf_regex = ( ) => {
92+
12393 const payload = {
12494 "type" : "message" ,
125- "items " : [ 'ping ayman' , 'hi bassem' , 'sup yo' ]
95+ "text " : "invite (Omar) (o@o.o) (foo) (batata)" ,
12696 }
12797
12898 const result = match ( payload , {
12999 "type" : "message" ,
130- "items " : [ / p i n g ( ?<name > \S + ) / , / h i (?< another > \S + ) / , / s u p y o / ]
100+ "text " : / i n v i t e \( ( ?<name > \S + ) \) \( (?< email > \S + ) \) \( (?< company > \S + ) \) \( (?< role > \S + ) \) / ,
131101 } )
132102
133103 return JSON . stringify ( {
134104 match : true ,
135105 total : 2 ,
136106 matches : {
137107 "type" : "message" ,
138- "items " : [ 'ping ayman' , 'hi bassem' , 'sup yo' ]
108+ "text " : "invite (Omar) (o@o.o) (foo) (batata)" ,
139109 } ,
140110 groups : {
141- name : 'ayman' ,
142- another : 'bassem'
111+ name : 'Omar' ,
112+ email : 'o@o.o' ,
113+ company : 'foo' ,
114+ role : 'batata'
143115 }
144116 } ) == JSON . stringify ( result ) ;
145- }
146-
147- const test_leaf_array_values_multi_type = ( ) => {
148- const payload = {
149- "type" : "message" ,
150- "items" : [ true , 'hi' , 2 , 3 ]
151- }
152-
153- const result = match ( payload , {
154- "type" : "message" ,
155- "items" : [ true , 'hi' , 2 , 3 ]
156- } )
157117
158- return JSON . stringify ( {
159- match : true ,
160- total : 2 ,
161- matches : {
162- "type" : "message" ,
163- "items" : [ true , 'hi' , 2 , 3 ]
164- }
165- } ) == JSON . stringify ( result ) ;
166- }
167-
168- const test_leaf_array_values = ( ) => {
169- const payload = {
170- "type" : "message" ,
171- "items" : [ 0 , 1 , 2 , 3 ]
172- }
173-
174- const result = match ( payload , {
175- "type" : "message" ,
176- "items" : [ 0 , 1 , 3 ]
177- } )
178-
179- return JSON . stringify ( {
180- match : true ,
181- total : 2 ,
182- matches : {
183- "type" : "message" ,
184- "items" : [ 0 , 1 , 2 , 3 ]
185- }
186- } ) == JSON . stringify ( result ) ;
187118}
188119
189120const test_nested_objects = ( ) => {
@@ -241,67 +172,134 @@ const test_nested_objects = () => {
241172 } ) == JSON . stringify ( result ) ;
242173}
243174
175+ const test_leaf_array_values = ( ) => {
176+ const payload = {
177+ "type" : "message" ,
178+ "items" : [ 0 , 1 , 2 , 3 ]
179+ }
180+
181+ const result = match ( payload , {
182+ "type" : "message" ,
183+ "items" : [ 0 , 1 , 3 ]
184+ } )
185+
186+ return JSON . stringify ( {
187+ match : true ,
188+ total : 2 ,
189+ matches : {
190+ "type" : "message" ,
191+ "items" : [ 0 , 1 , 2 , 3 ]
192+ }
193+ } ) == JSON . stringify ( result ) ;
194+ }
244195
245- const test_leaf_regex = ( ) => {
246-
196+ const test_leaf_array_values_multi_type = ( ) => {
247197 const payload = {
248198 "type" : "message" ,
249- "text " : "invite (Omar) (o@o.o) (foo) (batata)" ,
199+ "items " : [ true , 'hi' , 2 , 3 ]
250200 }
251201
252202 const result = match ( payload , {
253203 "type" : "message" ,
254- "text " : / i n v i t e \( (?< name > \S + ) \) \( (?< email > \S + ) \) \( (?< company > \S + ) \) \( (?< role > \S + ) \) / ,
204+ "items " : [ true , 'hi' , 2 , 3 ]
255205 } )
256206
257207 return JSON . stringify ( {
258208 match : true ,
259209 total : 2 ,
260210 matches : {
261211 "type" : "message" ,
262- "text" : "invite (Omar) (o@o.o) (foo) (batata)" ,
263- } ,
264- groups : {
265- name : 'Omar' ,
266- email : 'o@o.o' ,
267- company : 'foo' ,
268- role : 'batata'
212+ "items" : [ true , 'hi' , 2 , 3 ]
269213 }
270214 } ) == JSON . stringify ( result ) ;
271-
272215}
273216
274- const test_leaf_values = ( ) => {
275-
217+ const test_leaf_array_values_regex = ( ) => {
276218 const payload = {
277219 "type" : "message" ,
278- "text" : "text" ,
279- "int" : 1 ,
280- "bool" : true ,
281- "float" : 1.1 ,
282- }
220+ "items" : [ 'ping ayman' , 'hi bassem' , 'sup yo' ]
221+ }
283222
284223 const result = match ( payload , {
285224 "type" : "message" ,
286- "text" : "text" ,
287- "int" : 1 ,
288- "bool" : true ,
289- "float" : 1.1 ,
290- } )
225+ "items" : [ / p i n g (?< name > \S + ) / , / h i (?< another > \S + ) / , / s u p y o / ]
226+ } )
291227
292228 return JSON . stringify ( {
293229 match : true ,
294- total : 5 ,
230+ total : 2 ,
295231 matches : {
296232 "type" : "message" ,
297- "text" : "text" ,
298- "int" : 1 ,
299- "bool" : true ,
300- "float" : 1.1 ,
301- } ,
302- groups : { }
303- } ) == JSON . stringify ( result ) ;
233+ "items" : [ 'ping ayman' , 'hi bassem' , 'sup yo' ]
234+ } ,
235+ groups : {
236+ name : 'ayman' ,
237+ another : 'bassem'
238+ }
239+ } ) == JSON . stringify ( result ) ;
240+ }
241+
242+ const test_nested_objects_in_arrays = ( ) => {
243+ const payload = {
244+ "type" : "message" ,
245+ "text" : "invite (Omar) (o@o.o) (foo) (batata)" ,
246+ "blocks" : [
247+ {
248+ "number" : 1 ,
249+ "bool" : true ,
250+ "items" : [ 'ping ayman' , 'hi bassem' , 'sup yo' ]
251+ } , {
252+ "number" : 1 ,
253+ "bool" : true ,
254+ "some" : "ping mafsoum"
255+ }
256+ ]
257+ }
258+
259+ const result = match ( payload , {
260+ "type" : "message" ,
261+ "text" : / i n v i t e \( (?< name > \S + ) \) \( (?< email > \S + ) \) \( (?< company > \S + ) \) \( (?< role > \S + ) \) / ,
262+ "blocks" : [
263+ {
264+ "number" : 1 ,
265+ "bool" : true ,
266+ "items" : [ / p i n g (?< name_other > \S + ) / , / h i (?< another > \S + ) / , / s u p y o / ]
267+ } , {
268+ "number" : 1 ,
269+ "bool" : true ,
270+ "some" : / p i n g (?< who > .* ) /
271+ }
272+ ]
273+ } )
304274
275+ return JSON . stringify ( {
276+ match : true ,
277+ total : 8 ,
278+ matches : {
279+ "type" : "message" ,
280+ "text" : "invite (Omar) (o@o.o) (foo) (batata)" ,
281+ "blocks" : [
282+ {
283+ "number" : 1 ,
284+ "bool" : true ,
285+ "items" : [ 'ping ayman' , 'hi bassem' , 'sup yo' ]
286+ } , {
287+ "number" : 1 ,
288+ "bool" : true ,
289+ "some" : "ping mafsoum"
290+ }
291+ ]
292+ } ,
293+ groups : {
294+ name : 'Omar' ,
295+ email : 'o@o.o' ,
296+ company : 'foo' ,
297+ role : 'batata' ,
298+ name_other : 'ayman' ,
299+ another : 'bassem' ,
300+ who : "mafsoum"
301+ }
302+ } ) == JSON . stringify ( result ) ;
305303}
306304
307305module . exports = {
0 commit comments