Skip to content

Latest commit

 

History

History
44 lines (40 loc) · 2.12 KB

README.md

File metadata and controls

44 lines (40 loc) · 2.12 KB

About The Tests

TextMate Grammars

This client uses vscode-tmgrammar-test mentioned in Microsoft's vscode-textmate as the framework for testing TextMate grammars.

Run Test

npm run test:grammar

Add Tests

To quickly add test cases, follow the steps below:

  1. create a file (e.g file-name.bb) in test/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'
  1. Take snapshots of the scopes by running npm run snap-grammar
  2. A .snap file will be created and it will follow the name of the file you created (e.g file-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
  1. Create another file (e.g file-name-test.abc) in test/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"
  1. 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.
  2. Now this test file is ready for npm run test:grammar.

Important:

  1. Do not mix # and // in the test file. It will break the tests and all of them will pass successfully regardless.
  2. 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.