mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-19 03:44:23 -05:00
25 lines
1.2 KiB
JavaScript
25 lines
1.2 KiB
JavaScript
var assert = require("assert"),
|
|
bnf = require("../../lib/jison/bnf");
|
|
json2jison = require("../../lib/jison/json2jison");
|
|
|
|
exports["test basic grammar"] = function () {
|
|
var grammar = "%% test: foo bar | baz ; hello: world ;";
|
|
var expected = {bnf: {test: ["foo bar", "baz"], hello: ["world"]}};
|
|
|
|
assert.deepEqual(json2jison.convert(bnf.parse(grammar)), json2jison.convert(expected), "grammar should be parsed correctly");
|
|
};
|
|
|
|
exports["test advanced grammar"] = function () {
|
|
var grammar = "%start foo %% test: foo bar | baz ; hello: world {action} %prec UM;";
|
|
var expected = {start: "foo", bnf: {test: ["foo bar", "baz"], hello: [[ "world", "action", {prec: "UM"} ]]}};
|
|
|
|
assert.deepEqual(json2jison.convert(bnf.parse(grammar)), json2jison.convert(expected), "grammar should be parsed correctly");
|
|
};
|
|
|
|
exports["test actions"] = function () {
|
|
var grammar = "%start foo %% test: foo bar | baz ; hello: world {{action{} }} %prec UM;";
|
|
var expected = {start: "foo", bnf: {test: ["foo bar", "baz"], hello: [[ "world", "action{}", {prec: "UM"} ]]}};
|
|
|
|
assert.deepEqual(json2jison.convert(bnf.parse(grammar)), json2jison.convert(expected), "grammar should be parsed correctly");
|
|
};
|