This client uses vscode-tmgrammar-test mentioned in Microsoft's vscode-textmate as the framework for testing TextMate grammars.
npm run test:grammar
To quickly add test cases, follow the steps below:
- create a file (e.g
file-name.bb
) intest/grammars/snaps
containing only the code you wish to use as test cases. It is recommended to use space to separate each piece of the code.
foo () {}
VAR = '123'
- Take snapshots of the scopes by running
npm run snap-grammar
- A
.snap
file will be created and it will follow the name of the file you created (e.gfile-name.bb.snap
). This file contains the scopes for each character. The^
is used as an indicator for the characters the scopes are assigned to.
>foo () {}
#^^^ source.bb entity.name.function.python.bb
# ^^^^^^^ source.bb
>
>VAR = '123'
#^^^ source.bb variable.other.names.bb
# ^ source.bb
# ^ source.bb keyword.operator.bb
# ^ source.bb
# ^ source.bb string.quoted.single.bb
# ^^^ source.bb string.quoted.single.bb
# ^ source.bb string.quoted.single.bb
- Create another file (e.g
file-name-test.abc
) intest/grammars/test-cases
and copy the content of this snap file to it for actual testing. Be sure to add the following line at the very top:
# SYNTAX TEST "source.bb" "your title or comment"
- The scopes in this test file are treated as the expectations when running tests against them. Make any modifications you deem necessary to the scopes.
- Now this test file is ready for
npm run test:grammar
.
Important:
- Do not mix
#
and//
in the test file. It will break the tests and all of them will pass successfully regardless.- The method above is used for quickly generating unit tests, but be sure to double-check the scopes generated by the snap command to see if they actually meet the expectations.
For more information, read this.