Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes and enable coverage output in the console #204

Merged
merged 5 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

module.exports = {
"collectCoverage": true,
"coverageReporters": ["lcov"],
"coverageReporters": ["lcov", "text"],
"coveragePathIgnorePatterns": [
"<rootDir>/node_modules/",
"<rootDir>/lib/parser.js",
"<rootDir>/test",
],
"roots": [
"<rootDir>/test",
],
Expand Down
2 changes: 2 additions & 0 deletions lib/compiler/asts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const asts = {
}
}

// istanbul ignore next Presence of rules checked using another approach that not involve this function
// Any time when it is called the rules always exist
return -1;
},

Expand Down
3 changes: 3 additions & 0 deletions lib/compiler/passes/generate-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ function generateJS(ast, options) {
+ ")";
}
case "any": return "peg$anyExpectation()";
// istanbul ignore next Because we never generate expectation type we cannot reach this branch
default: throw new Error("Unknown expectation type (" + JSON.stringify(e) + ")");
}
}
Expand Down Expand Up @@ -525,6 +526,7 @@ function generateJS(ast, options) {
ip++;
break;

// istanbul ignore next Because we never generate invalid bytecode we cannot reach this branch
default:
throw new Error("Invalid opcode: " + bc[ip] + ".");
}
Expand Down Expand Up @@ -594,6 +596,7 @@ function generateJS(ast, options) {
"",
"function peg$SyntaxError(message, expected, found, location) {",
" var self = Error.call(this, message);",
" // istanbul ignore next Check is a necessary evil to support older environments",
" if (Object.setPrototypeOf) {",
" Object.setPrototypeOf(self, peg$SyntaxError.prototype);",
" }",
Expand Down
1 change: 1 addition & 0 deletions lib/grammar-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// See: https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
// This is roughly what typescript generates, it's not called after super(), where it's needed.
// istanbul ignore next This is a special black magic that cannot be covered everywhere
const setProtoOf = Object.setPrototypeOf
|| ({ __proto__: [] } instanceof Array
&& function(d, b) {
Expand Down
1 change: 1 addition & 0 deletions lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions test/cli/run.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ Options:
-h, --help display help for command
`;

await expect(await exec({
await expect(exec({
args: ["-h"],
})).toBe(HELP);
await expect(await exec({
})).resolves.toBe(HELP);
await expect(exec({
args: ["--help"],
})).toBe(HELP);
})).resolves.toBe(HELP);
});

it("rejects invalid options", async() => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/compiler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("Peggy compiler", () => {
})).to.throw('Unknown start rule "bar"');
});

it("checks ouput type", () => {
it("checks output type", () => {
const ast = parser.parse("foo='1'");
expect(compiler.compile(ast, compiler.passes, {
output: "source",
Expand Down