You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
vore-rpg/src/scripting/ScriptExpression.test.ts

24 lines
1.3 KiB

import {parse, SyntaxError} from "./NomScript.peggy";
describe("ScriptExpression", () => {
describe("parse", () => {
test("fails with an empty input", () => {
expect(() => parse("", {grammarSource: "testData", startRule: "TopLevelExpression"})).toThrow(SyntaxError)
});
test("fails with empty lines", () => {
expect(() => parse("\n\n\n\n\n", {grammarSource: "testData", startRule: "TopLevelExpression"})).toThrow(SyntaxError)
});
test("fails with lines filled only with whitespace", () => {
expect(() => parse("\n\n \n\t\t \t\n\n", {grammarSource: "testData", startRule: "TopLevelExpression"})).toThrow(SyntaxError)
});
test("fails with lines filled only with comments", () => {
expect(() => parse("\n\n /* */ \n// test \n /* */\n", {grammarSource: "testData", startRule: "TopLevelExpression"})).toThrow(SyntaxError)
});
test("works for a simple expression", () => {
expect(() => parse("73", {grammarSource: "testData", startRule: "TopLevelExpression"})).not.toThrow()
});
test("succeeds with end of line comments", () => {
expect(() => parse("90 // you know", {grammarSource: "testData", startRule: "TopLevelExpression"})).not.toThrow()
});
});
});