@@ -17,6 +17,7 @@ let counter = 0;
1717 * @typedef {object } TestCounts
1818 * @prop {number } valid
1919 * @prop {number } invalid
20+ * @prop {number } total
2021 * @prop {string } grammarPath
2122 * @prop {string } modifiedPath
2223 */
@@ -61,6 +62,20 @@ let counter = 0;
6162 * @typedef {import('peggy').Location } Location
6263 */
6364
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+
6479/**
6580 * @template T
6681 * @param {Parser } grammar
@@ -101,9 +116,8 @@ function checkParserStarts(grammar, starts, modified, counts) {
101116 ...options ,
102117 } ) ;
103118 } 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 ;
107121 }
108122 if ( typeof expected === "string" ) {
109123 equal ( res , expected , `${ source } (eq): "${ start . validInput } "` ) ;
@@ -175,6 +189,7 @@ function checkParserStarts(grammar, starts, modified, counts) {
175189 } ) ) ;
176190 }
177191 counts . valid ++ ;
192+ counts . total ++ ;
178193 }
179194
180195 if ( typeof start . invalidInput === "string" ) {
@@ -221,6 +236,7 @@ function checkParserStarts(grammar, starts, modified, counts) {
221236 equal ( typeof fmt , "string" ) ;
222237 }
223238 counts . invalid ++ ;
239+ counts . total ++ ;
224240 }
225241 }
226242}
@@ -270,6 +286,7 @@ export async function testPeggy(grammarUrl, starts, opts) {
270286 const counts = {
271287 valid : 0 ,
272288 invalid : 0 ,
289+ total : 0 ,
273290 grammarPath,
274291 modifiedPath,
275292 } ;
0 commit comments