/*global js_beautify: true */ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_beautify) { var opts = { indent_size: 4, indent_char: ' ', preserve_newlines: true, jslint_happy: false, keep_array_indentation: false, brace_style: 'collapse', space_before_conditional: true, break_chained_methods: false, selector_separator: '\n', end_with_newline: false }; function test_html_beautifier(input) { return html_beautify(input, opts); } var sanitytest; // test the input on beautifier with the current flag settings // does not check the indentation / surroundings as bt() does function test_fragment(input, expected) { expected = expected || expected === '' ? expected : input; sanitytest.expect(input, expected); // if the expected is different from input, run it again // expected output should be unchanged when run twice. if (expected !== input) { sanitytest.expect(expected, expected); } // Everywhere we do newlines, they should be replaced with opts.eol opts.eol = '\r\n'; expected = expected.replace(/[\n]/g, '\r\n'); sanitytest.expect(input, expected); input = input.replace(/[\n]/g, '\r\n'); sanitytest.expect(input, expected); opts.eol = '\n'; } // test html function bth(input, expectation) { var wrapped_input, wrapped_expectation, field_input, field_expectation; expectation = expectation || expectation === '' ? expectation : input; sanitytest.test_function(test_html_beautifier, 'html_beautify'); test_fragment(input, expectation); if (opts.indent_size === 4 && input) { wrapped_input = '
\n' + input.replace(/^(.+)$/mg, ' $1') + '\n inline\n
'; wrapped_expectation = '
\n' + expectation.replace(/^(.+)$/mg, ' $1') + '\n inline\n
'; test_fragment(wrapped_input, wrapped_expectation); } } function unicode_char(value) { return String.fromCharCode(value) } function beautifier_tests() { sanitytest = test_obj; bth(''); {{#default_options}} opts.{{name}} = {{&value}}; {{/default_options}} {{#groups}}{{#set_mustache_tags}}.{{/set_mustache_tags}}{{^matrix}} // {{&name}} {{#options}} opts.{{name}} = {{&value}}; {{/options}} {{#tests}} {{#test_line}}.{{/test_line}}; {{/tests}} {{/matrix}}{{#matrix}} // {{&name}} - ({{#matrix_context_string}}.{{/matrix_context_string}}) {{#options}} opts.{{name}} = {{&value}}; {{/options}} {{#tests}} {{#test_line}}.{{/test_line}}; {{/tests}} {{/matrix}}{{#unset_mustache_tags}}.{{/unset_mustache_tags}} {{/groups}} opts.end_with_newline = true; test_fragment('', '\n'); test_fragment('
\n'); test_fragment('
\n\n\n', '
\n'); test_fragment('\n' + ' \n' + '\n'); opts.end_with_newline = false; // error cases need love too bth('Evil'); bth(" test_fragment( '\n' + ' \n' + ''); test_fragment('
\n', '
'); bth('
'); bth('
content
'); bth('
', '
\n' + '
\n' + '
'); bth('
content
', '
\n' + '
content
\n' + '
'); bth('
\n' + ' content\n' + '
'); bth('
\n' + '
'); bth('
\n' + ' content\n' + '
'); bth('
\n' + '
', '
\n' + '
'); bth('
\n' + '
', '
\n' + '
'); bth('
\n' + '
\n' + '
\n' + '
', '
\n' + '
\n' + '
\n' + '
'); bth('
\n' + '
', '
\n' + '
'); bth('
content
', '
content
'); bth('
', '
'); bth('content\n' + '
\n' + '
\n' + 'content', 'content\n' + '
\n' + '
\n' + 'content'); bth('
  • \n' + '
    \n' + '
    \n' + '
  • '); bth('
  • \n' + '
    \n' + '
    \n' + '
  • ', '
  • \n' + '
    \n' + '
    \n' + '
  • '); bth('
  • \n' + ' content\n' + '
  • \n' + '
  • \n' + ' content\n' + '
  • '); bth('content'); bth(' content'); bth(' content', ' content'); bth('content'); bth(' content'); bth(' content', ' content'); bth('content'); bth(' content'); bth(' content', ' content'); bth('
    contentcontent
    '); bth('
    content content
    '); bth('
    content content
    ', '
    content content
    '); bth('Text Link Text'); // START tests for issue 453 bth('', ''); bth('', ''); bth('', ''); bth('', ''); bth('', ''); bth('', ''); bth('', ''); bth('', ''); bth('', ''); bth('', ''); bth('', ''); bth('', ''); bth('', ''); bth('', ''); bth('', ''); // END tests for issue 453 var unformatted = opts.unformatted; opts.unformatted = ['script', 'style']; bth(''); bth(''); opts.unformatted = unformatted; unformatted = opts.unformatted; opts.unformatted = ['custom-element']; test_fragment('
    should not' + ' insert newlines
    ', '
    should not' + ' insert newlines
    '); opts.unformatted = unformatted; // Tests that don't pass, but probably should. // bth('
    content
    '); // Handlebars tests // Without the indent option on, handlebars are treated as content. opts.wrap_line_length = 0; //...---------1---------2---------3---------4---------5---------6---------7 //...1234567890123456789012345678901234567890123456789012345678901234567890 bth('
    Some text that should not wrap at all.
    ', /* expected */ '
    Some text that should not wrap at all.
    '); // A value of 0 means no max line length, and should not wrap. //...---------1---------2---------3---------4---------5---------6---------7---------8---------9--------10--------11--------12--------13--------14--------15--------16--------17--------18--------19--------20--------21--------22--------23--------24--------25--------26--------27--------28--------29 //...12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 bth('
    Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all.
    ', /* expected */ '
    Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all.
    '); opts.wrap_line_length = "0"; //...---------1---------2---------3---------4---------5---------6---------7 //...1234567890123456789012345678901234567890123456789012345678901234567890 bth('
    Some text that should not wrap at all.
    ', /* expected */ '
    Some text that should not wrap at all.
    '); // A value of "0" means no max line length, and should not wrap //...---------1---------2---------3---------4---------5---------6---------7---------8---------9--------10--------11--------12--------13--------14--------15--------16--------17--------18--------19--------20--------21--------22--------23--------24--------25--------26--------27--------28--------29 //...12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 bth('
    Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all.
    ', /* expected */ '
    Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all.
    '); //BUGBUG: This should wrap before 40 not after. opts.wrap_line_length = 40; //...---------1---------2---------3---------4---------5---------6---------7 //...1234567890123456789012345678901234567890123456789012345678901234567890 bth('
    Some test text that should wrap_inside_this section here.
    ', /* expected */ '
    Some test text that should wrap_inside_this\n' + ' section here.
    '); opts.wrap_line_length = "40"; //...---------1---------2---------3---------4---------5---------6---------7 //...1234567890123456789012345678901234567890123456789012345678901234567890 bth('
    Some test text that should wrap_inside_this section here.
    ', /* expected */ '
    Some test text that should wrap_inside_this\n' + ' section here.
    '); opts.indent_size = 1; opts.indent_char = '\t'; opts.preserve_newlines = false; bth('
    \n\tfoo\n
    ', '
    foo
    '); opts.preserve_newlines = true; bth('
    \n\tfoo\n
    '); // test preserve_newlines and max_preserve_newlines opts.preserve_newlines = false; bth('
    Should not
    \n\n\n' + '
    preserve newlines
    ', '
    Should not
    \n' + '
    preserve newlines
    '); opts.preserve_newlines = true; opts.max_preserve_newlines = 0; bth('
    Should
    \n\n\n' + '
    preserve zero newlines
    ', '
    Should
    \n' + '
    preserve zero newlines
    '); opts.max_preserve_newlines = 1; bth('
    Should
    \n\n\n' + '
    preserve one newline
    ', '
    Should
    \n\n' + '
    preserve one newline
    '); opts.max_preserve_newlines = null; bth('
    Should
    \n\n\n' + '
    preserve one newline
    ', '
    Should
    \n\n\n' + '
    preserve one newline
    '); } beautifier_tests(); } if (typeof exports !== "undefined") { exports.run_html_tests = run_html_tests; }