Concerns about grammar test

I’ve already looked at how grammar unit testing is done in lezer/javascript:

Based on the examples above, if I want to test my own grammar, I need to prepare files in the following format:

# <maybe test case name>

<code here>

==>

<grammar node here>

Then, in a TypeScript test file, I use the fileTests function to run the test.

My question is:
Is this the only way to do it? Because this approach requires me to manually write the <grammar node> structure in every test file.
Is there a way to test using my defined grammar directly—without manually writing the <grammar node> each time?

You can, of course, just call the parser and do testing in a different way.

I don’t understand what that means though. You’ll need some kind of structure to test against to make sure the parser actually does what you want.

@marijn I mean for this example:

# Variable declaration

var a = b
  , c = d;
const [x] = y = 3;

==>

Script(
  VariableDeclaration(var,VariableDefinition,Equals,VariableName,VariableDefinition,Equals,VariableName),
  VariableDeclaration(const,ArrayPattern(VariableDefinition),Equals,AssignmentExpression(VariableName,Equals,Number)))

I should write this part manually,

Script(
  VariableDeclaration(var,VariableDefinition,Equals,VariableName,VariableDefinition,Equals,VariableName),
  VariableDeclaration(const,ArrayPattern(VariableDefinition),Equals,AssignmentExpression(VariableName,Equals,Number)))

And I want to use the existing grammar to test a code snippet, and don’t want to write the expecting part for every unit test. :grinning_face: