Gathering detailed insights and metrics for vscode-tmgrammar-test
Gathering detailed insights and metrics for vscode-tmgrammar-test
Gathering detailed insights and metrics for vscode-tmgrammar-test
Gathering detailed insights and metrics for vscode-tmgrammar-test
npm install vscode-tmgrammar-test
Typescript
Module System
Node Version
NPM Version
TypeScript (76.05%)
JavaScript (15.36%)
Dhall (8.1%)
Nix (0.39%)
HCL (0.1%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
106 Stars
120 Commits
13 Forks
3 Watchers
5 Branches
10 Contributors
Updated on Jul 01, 2025
Latest Version
0.1.3
Package Id
vscode-tmgrammar-test@0.1.3
Unpacked Size
109.06 kB
Size
24.85 kB
File Count
41
NPM Version
9.8.0
Node Version
20.5.1
Published on
Feb 05, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Provides a way to test textmate grammars against a vscode engine using user-friendly plaintext files.
Demo:
Inspired by Sublime Text syntax tests
As a project dependency:
1npm i --save-dev vscode-tmgrammar-test
Or as a standalone command line tool:
1npm i -g vscode-tmgrammar-test 2vscode-tmgrammar-test --help
1// SYNTAX TEST "source.scala" "sample testcase" 2 3// line can start with a <comment token> and not have a valid assertion 4 5class Stack[A] { 6// <----- keyword.declaration.scala 7// ^ - keyword.declaration.scala entity.name.class.declaration 8// ^^^^^ entity.name.class.declaration 9// ^ source.scala meta.bracket.scala 10// ^ entity.name.class 11// ^ meta.bracket.scala 12// ^ punctuation.section.block.begin.scala
To write a unit test:
<comment token> SYNTAX TEST "<language scope>" "optional description"
^
:1private var elements: List[A] = Nil 2// ^^^^^^^^ variable.other.declaration.scala
<-
:1var x = 3 2// <--- keyword.declaration.volatile.scala 3// the length of '-' determine how many characters are matched from the start of the line 4x=5 5// <~- keyword.operator.comparison.scala 6// you specify offset from start by using '~' character, just in case
-
symbol before them:1 / ensure comment start with two double slashes 2 ^ - comment.line.double slash.scala 3 4 / or you can combine both positive and negative scopes 5 ^ source.scala - comment.line.double slash.scala
Lines which start with a <comment token>
and assertion symbol are ignored by the textmate grammar.
Note, that scope comparison takes into account relative scope's position.
So, if required scopes are 'scope1 scope2'
, the test will report an error if a grammar returns them as 'scope2 scope1'
.
To run a unit test:
1vscode-tmgrammar-test 'tests/unit/**/*.test.scala'
Snapshot tests are like functional tests
but you don't have to write outputs explicitly.
All you have to do is to provide a source files, scopes of which you want to test. Then on
the first run vscode-tmgrammar-snap
will generate a set of .snap
files which are an
instant snapshot of lines of the source files together with corresponding scopes.
Then if you change the grammar and run the test again, the program will output the changes between
the .snap
file and the real output.
If you satisfied with the changes you can commit
them by running
1vscode-tmgrammar-snap --updateSnapshot ....
this will overwrite the existing .snap
files with a new ones.
After this you should commit them alongside with the source code test cases.
You can read more about them at snapshot testing
To run snapshot test:
1vscode-tmgrammar-snap 'tests/snap/**/*.scala'
The configuration follows the format of vscode:
1{ 2 "contributes": { 3 "languages": [ 4 { 5 "id": "scala", 6 "extensions": [ 7 ".scala", 8 ".sbt", 9 ".sc" 10 ] 11 } 12 ], 13 "grammars": [ 14 { 15 "language": "scala", 16 "scopeName": "source.scala", 17 "path": "./syntaxes/Scala.tmLanguage.json" 18 } 19 ] 20 } 21}
The idea is that for the average language extension all necessary information for tests are already included in the package.json
.
It is optional, though. If the configuration is missing it is necessary to specify grammars and scopeName of testcases via command line options.
Right now only regular grammars and Injection Grammars via injectTo
directive are supported.
Unit tests:
Usage: vscode-tmgrammar-test [options] <testcases...>
Run Textmate grammar test cases using vscode-textmate
Arguments:
testcases A glob pattern(s) which specifies testcases to run, e.g. "./tests/**/test*.dhall". Quotes are important!
Options:
-g, --grammar <grammar> Path to a grammar file. Multiple options supported. 'scopeName' is taken from the grammar (default: [])
--config <configuration.json> Path to the language configuration, package.json by default
-c, --compact Display output in the compact format, which is easier to use with VSCode problem matchers
--xunit-report <report.xml> Path to directory where test reports in the XUnit format will
be emitted in addition to console output
--xunit-format <generic|gitlab> Format of XML reports generated when --xunit-report is used.
`gitlab` format is suitable for viewing the results in GitLab
-V, --version output the version number
-h, --help display help for command
Snapshot tests:
Usage: vscode-tmgrammar-snap [options] <testcases...>
Run VSCode textmate grammar snapshot tests
Arguments:
testcases A glob pattern(s) which specifies testcases to run, e.g. "./tests/**/test*.dhall". Quotes are important!
Options:
-u, --updateSnapshot overwrite all snap files with new changes
--config <configuration.json> Path to the language configuration, package.json by default
--printNotModified include not modified scopes in the output (default: false)
--expandDiff produce each diff on two lines prefixed with "++" and "--" (default: false)
-g, --grammar <grammar> Path to a grammar file. Multiple options supported. 'scopeName' is taken from the grammar (default: [])
-s, --scope <scope> Explicitly specify scope of testcases, e.g. source.dhall
-V, --version output the version number
-h, --help display help for command
You can setup a vscode unit test task for convenience:
1 { 2 "label": "Run tests", 3 "type": "shell", 4 "command": "vscode-tmgrammar-test -c -g testcase/dhall.tmLanguage.json '**/*.dhall'", 5 "group": "test", 6 "presentation": { 7 "reveal": "always", 8 "panel":"new", 9 }, 10 "problemMatcher": { 11 "owner": "vscode-tmgrammar-test", 12 "fileLocation": [ 13 "relative", 14 "${workspaceFolder}", 15 ], 16 "pattern": [ 17 { 18 "regexp": "^(ERROR)\\s([^:]+):(\\d+):(\\d+):(\\d+)\\s(.*)$", 19 "severity": 1, 20 "file": 2, 21 "line": 3, 22 "column": 4, 23 "endColumn": 5, 24 "message": 6, 25 }, 26 ], 27 }, 28 },
Notice the -c
option that will output messages in a handy format for the problemMatcher.
Result:
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
Found 4/10 approved changesets -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More