dojo.provide("dojox.html.tests.format"); dojo.require("dojox.html.format"); doh.register("dojox.html.tests.format", [ { name: "Format: Basic HTML Format test", runTest: function(t) { // summary: // Simple test of basic HTML formatting. // description: // Simple test of basic HTML formatting. var txt = "
hello this is some text.
"; var expected = "
\n" + "\thello this is some text.\n" + "
\n"; var formattedTxt = dojox.html.format.prettyPrint(txt); doh.assertEqual(expected, formattedTxt); } }, { name: "Format: Basic HTML Format test with three space indent", runTest: function(t) { // summary: // Simple test of basic HTML formatting with spaced indenting instead of tab // description: // Simple test of basic HTML formatting with spaced indenting instead of tab var txt = "
hello this is some text.
"; var expected = "
\n" + " hello this is some text.\n" + "
\n"; var formattedTxt = dojox.html.format.prettyPrint(txt, 3); doh.assertEqual(expected, formattedTxt); } }, { name: "Format: Basic HTML Format test with three space indent and custom encoding", runTest: function(t) { // summary: // Simple test of basic HTML formatting with spaced indenting instead of tab // description: // Simple test of basic HTML formatting with spaced indenting instead of tab var txt = "
hello this is \"some\" entities & text.
"; var expected = "
\n" + " hello this is \"some\" entities & text.\n" + "
\n"; var formattedTxt = dojox.html.format.prettyPrint(txt, 3, -1, [["&", "amp"]]); doh.assertEqual(expected, formattedTxt); } }, { name: "Format: Basic HTML Format test with comment node", runTest: function(t) { // summary: // Simple test of basic HTML formatting with a comment node" // description: // Simple test of basic HTML formatting with a comment node" if(!dojo.isIE){ // Hurray for IE, it sometimes just strips comment nodes from the // dom. So we can't test this reliably. var txt = "

"; var expected = "
\n" + " \n" + "
\n" + "
\n"; var formattedTxt = dojox.html.format.prettyPrint(txt, 3); doh.assertEqual(expected, formattedTxt); } } }, { name: "Format: Basic HTML Format test with inline tags", runTest: function(t) { // summary: // Simple test of basic HTML formatting with spaced indenting instead of tab // description: // Simple test of basic HTML formatting with spaced indenting instead of tab var txt = "
hello Example.com this is some text after the link.
"; var expected = "
\n" + " hello Example.com this is some text after the link.\n" + "
\n"; var formattedTxt = dojox.html.format.prettyPrint(txt, 3); doh.assertEqual(expected, formattedTxt); } }, { name: "Format: Basic HTML Format test with inline tags (2)", runTest: function(t) { // summary: // Simple test of basic HTML formatting with spaced indenting instead of tab // description: // Simple test of basic HTML formatting with spaced indenting instead of tab var txt = "
hello
Example.com this is some text after the link.
"; var expected = "
\n" + " hello\n"+ "
\n" + " Example.com this is some text after the link.\n" + "
\n"; var formattedTxt = dojox.html.format.prettyPrint(txt, 3); doh.assertEqual(expected, formattedTxt); } }, { name: "Format: Basic HTML Format test with id", runTest: function(t) { // summary: // Simple test of basic HTML formatting with an id attr set. // description: // Simple test of basic HTML formatting with an id attr set. var txt = "
hello this is some text.
"; var expected = "
\n" + "\thello this is some text.\n" + "
\n"; var formattedTxt = dojox.html.format.prettyPrint(txt); doh.assertEqual(expected, formattedTxt); } }, { name: "Format: Basic HTML Format test with attributes (sorting attributes)", runTest: function(t) { // summary: // Simple test of basic HTML formatting with an id attr set. // description: // Simple test of basic HTML formatting with an id attr set. var txt = "
hello this is some text.
"; var expected = "
\n" + "\thello this is some text.\n" + "
\n"; var formattedTxt = dojox.html.format.prettyPrint(txt); doh.assertEqual(expected, formattedTxt); } }, { name: "Format: Basic HTML Format test with attributes (multiple unquoted)", runTest: function(t) { // summary: // Simple test of basic HTML formatting with an id attr set. // description: // Simple test of basic HTML formatting with an id attr set. var txt = "

hello this is some text.

"; var expected = "

\n\t" + "hello this is some text." + "\n

\n"; var formattedTxt = dojox.html.format.prettyPrint(txt); doh.assertEqual(expected, formattedTxt); } }, { name: "Format: Basic HTML Format test with style", runTest: function(t) { // summary: // Simple test of basic HTML formatting with an id attr set. // description: // Simple test of basic HTML formatting with an id attr set. var txt = "
hello this is some text.
"; var expected = "
\n" + "\thello this is some text.\n" + "
\n"; var formattedTxt = dojox.html.format.prettyPrint(txt); doh.assertEqual(expected, formattedTxt); } }, { name: "Format: Basic HTML Format test with multi style", runTest: function(t) { // summary: // Simple test of basic HTML formatting with an id attr set. // description: // Simple test of basic HTML formatting with an id attr set. var txt = "
hello this is some text.
"; var expected = "
\n" + "\thello this is some text.\n" + "
\n"; var formattedTxt = dojox.html.format.prettyPrint(txt); doh.assertEqual(expected, formattedTxt); } }, { name: "Format: Basic HTML Format with script test", runTest: function(t) { // summary: // Simple test of basic HTML formatting with an embedded script tag. // description: // Simple test of basic HTML formatting with an embedded script tag. var txt = "
hello
this is some text.
"; var expected = "
\n" + "\t
\n" + "\t\thello\n" + "\t
\n"+ "\tthis is some text.\n" + "\t\n" + "
\n"; var formattedTxt = dojox.html.format.prettyPrint(txt); doh.assertEqual(dojo.trim(expected), dojo.trim(formattedTxt)); } }, { name: "Format: Basic HTML Format with script test and three space indent", runTest: function(t) { // summary: // Simple test of basic HTML formatting with an embedded script tag. // description: // Simple test of basic HTML formatting with an embedded script tag. var txt = "
hello
this is some text.
"; var expected = "
\n" + "
\n" + " hello\n" + "
\n"+ " this is some text.\n" + " \n" + "
\n"; var formattedTxt = dojox.html.format.prettyPrint(txt, 3); doh.assertEqual(expected, formattedTxt); } }, { name: "Format: Basic HTML Format with script test and three space indent, XHTML", runTest: function(t) { // summary: // Simple test of basic HTML formatting with an embedded script tag. // description: // Simple test of basic HTML formatting with an embedded script tag. var txt = "
hello

this is some text.
"; var expected = "
\n" + "
\n" + " hello\n" + "
\n" + "
\n" + "
\n"+ " this is some text.\n" + " \n" + "
\n"; var formattedTxt = dojox.html.format.prettyPrint(txt, 3, -1, null, true); doh.assertEqual(expected, formattedTxt); } }, { name: "Format: Basic HTML Format with <pre> tag", runTest: function(t) { // summary: // Simple test of basic HTML formatting with an embedded pre tag. // description: // Simple test of basic HTML formatting with an embedded pre tag. if(!dojo.isIE){ // IE generates good pre tags, but I think the endline chars differ // so direct comparison fails. When I figure that out, I can enable // this test. var txt = "
hello\nthis is    spaced\nWhee!\n
"; var expected = "
\n" + "\t
\n" +
									"hello\n" +
									"this is    spaced\n" +
									"Whee!\n" +
									"\t
\n"+ "
\n"; var formattedTxt = dojox.html.format.prettyPrint(txt); doh.assertEqual(expected, formattedTxt); } } }, { name: "Format: Basic HTML Format with <pre> tag and three space indent", runTest: function(t) { // summary: // Simple test of basic HTML formatting with an embedded pre tag. // description: // Simple test of basic HTML formatting with an embedded pre tag. if(!dojo.isIE){ // IE generates good pre tags, but I think the endline chars differ // so direct comparison fails. When I figure that out, I can enable // this test. var txt = "
hello\nthis is    spaced\nWhee!\n
"; var expected = "
\n" + "
\n" +
									"hello\n" +
									"this is    spaced\n" +
									"Whee!\n" +
									"   
\n"+ "
\n"; var formattedTxt = dojox.html.format.prettyPrint(txt, 3); doh.assertEqual(expected, formattedTxt); } } }, { name: "Format: Semi-complex HTML format", timeout: 10000, runTest: function(t) { // summary: // Simple test of somewhat complex HTML in an external file getting formatted. // description: // Simple test of basic HTML formatting with an embedded pre tag. if(!dojo.isIE){ // Still working out minor comparison issues on IE. Sigh. // the output is pretty accurate, just need to fix a few things. // Like I think the newlines differ or somesuch. var deferred = new doh.Deferred(); var args = { url: dojo.moduleUrl("dojox.html.tests", "unformatted.html").toString(), handleAs: "text", preventCache: true } var ufd = dojo.xhrGet(args); ufd.addCallback(function(html){ html = dojox.html.format.prettyPrint(html, 3); var fArgs = { url: dojo.moduleUrl("dojox.html.tests", "formatted.html").toString(), preventCache: true, handleAs: "text" } var fd = dojo.xhrGet(fArgs); fd.addCallback(function(fHtml){ try{ doh.assertEqual(fHtml, html); deferred.callback(true); }catch(e){ deferred.errback(e); } }); fd.addErrback(function(error){ deferred.errback(error); }); }); ufd.addErrback(function(err){ console.log("Boom!"); deferred.errback(err); }); return deferred; } return null; } } ] );