@@ -38,7 +38,6 @@ function buildData(lines) {
3838 captures : { }
3939 }
4040 let inCapture = false
41- let captures = null // Remember captures' name and index.
4241
4342 lines . forEach ( ( line ) => {
4443 if ( line === '' || line . startsWith ( '#' ) ) {
@@ -50,12 +49,7 @@ function buildData(lines) {
5049 }
5150
5251 if ( line . startsWith ( 'srl: ' ) ) {
53- captures = [ ]
54-
55- data . srl = line . substr ( 5 ) . replace ( / a s \s + " ( [ ^ " ] + ) " / g, ( s , c ) => {
56- captures . push ( c )
57- return ''
58- } )
52+ data . srl = line . substr ( 5 )
5953 } else if ( line . startsWith ( 'match: "' ) ) {
6054 data . matches . push ( applySpecialChars ( line . slice ( 8 , - 1 ) ) )
6155 } else if ( line . startsWith ( 'no match: "' ) ) {
@@ -66,23 +60,15 @@ function buildData(lines) {
6660 ) {
6761 inCapture = line . slice ( 13 , - 2 )
6862 data . captures [ inCapture ] = [ ]
69- } else if (
70- inCapture &&
71- line . startsWith ( '-' )
72- ) {
63+ } else if ( inCapture && line . startsWith ( '-' ) ) {
7364 const split = line . substr ( 1 ) . split ( ': ' )
74- const index = captures . indexOf ( split [ 1 ] . trim ( ) )
7565 let target = data . captures [ inCapture ] [ Number ( split [ 0 ] ) ]
7666
7767 if ( ! target ) {
7868 target = data . captures [ inCapture ] [ Number ( split [ 0 ] ) ] = [ ]
7969 }
8070
81- if ( index !== - 1 ) {
82- target [ index ] = applySpecialChars ( split [ 2 ] . slice ( 1 , - 1 ) )
83- } else {
84- target . push ( applySpecialChars ( split [ 2 ] . slice ( 1 , - 1 ) ) )
85- }
71+ target [ split [ 1 ] ] = applySpecialChars ( split [ 2 ] . slice ( 1 , - 1 ) )
8672 }
8773 } )
8874
@@ -133,15 +119,26 @@ function runAssertions(data) {
133119 )
134120
135121 matches . forEach ( ( capture , index ) => {
136- const result = Array . from ( capture ) . slice ( 1 ) . map ( ( item ) => {
137- return item === undefined ? '' : item
138- } )
139-
140- assert . deepEqual (
141- result ,
142- expected [ index ] ,
143- `The capture group did not return the expected results for test ${ test } .${ getExpression ( data . srl , query ) } `
144- )
122+ // const result = Array.from(capture).slice(1).map((item) => {
123+ // return item === undefined ? '' : item
124+ // })
125+ const item = expected [ index ]
126+
127+ for ( let key in item ) {
128+ if ( typeof key === 'number' ) {
129+ assert . equal (
130+ capture [ key + 1 ] ,
131+ item [ key ] ,
132+ `The capture group did not return the expected results for test ${ test } .${ getExpression ( data . srl , query ) } `
133+ )
134+ } else {
135+ assert . equal (
136+ capture [ key ] ,
137+ item [ key ] ,
138+ `The capture group did not return the expected results for test ${ test } .${ getExpression ( data . srl , query ) } `
139+ )
140+ }
141+ }
145142 } )
146143
147144 assertionMade = true
0 commit comments