Skip to content

Commit

Permalink
add lexer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Apr 4, 2019
1 parent 7d93cef commit fe8149e
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion packages/moon/test/compiler/lexer.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lex } from "../../src/compiler/lexer/lexer";
import { lex, tokenString } from "../../src/compiler/lexer/lexer";

test("lex opening tag", () => {
expect(lex(`<div>`)).toEqual([{"attributes": {}, "closed": false, "type": "tagOpen", "value": "div"}]);
Expand Down Expand Up @@ -50,3 +50,38 @@ test("lex attributes", () => {
test("lex comments", () => {
expect(lex(`<!-- comment -->`)).toEqual([]);
});

test("opening tag token to string", () => {
const input = "<div>";
expect(tokenString(lex(input)[0])).toBe(input);
});

test("opening tag token with attributes to string", () => {
const input = `<div id="test-id" class='test-class' expression={dynamic}>`;
expect(tokenString(lex(input)[0])).toBe(input);
});

test("self-closing tag token to string", () => {
const input = `<input/>`;
expect(tokenString(lex(input)[0])).toBe(input);
});

test("self-closing tag token with attributes to string", () => {
const input = `<input id="test-id" class='test-class' expression={dynamic}/>`;
expect(tokenString(lex(input)[0])).toBe(input);
});

test("closing tag token to string", () => {
const input = `</div>`;
expect(tokenString(lex(input)[0])).toBe(input);
});

test("text token to string", () => {
const input = `Test Text`;
expect(tokenString(lex(input)[0])).toBe(input);
});

test("expression token to string", () => {
const input = `{dynamic + 1}`;
expect(tokenString(lex(input)[0])).toBe(input);
});

0 comments on commit fe8149e

Please sign in to comment.