TextMate Grammar Test Runner

0.6.0 · active · verified Tue Apr 21

This package provides a comprehensive test runner for validating TextMate grammars against the same engine used by VS Code. It offers both unit and snapshot testing capabilities, enabling developers to write assertions against token scopes and to easily track changes in grammar tokenization over time. The current stable version is 0.6.0, with minor releases occurring relatively frequently, driven by performance improvements, bug fixes, and feature enhancements. It serves as a modern and actively maintained successor to the `vscode-tmgrammar-test` package, featuring an updated codebase and enhanced functionality. Key differentiators include its direct validation against the VS Code TextMate engine, robust snapshot testing with an update mechanism, and detailed unit testing syntax for precise scope assertions, including negative assertions and line start token targeting.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates setting up `textmate-grammar-test` in `package.json` scripts and a basic unit test file for a TypeScript grammar.

{
  "name": "my-grammar",
  "version": "1.0.0",
  "scripts": {
    "test:grammar": "npx textmate-grammar-test syntax/tests/**/*.ts"
  },
  "devDependencies": {
    "textmate-grammar-test": "^0.6.0"
  }
}

// syntax/tests/example.ts
// SYNTAX TEST "source.ts" "Basic TypeScript variable declaration"

let count: number = 1;
//  ^^^^^ variable.other.readwrite.ts
//         ^^^^^^ support.type.primitive.ts

const message = "Hello, World!";
// <---- storage.type.ts
//           ^^^^^^^ string.quoted.double.ts

view raw JSON →