(function() { module("tinymce.html.SaxParser"); var writer = new tinymce.html.Writer(), schema = new tinymce.html.Schema(); function createCounter(writer) { var counts = {}; return { counts : counts, comment: function(text) { if ("comment" in counts) { counts.comment++; } else { counts.comment = 1; } writer.comment(text); }, cdata: function(text) { if ("cdata" in counts) { counts.cdata++; } else { counts.cdata = 1; } writer.cdata(text); }, text: function(text, raw) { if ("text" in counts) { counts.text++; } else { counts.text = 1; } writer.text(text, raw); }, start: function(name, attrs, empty) { if ("start" in counts) { counts.start++; } else { counts.start = 1; } writer.start(name, attrs, empty); }, end: function(name) { if ("end" in counts) { counts.end++; } else { counts.end = 1; } writer.end(name); }, pi: function(name, text) { if ("pi" in counts) { counts.pi++; } else { counts.pi = 1; } writer.pi(name, text); }, doctype: function(text) { if ("doctype:" in counts) { counts.doctype++; } else { counts.doctype = 1; } writer.doctype(text); } }; } test('Parse elements', function() { var counter, parser; expect(46); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse(''); equal(writer.getContent(), '', 'Parse attribute formats.'); deepEqual(counter.counts, {start:1, end:1}, 'Parse attribute formats counts.'); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse('\'>'); equal(writer.getContent(), '', 'Parse attributes with <> in them.'); deepEqual(counter.counts, {start:1, end:1}, 'Parse attributes with <> in them (count).'); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse(''); equal(writer.getContent(), '', 'Parse compressed attributes.'); deepEqual(counter.counts, {start:1, end:1}, 'Parse compressed attributes (count).'); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse(''); equal(writer.getContent(), '', 'Single empty attribute.'); deepEqual(counter.counts, {start:1, end:1}, 'Single empty attributes (count).'); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse(''); equal(writer.getContent(), '', 'Empty attribute at end.'); deepEqual(counter.counts, {start:1, end:1}, 'Empty attribute at end (count).'); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse(''); equal(writer.getContent(), '', 'Empty attribute at start.'); deepEqual(counter.counts, {start:1, end:1}, 'Empty attribute at start (count).'); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse(''); equal(writer.getContent(), '', 'Parse empty element.'); deepEqual(counter.counts, {start:1}, 'Parse empty element counts.'); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse(''); equal(writer.getContent(), '', 'Parse attributes with linebreak.'); deepEqual(counter.counts, {start: 1}, 'Parse attributes with linebreak counts.'); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse(''); equal(writer.getContent(), '', 'Parse attributes with whitespace.'); deepEqual(counter.counts, {start: 1}, 'Parse attributes with whitespace counts.'); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse('text'); equal(writer.getContent(), 'text', 'Parse element with namespace.'); deepEqual(counter.counts, {start:1, text:1, end: 1}, 'Parse element with namespace counts.'); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse('text'); equal(writer.getContent(), 'text', 'Parse element with dash name.'); deepEqual(counter.counts, {start:1, text:1, end:1}, 'Parse element with dash name counts.'); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse('text1

text2text3

text4text5'); equal(writer.getContent(), 'text1

text2text3

text4text5', 'Parse tag soup 1.'); deepEqual(counter.counts, {text:5, start: 2, end: 2}, 'Parse tag soup 1 counts.'); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse('text1

text2text3

text4text5'); equal(writer.getContent(), 'text1

text2text3

text4text5', 'Parse tag soup 2.'); deepEqual(counter.counts, {text: 5, start: 2, end: 2}, 'Parse tag soup 2 counts.'); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse('text1

text2texte>xt4text5'); equal(writer.getContent(), 'text1

text2tex<t3

te>xt4text5', 'Parse tag soup 3.'); deepEqual(counter.counts, {text: 5, start: 2, end: 2}, 'Parse tag soup 3 counts.'); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse('text1

text2text3'); equal(writer.getContent(), 'text1

text2text3

', 'Parse tag soup 4.'); deepEqual(counter.counts, {text: 3, start: 2, end: 2}, 'Parse tag soup 4 counts.'); counter = createCounter(writer); parser = new tinymce.html.SaxParser(counter, schema); writer.reset(); parser.parse('text1