/*global test, deepEqual, largeModule, strictEqual */ largeModule('HtmlTextParser'); var parser = new cc._Test.HtmlTextParser(); test('Basic Test', function() { var testStr1 = "hello world"; deepEqual(parser.parse(testStr1), [{text: "hello world"}], 'No Html string should be equal to original.'); var testInvalidStr2 = "Super weapon"; deepEqual(parser.parse(eventTestString2), [{text: "Super weapon", style: { color: "#0xff0000", event: { click : "event1", } }}], "Color with event"); var eventTestString3 = "hello world"; deepEqual(parser.parse(eventTestString3), [{text: "hello world", style: { size: 20, event: { click : "event1", } }}], "Size with event"); var eventTestString4 = "hello world"; deepEqual(parser.parse(eventTestString4), [{text: "hello world", style: {} }], "Failed path: Size with event"); var invalidEventTestString4 = "hello world"; deepEqual(parser.parse(invalidEventTestString5), [{text: "hello world", style: {size: 20, event: {}} }], "Failed path: event name quote not match."); }); test('Test special symbol escape', function() { var testLessThan = "hello<world"; deepEqual(parser.parse(testLessThan), [ {text: "helloworld", style: { event: { click: 'event1' } }}], "The > symbol should be correctly escaped."); var testAmp = "hello&world"; deepEqual(parser.parse(testAmp), [{text: "hello&world", style: { color: "#0xff00" }}], "The amp symbol should be correctly escaped."); var testQuot = "hello"world"; deepEqual(parser.parse(testQuot), [{text: "hello\"world", style: {}}], "The quot symbol should be correctly escaped."); var testApos = "Hi, hello'world"; deepEqual(parser.parse(testApos), [{text: "Hi, ", style: { color: "#0xffee" }}, {text: "hello'world", style: { color: "#0xffee", size: 20 }}], "The apos symbol should be correctly escaped."); }); test('Integrate test', function() { var eventTestString = "hello world, Ni hao "; deepEqual(parser.parse(eventTestString), [{text: "hello "}, {text: "world", style: {bold: true}}, {text: ", "}, {text: " Ni hao ", style : {color: "#0xff0000"}}], "Happy path 1"); var moreComplexString = "大小不一,颜色不同可点击"; deepEqual(parser.parse(moreComplexString), [{text: "大小", style: {size: 20}}, {text: "不一", style: {size: 10}}, {text:","}, {text: "颜色", style: {color: "#0xffeeaa"}}, {text: "不同", style: {color: "#0xffaaee"}}, {text: "可点击", style: {event: {click: 'event1'}}}], "more complex test"); }); test('bold/italic/underline test', function () { var stringWithBold = "hello \n world"; deepEqual(parser.parse(stringWithBold), [{text: "hello \n world", style: {bold: true}}], "bold test"); var stringWithItalic = "hello world"; deepEqual(parser.parse(stringWithItalic), [{text: "hello world", style: {italic: true}}], "italic test"); var stringWithUnderline = "hello world"; deepEqual(parser.parse(stringWithUnderline), [{text: "hello world", style: {underline: true}}], "underline test"); }); test('test br tag', function () { var newlineTest = "
"; deepEqual(parser.parse(newlineTest), [{text: "", style: {newline: true}},], "newline element test"); var newlineTest2 = "hello a< br /> world"; deepEqual(parser.parse(newlineTest2), [{text: "hello "}, {text: "a", style: {bold: true}}, {text: "", style: {newline: true}}, {text: " world"} ], "newline element test"); var newlineTest3 = "< br />"; deepEqual(parser.parse(newlineTest3), [{text: "", style: {newline: true}},], "newline element test"); var newlineTest4 = "

"; deepEqual(parser.parse(newlineTest4), [], "newline element test"); var newlineTest5 = "hello a
world"; deepEqual(parser.parse(newlineTest5), [{text: "hello "}, {text: "a", style: {bold: true}}, {text: " world"} ], "newline element test"); var newlineTest6 = "hello a

world"; deepEqual(parser.parse(newlineTest6), [{text: "hello "}, {text: "a", style: {bold: true}}, {text: "", style: {newline: true}}, {text: "", style: {newline: true}}, {text: " world"} ], "newline element test"); var newlineTest7 = "hello a

world"; deepEqual(parser.parse(newlineTest7), [{text: "hello "}, {text: "a", style: {bold: true}}, {text: "", style: {newline: true}}, {text: "", style: {newline: true}}, {text: "world"} ], "newline element test"); }); test('test image tag', function () { var imageTest1 = ""; deepEqual(parser.parse(imageTest1), [ {text: "", style: {isImage: true, src: "weapon"}} ], "image element test 1"); var imageTest2 = ''; deepEqual(parser.parse(imageTest2), [ {text: "", style: {isImage: true, src: "weapon"}} ], "image element test 2"); var imageTest3 = "hello, world"; deepEqual(parser.parse(imageTest3), [ {text: "hello, "}, {text: "world", style : {bold: true}}, {text: "", style: {isImage: true, src: "nihao"}} ], "image element test"); var imageTest4 = "hello, world"; deepEqual(parser.parse(imageTest4), [ {text: "hello, "}, {text: "world", style : {bold: true}}, ], "image element test"); var imageTest5 = "hello, world"; deepEqual(parser.parse(imageTest5), [ {text: "hello, "}, {text: "world", style : {bold: true}}, ], "image element event test"); var imageTest6 = "hello, world"; deepEqual(parser.parse(imageTest6), [ {text: "hello, "}, {text: "world", style : {bold: true}}, {text: "", style: {isImage: true, src: "head", event: {click: "handler"}}} ], "image element event test"); var invalidImageTest1 = ""; deepEqual(parser.parse(invalidImageTest1), [], "image element invalid test"); var invalidImageTest2 = ""; deepEqual(parser.parse(invalidImageTest2), [], "image element invalid test"); var invalidImageTest3 = ""; deepEqual(parser.parse(invalidImageTest3), [], "image element invalid test"); var nestedImageTest4 = ""; deepEqual(parser.parse(nestedImageTest4), [{text: "", style: {isImage: true, src: 'world', event: {click: 'handler'}}}], "image element invalid test"); }); test('test outline tag', function () { var outlineTest1 = "hello"; deepEqual(parser.parse(outlineTest1), [ {text: "hello", style: { outline: { color: "#0f00ff", width: 2 }}} ], "outline element test 1"); var outlineTest2 = 'hello'; deepEqual(parser.parse(outlineTest2), [ {text: "hello", style: { outline: { color: "#0f00ff", width: 1 } }} ], "outline element test 2"); var outlineTest3 = 'hello'; deepEqual(parser.parse(outlineTest3), [ {text: "hello", style: { outline: { color: "#ffffff", width: 4 } }} ], "outline element test 3"); var outlineTest4 = 'hello'; deepEqual(parser.parse(outlineTest4), [ {text: "hello", style: { outline: { color: "#ffffff", width: 1 } }} ], "outline element test 4"); var outlineTest5 = "hello"; deepEqual(parser.parse(outlineTest5), [ {text: "hello", style: { outline: { color: "#0f00ff", width: 2 }, event: { click: "clickme" } }} ], "outline element test 5"); var outlineTest6 = "hello"; deepEqual(parser.parse(outlineTest6), [ {text: "hello", style: { outline: { color: "#0f00ff", width: 2 }, event: { click: "clickme" } }} ], "outline element test 6"); var outlineTest7 = "hello"; deepEqual(parser.parse(outlineTest7), [ {text: "hello", style: { outline: { color: "#0f00ff", width: 2 }, event: { click: "clickme" } }} ], "outline element test 7"); var outlineTest8 = "hello"; deepEqual(parser.parse(outlineTest8), [ {text: "hello", style: { bold: true, underline: true, outline: { color: "#0f00ff", width: 2 }, event: { click: "clickme" } }} ], "outline element test 8"); var invalidOutlineTest1 = "hello"; deepEqual(parser.parse(invalidOutlineTest1), [ {text: "hello", style: { outline: { color: "#ffffff", width: 2 }, event: { click: "clickme" } }} ], "invalid outline element test 1"); var invalidOutlineTest2 = "hello"; deepEqual(parser.parse(invalidOutlineTest2), [ {text: "hello", style: { outline: { color: "#ffffff", width: 1 } }} ], "invalid outline element test 2"); var invalidOutlineTest3 = "hello"; deepEqual(parser.parse(invalidOutlineTest3), [ {text: "hello", style: {}} ], "invalid outline element test 3"); });