IntelliJ Platform Plugin SDK Help

2. Parsing Test

For more complex Lexers (e.g., having additional logic), it is advisable to add separate tests inheriting from LexerTestCase.

Update Grammar and Regenerate the Parser

Before creating the parsing test, ensure the parser definition (Simple.bnf) includes the lines shown below. These additional lines facilitate testing incorrect keys.

If the lines below are not present in Simple.bnf, replace the existing property definition with the lines below. Don't forget to regenerate the parser after updating the file! Right-click on the Simple.bnf file and select Generate Parser Code.

property ::= (KEY? SEPARATOR VALUE?) | KEY { pin=3 recoverWhile="recover_property" mixin="org.intellij.sdk.language.psi.impl.SimpleNamedElementImpl" implements="org.intellij.sdk.language.psi.SimpleNamedElement" methods=[getKey getValue getName setName getNameIdentifier getPresentation] } private recover_property ::= !(KEY|SEPARATOR|COMMENT)

Define Input Test Data

Create the ParsingTestData.simple properties file in the testData folder. Note the last few lines define a purposely incorrect key.

Copy the Expected PSI Tree

The easiest way to get the expected PSI structure for any file is to use the PSI Viewer. Run the project and use .

PSI Tree Copy

Use the Copy PSI button to copy the expected PSI structure to the clipboard.

Define the Output Reference Test Data

Create a file ParsingTestData.txt with the copied PSI tree.

Define a Parsing Test

Subclass ParsingTestCase to create SimpleParsingTest: Override getTestDataPath(), and return the path from the root of this plugin module to the testData directory.

Run the Test

Run tests by:

  • Opening the Gradle Tool Window.

  • Select the simple_language_plugin node. You may need to reimport it as a Gradle project.

  • Drill down under simple_language_plugin to Tasks, verification, test task.

  • Run the test task.

The results are displayed in the Run Tool Window, and also written to the simple_language_plugin/build/test-results/test directory.

If the Run Tool Window displays the error Test events were not received, do the following:

  • In the Gradle Tool Window, drill down under simple_language_plugin to Tasks, build, clean task.

  • Run the clean task, which deletes the simple_language_plugin/build directory.

  • Restart the test.

Last modified: 29 九月 2022