@@ -38,7 +38,6 @@ function buildData(lines) {
38
38
captures : { }
39
39
}
40
40
let inCapture = false
41
- let captures = null // Remember captures' name and index.
42
41
43
42
lines . forEach ( ( line ) => {
44
43
if ( line === '' || line . startsWith ( '#' ) ) {
@@ -50,12 +49,7 @@ function buildData(lines) {
50
49
}
51
50
52
51
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 )
59
53
} else if ( line . startsWith ( 'match: "' ) ) {
60
54
data . matches . push ( applySpecialChars ( line . slice ( 8 , - 1 ) ) )
61
55
} else if ( line . startsWith ( 'no match: "' ) ) {
@@ -66,23 +60,15 @@ function buildData(lines) {
66
60
) {
67
61
inCapture = line . slice ( 13 , - 2 )
68
62
data . captures [ inCapture ] = [ ]
69
- } else if (
70
- inCapture &&
71
- line . startsWith ( '-' )
72
- ) {
63
+ } else if ( inCapture && line . startsWith ( '-' ) ) {
73
64
const split = line . substr ( 1 ) . split ( ': ' )
74
- const index = captures . indexOf ( split [ 1 ] . trim ( ) )
75
65
let target = data . captures [ inCapture ] [ Number ( split [ 0 ] ) ]
76
66
77
67
if ( ! target ) {
78
68
target = data . captures [ inCapture ] [ Number ( split [ 0 ] ) ] = [ ]
79
69
}
80
70
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 ) )
86
72
}
87
73
} )
88
74
@@ -133,15 +119,26 @@ function runAssertions(data) {
133
119
)
134
120
135
121
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
+ }
145
142
} )
146
143
147
144
assertionMade = true
0 commit comments