ReSharper Platform SDK
 
Because ReSharper Platform SDK undefined is still in development, this documentation may not be entirely accurate and is subject to change.

Testing Parsers

Last modified: 04 July 2023

The ParserTestBase<TLanguage> can be used to create tests for a parser of a specific language. It derives from BaseTestWithTextControl, which means it will create an in-memory ReSharper instance, with a solution and a project loaded. The test will load a specific text file into an in-memory text control, parse it, retrieve any IFile instances that match TLanguage, and compare the results against a .gold file.

The .gold file will be the IFile and children, written as an indented text file. Each line will be another node in the tree, with the text being the result of calling ToString() on the node instance.

For example, given the following CSS file - test01.css:

Then the test01.css.gold file would be something like:

Note that the PSI tree includes comments and whitespace.

Also note that the input file contains a {caret} text. The ParserTestBase<T> class finds the file to test by looking for the current text caret location, as defined by special strings in the file. Here, it is looking for {caret} to know which file should be processed. This means that all input files require the {caret} text to be added to the file. See below for an alternative implementation that doesn't require {caret} in the input file.