-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check allowedStartRules. Fixes #166.
- Loading branch information
Showing
4 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"use strict"; | ||
|
||
const chai = require("chai"); | ||
const parser = require("../../lib/parser"); | ||
const compiler = require("../../lib/compiler/index"); | ||
|
||
const expect = chai.expect; | ||
|
||
describe("Peggy compiler", () => { | ||
it("checks start rules", () => { | ||
const ast = parser.parse("foo='1'"); | ||
expect(compiler.compile(ast, compiler.passes)).to.be.an("object"); | ||
expect(() => compiler.compile(ast, compiler.passes, { | ||
allowedStartRules: null, | ||
})).to.throw("allowedStartRules must be an array"); | ||
expect(() => compiler.compile(ast, compiler.passes, { | ||
allowedStartRules: [], | ||
})).to.throw("Must have at least one start rule"); | ||
expect(() => compiler.compile(ast, compiler.passes, { | ||
allowedStartRules: ["bar"], | ||
})).to.throw('Unknown start rule "bar"'); | ||
}); | ||
|
||
it("checks ouput type", () => { | ||
const ast = parser.parse("foo='1'"); | ||
expect(compiler.compile(ast, compiler.passes, { | ||
output: "source", | ||
})).to.be.a("string"); | ||
expect(() => compiler.compile(ast, compiler.passes, { | ||
output: "INVALID OUTPUT TYPE", | ||
})).to.throw("Invalid output format: INVALID OUTPUT TYPE."); | ||
}); | ||
}); |