Skip to content

Grammar testing framework for atom based on syntax test files

License

Notifications You must be signed in to change notification settings

kevinastone/atom-grammar-test

Repository files navigation

Atom Grammar Test

npm version Build Status

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.

View the grammar

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"
#pragma once
// <- 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

#include "stdio.h"
// <- keyword.control.directive.include
//       ^ meta string punctuation.definition.string.begin
//               ^ meta string punctuation.definition.string.end
int square(int x)
// <- storage.type
//  ^ meta.function entity.name.function
//         ^ storage.type
{
    return x * x;
//  ^^^^^^ keyword.control
}

"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 ->
      atom.packages.activatePackage '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

Projects Using Atom Grammar Test

About

Grammar testing framework for atom based on syntax test files

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •