You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running unit tests against grammar definitions, I currently do the following:
asyncfunctioncompileGrammarText(text: string){returnnewPromise<CompiledRules>((res,rej)=>{constproc=exec('npx nearleyc -q',(err,stdout,stderr)=>{if(err)rej(stderr)constwindow={grammar: null}Function("window",stdout)(window)res(window.grammar)})proc.stdin.write(text)proc.stdin.end()})}describe('DEFINITION_NAME',()=>{
let parser: Parser
let initState: anybefore(async()=>{constgrammar=awaitUtils.compileGrammarText(` @include "${__dirname}/grammar.ne" input -> DEFINITION_NAME {% id %} `)parser=newParser(Grammar.fromCompiled(grammar))initState=parser.save()})beforeEach(()=>parser.restore(initState))tests.forEach(test=>{it(`should parse "${test.value}"`,()=>{parser.feed(test.value)expect(parser.results).to.deep.equal(test.expected)})})})
For 500 or so unit tests, this can take about 30 seconds or more to run - most of that time being spent piping data to and from nearleyc. If/when I get some time, I'd like to abstract the compiler logic from nearleyc's IO and expose it as part of the library's API.
The text was updated successfully, but these errors were encountered:
When running unit tests against grammar definitions, I currently do the following:
For 500 or so unit tests, this can take about 30 seconds or more to run - most of that time being spent piping data to and from
nearleyc
. If/when I get some time, I'd like to abstract the compiler logic fromnearleyc
's IO and expose it as part of the library's API.The text was updated successfully, but these errors were encountered: