Atom Grammar Test
Atom Grammar Test is a testing framework for Atom Grammar definitions inspired by the Syntax Testing format for Sublime Text 3. It allows you to define grammar fixtures for testing your grammar rules. Because the fixtures match the source code format, they can be both programmatically tested as well as visually inspected for easily development.
Here's an adaption of the example provided in the Sublime docs where you define your tokenization assertions in-line as comments. Note how it visually annotates how the grammar should be parsed.
// SYNTAX TEST "source.c" // <- punctuation.definition.directive meta.preprocessor.c // <- keyword.control.directive.pragma // foo // ^ source.c comment.line // <- punctuation.definition.comment /* foo */// ^ source.c comment.block // <- punctuation.definition.comment.begin // ^ punctuation.definition.comment.end // <- keyword.control.directive.include // ^ meta string punctuation.definition.string.begin // ^ meta string punctuation.definition.string.end int "Hello, World! // not a comment";// ^ string.quoted.double // ^ string.quoted.double // EOF Check (root scope) // >> =source.c
Once you've defined your grammar test, you can simply plug into the Jasmine 1.3 provided by Atom:
grammarTest = require 'atom-grammar-test' describe 'My Grammar'-> beforeEach -> # Ensure you're language package is loaded waitsForPromise -> atompackagesactivatePackage 'language-<your-grammar>' grammarTest'<path to your grammar test file>'
Installation Instructions
You can install atom-grammar-test
via npm and should add it to your
devDependencies
of your atom package's package.json:
npm install atom-grammar-test --save-dev