-
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.
- Loading branch information
markw65
committed
Sep 7, 2023
1 parent
ef0a1d0
commit e59a378
Showing
4 changed files
with
87 additions
and
22 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,56 @@ | ||
// @ts-check | ||
"use strict"; | ||
|
||
const chai = require("chai"); | ||
const pass = require("../../../../lib/compiler/passes/generate-js"); | ||
|
||
const { expect } = chai; | ||
/** | ||
* @typedef {import("../../../../lib/peg")} PEG | ||
*/ | ||
|
||
describe("compiler pass |generateJS|", () => { | ||
describe("coverage", () => { | ||
/** @type {PEG.ast.Grammar} */ | ||
const ast = { | ||
type: "grammar", | ||
rules: [], | ||
location: { | ||
source: "", | ||
start: { line:1, column:1, offset:0 }, | ||
end: { line:1, column:1, offset:0 }, | ||
}, | ||
}; | ||
const options | ||
= /** @type {PEG.SourceBuildOptions<PEG.SourceOutputs>} */({}); | ||
it("throws unless various grammar fields are set", () => { | ||
expect( | ||
() => pass(ast, options) | ||
).to.throw(Error, "generateJS: generate bytecode was not called."); | ||
ast.literals = []; | ||
expect( | ||
() => pass({ ...ast, literals:[] }, options) | ||
).to.throw(Error, "generateJS: generate bytecode was not called."); | ||
ast.locations = []; | ||
expect( | ||
() => pass({ ...ast, literals:[] }, options) | ||
).to.throw(Error, "generateJS: generate bytecode was not called."); | ||
ast.classes = []; | ||
expect( | ||
() => pass({ ...ast, literals:[] }, options) | ||
).to.throw(Error, "generateJS: generate bytecode was not called."); | ||
ast.expectations = []; | ||
expect( | ||
() => pass({ ...ast, literals:[] }, options) | ||
).to.throw(Error, "generateJS: generate bytecode was not called."); | ||
ast.functions = []; | ||
expect( | ||
() => pass(ast, options) | ||
).to.throw(Error, "generateJS: options.allowedStartRules was not set."); | ||
options.allowedStartRules = ["start"]; | ||
expect( | ||
() => pass(ast, options) | ||
).to.not.throw(); | ||
}); | ||
}); | ||
}); |