From fe8149ec93a18b59df89d234a60532aee5948a15 Mon Sep 17 00:00:00 2001 From: Kabir Shah Date: Thu, 4 Apr 2019 01:13:20 -0700 Subject: [PATCH] add lexer tests --- packages/moon/test/compiler/lexer.test.js | 37 ++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/moon/test/compiler/lexer.test.js b/packages/moon/test/compiler/lexer.test.js index 9dc2ea2c..817a4f16 100644 --- a/packages/moon/test/compiler/lexer.test.js +++ b/packages/moon/test/compiler/lexer.test.js @@ -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(`
`)).toEqual([{"attributes": {}, "closed": false, "type": "tagOpen", "value": "div"}]); @@ -50,3 +50,38 @@ test("lex attributes", () => { test("lex comments", () => { expect(lex(``)).toEqual([]); }); + +test("opening tag token to string", () => { + const input = "
"; + expect(tokenString(lex(input)[0])).toBe(input); +}); + +test("opening tag token with attributes to string", () => { + const input = `
`; + expect(tokenString(lex(input)[0])).toBe(input); +}); + +test("self-closing tag token to string", () => { + const input = ``; + expect(tokenString(lex(input)[0])).toBe(input); +}); + +test("self-closing tag token with attributes to string", () => { + const input = ``; + expect(tokenString(lex(input)[0])).toBe(input); +}); + +test("closing tag token to string", () => { + const input = `
`; + 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); +});