Skip to content

Commit

Permalink
accurate error messages and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Apr 5, 2019
1 parent e3b9b04 commit c4827e7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/moon/dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
var typeExec = typeRE.exec(input);

if ("development" === "development" && typeExec === null) {
lexError("Lexer expected a valid opening or closing tag.", input, i);
lexError("Lexer expected a valid opening or self-closing tag.", input, i);
}

var typeMatch = typeExec[0];
Expand Down
2 changes: 1 addition & 1 deletion packages/moon/src/compiler/lexer/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function lex(input) {
const typeExec = typeRE.exec(input);

if (process.env.MOON_ENV === "development" && typeExec === null) {
lexError("Lexer expected a valid opening or closing tag.", input, i);
lexError("Lexer expected a valid opening or self-closing tag.", input, i);
}

const typeMatch = typeExec[0];
Expand Down
10 changes: 5 additions & 5 deletions packages/moon/test/compiler/lexer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,21 @@ test("lex error from unclosed opening bracket", () => {
test("lex error from invalid opening tag", () => {
console.error = jest.fn();

expect(Array.isArray(lex("<div"))).toBe(true);
expect(() => {lex("<div");}).toThrow();
expect(console.error).toBeCalled();
});

test("lex error from invalid closing tag", () => {
test("lex error from invalid self-closing tag", () => {
console.error = jest.fn();

expect(Array.isArray(lex("<div/"))).toBe(true);
expect(() => {lex("<input/");}).toThrow();
expect(console.error).toBeCalled();
});

test("lex error from unclosed self-closing tag", () => {
test("lex error from unclosed closing tag", () => {
console.error = jest.fn();

expect(Array.isArray(lex("</input"))).toBe(true);
expect(Array.isArray(lex("</div"))).toBe(true);
expect(console.error).toBeCalled();
});

Expand Down

0 comments on commit c4827e7

Please sign in to comment.