VSCode Textmate Grammar Test Runner

0.1.3 · active · verified Tue Apr 21

vscode-tmgrammar-test is a utility for testing VSCode TextMate grammars using a user-friendly plaintext file format, inspired by Sublime Text's syntax testing capabilities. The package provides both unit and snapshot testing functionalities, allowing developers to verify syntax highlighting behavior against a VSCode engine. The current stable version is v0.1.3, with releases occurring periodically to introduce new features, fix bugs, and address breaking changes, such as the removal of certain CLI options and dropping Node.js 10.x support in v0.1.1. Key differentiators include its direct use of the VSCode TextMate engine for accurate simulation, a clear and concise assertion syntax within test files for precise scope checking, and built-in snapshot testing for tracking grammar changes over time. It is designed to be integrated as a development dependency, primarily invoked via its command-line interface, making it an essential tool for grammar authors.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates installation as a dev dependency and running a basic unit test for a TextMate grammar using the CLI tool.

npm i --save-dev vscode-tmgrammar-test

// Create a unit test file, e.g., `tests/example.test.js`
// This content would typically be in a `.scala` or similar file, not a `.js` file itself.
// SYNTAX TEST "source.scala" "basic scala class definition"

// line can start with a <comment token> and not have a valid assertion

class Stack[A] {
// <-----  keyword.declaration.scala
//   ^ - keyword.declaration.scala entity.name.class.declaration
//    ^^^^^  entity.name.class.declaration
//         ^  source.scala meta.bracket.scala
//          ^  entity.name.class
//           ^  meta.bracket.scala
//             ^  punctuation.section.block.begin.scala
}

// Add to package.json scripts:
// "scripts": {
//   "test:grammar": "vscode-tmgrammar-test 'tests/**/*.test.scala'"
// }

// Then run from your terminal:
npx vscode-tmgrammar-test 'tests/**/*.test.js' # Adjust glob to your test file extension

view raw JSON →