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() }); }); });