@@ -17,6 +17,7 @@ let counter = 0;
17
17
* @typedef {object } TestCounts
18
18
* @prop {number } valid
19
19
* @prop {number } invalid
20
+ * @prop {number } total
20
21
* @prop {string } grammarPath
21
22
* @prop {string } modifiedPath
22
23
*/
@@ -61,6 +62,20 @@ let counter = 0;
61
62
* @typedef {import('peggy').Location } Location
62
63
*/
63
64
65
+ /**
66
+ * Add the formatted information to the given error.
67
+ *
68
+ * @param {unknown } e
69
+ * @param {string } source
70
+ * @param {string } text
71
+ */
72
+ function format ( e , source , text ) {
73
+ const er = /** @type {import('peggy').parser.SyntaxError } */ ( e ) ;
74
+ if ( typeof er ?. format === "function" ) {
75
+ er . message = er . format ( [ { source, text } ] ) ;
76
+ }
77
+ }
78
+
64
79
/**
65
80
* @template T
66
81
* @param {Parser } grammar
@@ -101,9 +116,8 @@ function checkParserStarts(grammar, starts, modified, counts) {
101
116
...options ,
102
117
} ) ;
103
118
} catch ( er ) {
104
- const e = /** @type {import('peggy').parser.SyntaxError } */ ( er ) ;
105
- e . message = e . format ( [ { source, text : start . validInput } ] ) ;
106
- throw e ;
119
+ format ( er , source , start . validInput ) ;
120
+ throw er ;
107
121
}
108
122
if ( typeof expected === "string" ) {
109
123
equal ( res , expected , `${ source } (eq): "${ start . validInput } "` ) ;
@@ -175,6 +189,7 @@ function checkParserStarts(grammar, starts, modified, counts) {
175
189
} ) ) ;
176
190
}
177
191
counts . valid ++ ;
192
+ counts . total ++ ;
178
193
}
179
194
180
195
if ( typeof start . invalidInput === "string" ) {
@@ -221,6 +236,7 @@ function checkParserStarts(grammar, starts, modified, counts) {
221
236
equal ( typeof fmt , "string" ) ;
222
237
}
223
238
counts . invalid ++ ;
239
+ counts . total ++ ;
224
240
}
225
241
}
226
242
}
@@ -270,6 +286,7 @@ export async function testPeggy(grammarUrl, starts, opts) {
270
286
const counts = {
271
287
valid : 0 ,
272
288
invalid : 0 ,
289
+ total : 0 ,
273
290
grammarPath,
274
291
modifiedPath,
275
292
} ;
0 commit comments