1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-23 13:53:15 +00:00

Fix html parser tests

This commit is contained in:
Jermolene 2014-04-17 14:43:24 +01:00
parent f57e047877
commit d08a2d109f

View File

@ -23,127 +23,127 @@ describe("HTML tag new parser tests", function() {
var parser = new FakeParser();
it("should parse whitespace", function() {
expect(parser.parseWhiteSpace("p ",0)).toEqual(
expect($tw.utils.parseWhiteSpace("p ",0)).toEqual(
null
);
expect(parser.parseWhiteSpace("p ",1)).toEqual(
expect($tw.utils.parseWhiteSpace("p ",1)).toEqual(
{ type : 'whitespace', start : 1, end : 3 }
);
});
it("should parse string tokens", function() {
expect(parser.parseTokenString("p= ",0,"=")).toEqual(
expect($tw.utils.parseTokenString("p= ",0,"=")).toEqual(
null
);
expect(parser.parseTokenString("p= ",1,"=")).toEqual(
expect($tw.utils.parseTokenString("p= ",1,"=")).toEqual(
{ type : 'token', value : '=', start : 1, end : 2 }
);
});
it("should parse regexp tokens", function() {
expect(parser.parseTokenRegExp("p=' ",0,/(=(?:'|"))/)).toEqual(
expect($tw.utils.parseTokenRegExp("p=' ",0,/(=(?:'|"))/)).toEqual(
null
);
expect(parser.parseTokenRegExp("p=' ",1,/(=(?:'|"))/g).match[0]).toEqual(
expect($tw.utils.parseTokenRegExp("p=' ",1,/(=(?:'|"))/g).match[0]).toEqual(
'=\''
);
expect(parser.parseTokenRegExp("p=blah ",2,/([^\s>]+)/g).match[0]).toEqual(
expect($tw.utils.parseTokenRegExp("p=blah ",2,/([^\s>]+)/g).match[0]).toEqual(
'blah'
);
});
it("should parse string literals", function() {
expect(parser.parseStringLiteral("p='blah' ",0)).toEqual(
expect($tw.utils.parseStringLiteral("p='blah' ",0)).toEqual(
null
);
expect(parser.parseStringLiteral("p='blah' ",2)).toEqual(
expect($tw.utils.parseStringLiteral("p='blah' ",2)).toEqual(
{ type : 'string', start : 2, value : 'blah', end : 8 }
);
expect(parser.parseStringLiteral("p='' ",2)).toEqual(
expect($tw.utils.parseStringLiteral("p='' ",2)).toEqual(
{ type : 'string', start : 2, value : '', end : 4 }
);
expect(parser.parseStringLiteral("p=\"blah' ",2)).toEqual(
expect($tw.utils.parseStringLiteral("p=\"blah' ",2)).toEqual(
null
);
expect(parser.parseStringLiteral("p=\"\" ",2)).toEqual(
expect($tw.utils.parseStringLiteral("p=\"\" ",2)).toEqual(
{ type : 'string', start : 2, value : '', end : 4 }
);
});
it("should parse macro parameters", function() {
expect(parser.parseMacroParameter("me",0)).toEqual(
expect($tw.utils.parseMacroParameter("me",0)).toEqual(
{ type : 'macro-parameter', start : 0, value : 'me', end : 2 }
);
expect(parser.parseMacroParameter("me:one",0)).toEqual(
expect($tw.utils.parseMacroParameter("me:one",0)).toEqual(
{ type : 'macro-parameter', start : 0, value : 'one', name : 'me', end : 6 }
);
expect(parser.parseMacroParameter("me:'one two three'",0)).toEqual(
expect($tw.utils.parseMacroParameter("me:'one two three'",0)).toEqual(
{ type : 'macro-parameter', start : 0, value : 'one two three', name : 'me', end : 18 }
);
expect(parser.parseMacroParameter("'one two three'",0)).toEqual(
expect($tw.utils.parseMacroParameter("'one two three'",0)).toEqual(
{ type : 'macro-parameter', start : 0, value : 'one two three', end : 15 }
);
expect(parser.parseMacroParameter("me:[[one two three]]",0)).toEqual(
expect($tw.utils.parseMacroParameter("me:[[one two three]]",0)).toEqual(
{ type : 'macro-parameter', start : 0, value : 'one two three', name : 'me', end : 20 }
);
expect(parser.parseMacroParameter("[[one two three]]",0)).toEqual(
expect($tw.utils.parseMacroParameter("[[one two three]]",0)).toEqual(
{ type : 'macro-parameter', start : 0, value : 'one two three', end : 17 }
);
expect(parser.parseMacroParameter("myparam>",0)).toEqual(
expect($tw.utils.parseMacroParameter("myparam>",0)).toEqual(
{ type : 'macro-parameter', start : 0, value : 'myparam', end : 7 }
);
});
it("should parse macro invocations", function() {
expect(parser.parseMacroInvocation("<<mymacro",0)).toEqual(
expect($tw.utils.parseMacroInvocation("<<mymacro",0)).toEqual(
null
);
expect(parser.parseMacroInvocation("<<mymacro>>",0)).toEqual(
expect($tw.utils.parseMacroInvocation("<<mymacro>>",0)).toEqual(
{ type : 'macrocall', start : 0, params : [ ], name : 'mymacro', end : 11 }
);
expect(parser.parseMacroInvocation("<<mymacro one two three>>",0)).toEqual(
expect($tw.utils.parseMacroInvocation("<<mymacro one two three>>",0)).toEqual(
{ type : 'macrocall', start : 0, params : [ { type : 'macro-parameter', start : 9, value : 'one', end : 13 }, { type : 'macro-parameter', start : 13, value : 'two', end : 17 }, { type : 'macro-parameter', start : 17, value : 'three', end : 23 } ], name : 'mymacro', end : 25 }
);
expect(parser.parseMacroInvocation("<<mymacro p:one q:two three>>",0)).toEqual(
expect($tw.utils.parseMacroInvocation("<<mymacro p:one q:two three>>",0)).toEqual(
{ type : 'macrocall', start : 0, params : [ { type : 'macro-parameter', start : 9, value : 'one', name : 'p', end : 15 }, { type : 'macro-parameter', start : 15, value : 'two', name : 'q', end : 21 }, { type : 'macro-parameter', start : 21, value : 'three', end : 27 } ], name : 'mymacro', end : 29 }
);
expect(parser.parseMacroInvocation("<<mymacro 'one two three'>>",0)).toEqual(
expect($tw.utils.parseMacroInvocation("<<mymacro 'one two three'>>",0)).toEqual(
{ type : 'macrocall', start : 0, params : [ { type : 'macro-parameter', start : 9, value : 'one two three', end : 25 } ], name : 'mymacro', end : 27 }
);
expect(parser.parseMacroInvocation("<<mymacro r:'one two three'>>",0)).toEqual(
expect($tw.utils.parseMacroInvocation("<<mymacro r:'one two three'>>",0)).toEqual(
{ type : 'macrocall', start : 0, params : [ { type : 'macro-parameter', start : 9, value : 'one two three', name : 'r', end : 27 } ], name : 'mymacro', end : 29 }
);
expect(parser.parseMacroInvocation("<<myMacro one:two three:'four and five'>>",0)).toEqual(
expect($tw.utils.parseMacroInvocation("<<myMacro one:two three:'four and five'>>",0)).toEqual(
{ type : 'macrocall', start : 0, params : [ { type : 'macro-parameter', start : 9, value : 'two', name : 'one', end : 17 }, { type : 'macro-parameter', start : 17, value : 'four and five', name : 'three', end : 39 } ], name : 'myMacro', end : 41 }
);
});
it("should parse HTML attributes", function() {
expect(parser.parseAttribute("p='blah' ",1)).toEqual(
expect($tw.utils.parseAttribute("p='blah' ",1)).toEqual(
null
);
expect(parser.parseAttribute("p='blah' ",0)).toEqual(
expect($tw.utils.parseAttribute("p='blah' ",0)).toEqual(
{ type : 'string', start : 0, name : 'p', value : 'blah', end : 8 }
);
expect(parser.parseAttribute("p=\"blah\" ",0)).toEqual(
expect($tw.utils.parseAttribute("p=\"blah\" ",0)).toEqual(
{ type : 'string', start : 0, name : 'p', value : 'blah', end : 8 }
);
expect(parser.parseAttribute("p=blah ",0)).toEqual(
expect($tw.utils.parseAttribute("p=blah ",0)).toEqual(
{ type : 'string', start : 0, name : 'p', value : 'blah', end : 6 }
);
expect(parser.parseAttribute("p =blah ",0)).toEqual(
expect($tw.utils.parseAttribute("p =blah ",0)).toEqual(
{ type : 'string', start : 0, name : 'p', value : 'blah', end : 7 }
);
expect(parser.parseAttribute("p= blah ",0)).toEqual(
expect($tw.utils.parseAttribute("p= blah ",0)).toEqual(
{ type : 'string', start : 0, name : 'p', value : 'blah', end : 7 }
);
expect(parser.parseAttribute("p = blah ",0)).toEqual(
expect($tw.utils.parseAttribute("p = blah ",0)).toEqual(
{ type : 'string', start : 0, name : 'p', value : 'blah', end : 8 }
);
expect(parser.parseAttribute("p = >blah ",0)).toEqual(
expect($tw.utils.parseAttribute("p = >blah ",0)).toEqual(
{ type : 'string', value : 'true', start : 0, name : 'p', end : 4 }
);
expect(parser.parseAttribute(" attrib1>",0)).toEqual(
expect($tw.utils.parseAttribute(" attrib1>",0)).toEqual(
{ type : 'string', value : 'true', start : 0, name : 'attrib1', end : 8 }
);
});