mirror of
https://github.com/beautifier/js-beautify.git
synced 2025-02-23 23:01:11 +00:00
Add tests
This commit is contained in:
parent
f97b8f8f90
commit
47231ba0ee
@ -4914,6 +4914,44 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
|
||||
' <tr>\n' +
|
||||
' <td>Electric locomotive operating sounds\n' +
|
||||
' <td>✔\n' +
|
||||
' <table>\n' +
|
||||
' <caption>37547 TEE Electric Powered Rail Car Train Functions (Abbreviated)\n' +
|
||||
' <colgroup>\n' +
|
||||
' <col>\n' +
|
||||
' <col>\n' +
|
||||
' <col>\n' +
|
||||
' <thead>\n' +
|
||||
' <tr>\n' +
|
||||
' <th>Function\n' +
|
||||
' <th>Control Unit\n' +
|
||||
' <th>Central Station\n' +
|
||||
' <tbody>\n' +
|
||||
' <tr>\n' +
|
||||
' <td>Headlights\n' +
|
||||
' <td>✔\n' +
|
||||
' <td>✔\n' +
|
||||
' <tr>\n' +
|
||||
' <td>Interior Lights\n' +
|
||||
' <td>✔\n' +
|
||||
' <td>✔\n' +
|
||||
' <tr>\n' +
|
||||
' <td>Electric locomotive operating sounds\n' +
|
||||
' <td>✔\n' +
|
||||
' <td>✔\n' +
|
||||
' <tr>\n' +
|
||||
' <td>Engineer’s cab lighting\n' +
|
||||
' <td>\n' +
|
||||
' <td>✔\n' +
|
||||
' <tr>\n' +
|
||||
' <td>Station Announcements - Swiss\n' +
|
||||
' <td>\n' +
|
||||
' <td>✔\n' +
|
||||
' <tfoot>\n' +
|
||||
' <tr>\n' +
|
||||
' <td>Station Announcements - Swiss\n' +
|
||||
' <td>\n' +
|
||||
' <td>✔\n' +
|
||||
' </table>\n' +
|
||||
' <td>✔\n' +
|
||||
' <tr>\n' +
|
||||
' <td>Engineer’s cab lighting\n' +
|
||||
@ -4935,7 +4973,7 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
|
||||
// Unformatted tags
|
||||
reset_options();
|
||||
set_name('Unformatted tags');
|
||||
test_fragment(
|
||||
bth(
|
||||
'<ol>\n' +
|
||||
' <li>b<pre>c</pre></li>\n' +
|
||||
'</ol>',
|
||||
@ -4945,36 +4983,36 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
|
||||
' <pre>c</pre>\n' +
|
||||
' </li>\n' +
|
||||
'</ol>');
|
||||
test_fragment(
|
||||
bth(
|
||||
'<ol>\n' +
|
||||
' <li>b<code>c</code></li>\n' +
|
||||
'</ol>');
|
||||
test_fragment(
|
||||
bth(
|
||||
'<ul>\n' +
|
||||
' <li>\n' +
|
||||
' <span class="octicon octicon-person"></span>\n' +
|
||||
' <a href="/contact/">Kontakt</a>\n' +
|
||||
' </li>\n' +
|
||||
'</ul>');
|
||||
test_fragment('<div class="searchform"><input type="text" value="" name="s" id="s" /><input type="submit" id="searchsubmit" value="Search" /></div>');
|
||||
test_fragment('<div class="searchform"><input type="text" value="" name="s" id="s"><input type="submit" id="searchsubmit" value="Search"></div>');
|
||||
test_fragment(
|
||||
bth('<div class="searchform"><input type="text" value="" name="s" id="s" /><input type="submit" id="searchsubmit" value="Search" /></div>');
|
||||
bth('<div class="searchform"><input type="text" value="" name="s" id="s"><input type="submit" id="searchsubmit" value="Search"></div>');
|
||||
bth(
|
||||
'<p>\n' +
|
||||
' <a href="/test/"><img src="test.jpg" /></a>\n' +
|
||||
'</p>');
|
||||
test_fragment(
|
||||
bth(
|
||||
'<p>\n' +
|
||||
' <a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a>\n' +
|
||||
'</p>');
|
||||
test_fragment(
|
||||
bth(
|
||||
'<p>\n' +
|
||||
' <a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a>\n' +
|
||||
'</p>');
|
||||
test_fragment(
|
||||
bth(
|
||||
'<p>\n' +
|
||||
' <span>image: <img src="test.jpg" /></span><span>image: <img src="test.jpg" /></span>\n' +
|
||||
'</p>');
|
||||
test_fragment(
|
||||
bth(
|
||||
'<p>\n' +
|
||||
' <strong>image: <img src="test.jpg" /></strong><strong>image: <img src="test.jpg" /></strong>\n' +
|
||||
'</p>');
|
||||
@ -4999,8 +5037,11 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
|
||||
// ISSUE #545 and #944 Ignore directive works in html
|
||||
reset_options();
|
||||
set_name('ISSUE #545 and #944 Ignore directive works in html');
|
||||
|
||||
// ignore starts _after_ the start comment, ends after the end comment
|
||||
bth(
|
||||
'<!-- beautify ignore:start -->\n' +
|
||||
'<div>\n' +
|
||||
' <!-- beautify ignore:start -->\n' +
|
||||
'@{\n' +
|
||||
'\n' +
|
||||
' ViewBag.Title = "Dashboard";\n' +
|
||||
@ -5014,20 +5055,21 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
|
||||
' }\n' +
|
||||
'\n' +
|
||||
'}\n' +
|
||||
'<!-- beautify ignore:end -->\n' +
|
||||
' <!-- beautify ignore:end -->\n' +
|
||||
'\n' +
|
||||
'<header class="layout-header">\n' +
|
||||
' <header class="layout-header">\n' +
|
||||
'\n' +
|
||||
' <h2 id="logo"><a href="/">Logo</a></h2>\n' +
|
||||
' <h2 id="logo"><a href="/">Logo</a></h2>\n' +
|
||||
'\n' +
|
||||
' <ul class="social">\n' +
|
||||
' <ul class="social">\n' +
|
||||
'\n' +
|
||||
' <li class="facebook"><a href="#">Facebook</a></li>\n' +
|
||||
' <li class="twitter"><a href="#">Twitter</a></li>\n' +
|
||||
' <li class="facebook"><a href="#">Facebook</a></li>\n' +
|
||||
' <li class="twitter"><a href="#">Twitter</a></li>\n' +
|
||||
'\n' +
|
||||
' </ul>\n' +
|
||||
' </ul>\n' +
|
||||
'\n' +
|
||||
'</header>');
|
||||
' </header>\n' +
|
||||
'</div>');
|
||||
|
||||
|
||||
//============================================================
|
||||
|
@ -2462,23 +2462,26 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
|
||||
bt(
|
||||
'/* beautify ignore:start */\n' +
|
||||
' var a,,,{ 1;\n' +
|
||||
'/* beautify ignore:end */');
|
||||
' /* beautify ignore:end */');
|
||||
bt(
|
||||
'var a = 1;\n' +
|
||||
'/* beautify ignore:start */\n' +
|
||||
' var a = 1;\n' +
|
||||
'/* beautify ignore:end */');
|
||||
|
||||
// ignore starts _after_ the start comment, ends after the end comment
|
||||
bt('/* beautify ignore:start */ {asdklgh;y;+++;dd2d}/* beautify ignore:end */');
|
||||
bt('/* beautify ignore:start */ {asdklgh;y;+++;dd2d} /* beautify ignore:end */');
|
||||
bt(
|
||||
'var a = 1;\n' +
|
||||
'/* beautify ignore:start */\n' +
|
||||
' var a,,,{ 1;\n' +
|
||||
'/* beautify ignore:end */',
|
||||
'/*beautify ignore:end*/',
|
||||
// -- output --
|
||||
'var a = 1;\n' +
|
||||
'/* beautify ignore:start */\n' +
|
||||
' var a,,,{ 1;\n' +
|
||||
'/* beautify ignore:end */');
|
||||
'/*beautify ignore:end*/');
|
||||
bt(
|
||||
'var a = 1;\n' +
|
||||
' /* beautify ignore:start */\n' +
|
||||
|
@ -2234,23 +2234,26 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
bt(
|
||||
'/* beautify ignore:start */\n' +
|
||||
' var a,,,{ 1;\n' +
|
||||
'/* beautify ignore:end */')
|
||||
' /* beautify ignore:end */')
|
||||
bt(
|
||||
'var a = 1;\n' +
|
||||
'/* beautify ignore:start */\n' +
|
||||
' var a = 1;\n' +
|
||||
'/* beautify ignore:end */')
|
||||
|
||||
# ignore starts _after_ the start comment, ends after the end comment
|
||||
bt('/* beautify ignore:start */ {asdklgh;y;+++;dd2d}/* beautify ignore:end */')
|
||||
bt('/* beautify ignore:start */ {asdklgh;y;+++;dd2d} /* beautify ignore:end */')
|
||||
bt(
|
||||
'var a = 1;\n' +
|
||||
'/* beautify ignore:start */\n' +
|
||||
' var a,,,{ 1;\n' +
|
||||
'/* beautify ignore:end */',
|
||||
'/*beautify ignore:end*/',
|
||||
# -- output --
|
||||
'var a = 1;\n' +
|
||||
'/* beautify ignore:start */\n' +
|
||||
' var a,,,{ 1;\n' +
|
||||
'/* beautify ignore:end */')
|
||||
'/*beautify ignore:end*/')
|
||||
bt(
|
||||
'var a = 1;\n' +
|
||||
' /* beautify ignore:start */\n' +
|
||||
|
@ -1194,6 +1194,44 @@ exports.test_data = {
|
||||
' <tr>',
|
||||
' <td>Electric locomotive operating sounds',
|
||||
' <td>✔',
|
||||
' <table>',
|
||||
' <caption>37547 TEE Electric Powered Rail Car Train Functions (Abbreviated)',
|
||||
' <colgroup>',
|
||||
' <col>',
|
||||
' <col>',
|
||||
' <col>',
|
||||
' <thead>',
|
||||
' <tr>',
|
||||
' <th>Function',
|
||||
' <th>Control Unit',
|
||||
' <th>Central Station',
|
||||
' <tbody>',
|
||||
' <tr>',
|
||||
' <td>Headlights',
|
||||
' <td>✔',
|
||||
' <td>✔',
|
||||
' <tr>',
|
||||
' <td>Interior Lights',
|
||||
' <td>✔',
|
||||
' <td>✔',
|
||||
' <tr>',
|
||||
' <td>Electric locomotive operating sounds',
|
||||
' <td>✔',
|
||||
' <td>✔',
|
||||
' <tr>',
|
||||
' <td>Engineer’s cab lighting',
|
||||
' <td>',
|
||||
' <td>✔',
|
||||
' <tr>',
|
||||
' <td>Station Announcements - Swiss',
|
||||
' <td>',
|
||||
' <td>✔',
|
||||
' <tfoot>',
|
||||
' <tr>',
|
||||
' <td>Station Announcements - Swiss',
|
||||
' <td>',
|
||||
' <td>✔',
|
||||
' </table>',
|
||||
' <td>✔',
|
||||
' <tr>',
|
||||
' <td>Engineer’s cab lighting',
|
||||
@ -1216,7 +1254,6 @@ exports.test_data = {
|
||||
description: "Unformatted tag behavior",
|
||||
options: [],
|
||||
tests: [{
|
||||
fragment: true,
|
||||
input: '<ol>\n <li>b<pre>c</pre></li>\n</ol>',
|
||||
output: [
|
||||
'<ol>',
|
||||
@ -1226,15 +1263,15 @@ exports.test_data = {
|
||||
'</ol>'
|
||||
]
|
||||
},
|
||||
{ fragment: true, unchanged: '<ol>\n <li>b<code>c</code></li>\n</ol>' },
|
||||
{ fragment: true, unchanged: '<ul>\n <li>\n <span class="octicon octicon-person"></span>\n <a href="/contact/">Kontakt</a>\n </li>\n</ul>' },
|
||||
{ fragment: true, unchanged: '<div class="searchform"><input type="text" value="" name="s" id="s" /><input type="submit" id="searchsubmit" value="Search" /></div>' },
|
||||
{ fragment: true, unchanged: '<div class="searchform"><input type="text" value="" name="s" id="s"><input type="submit" id="searchsubmit" value="Search"></div>' },
|
||||
{ fragment: true, unchanged: '<p>\n <a href="/test/"><img src="test.jpg" /></a>\n</p>' },
|
||||
{ fragment: true, unchanged: '<p>\n <a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a>\n</p>' },
|
||||
{ fragment: true, unchanged: '<p>\n <a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a>\n</p>' },
|
||||
{ fragment: true, unchanged: '<p>\n <span>image: <img src="test.jpg" /></span><span>image: <img src="test.jpg" /></span>\n</p>' },
|
||||
{ fragment: true, unchanged: '<p>\n <strong>image: <img src="test.jpg" /></strong><strong>image: <img src="test.jpg" /></strong>\n</p>' }
|
||||
{ unchanged: '<ol>\n <li>b<code>c</code></li>\n</ol>' },
|
||||
{ unchanged: '<ul>\n <li>\n <span class="octicon octicon-person"></span>\n <a href="/contact/">Kontakt</a>\n </li>\n</ul>' },
|
||||
{ unchanged: '<div class="searchform"><input type="text" value="" name="s" id="s" /><input type="submit" id="searchsubmit" value="Search" /></div>' },
|
||||
{ unchanged: '<div class="searchform"><input type="text" value="" name="s" id="s"><input type="submit" id="searchsubmit" value="Search"></div>' },
|
||||
{ unchanged: '<p>\n <a href="/test/"><img src="test.jpg" /></a>\n</p>' },
|
||||
{ unchanged: '<p>\n <a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a>\n</p>' },
|
||||
{ unchanged: '<p>\n <a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a>\n</p>' },
|
||||
{ unchanged: '<p>\n <span>image: <img src="test.jpg" /></span><span>image: <img src="test.jpg" /></span>\n</p>' },
|
||||
{ unchanged: '<p>\n <strong>image: <img src="test.jpg" /></strong><strong>image: <img src="test.jpg" /></strong>\n</p>' }
|
||||
]
|
||||
}, {
|
||||
name: "File starting with comment",
|
||||
@ -1257,8 +1294,10 @@ exports.test_data = {
|
||||
description: "",
|
||||
options: [],
|
||||
tests: [{
|
||||
comment: 'ignore starts _after_ the start comment, ends after the end comment',
|
||||
unchanged: [
|
||||
'<!-- beautify ignore:start -->',
|
||||
'<div>',
|
||||
' <!-- beautify ignore:start -->',
|
||||
'@{',
|
||||
'',
|
||||
' ViewBag.Title = "Dashboard";',
|
||||
@ -1272,20 +1311,21 @@ exports.test_data = {
|
||||
' }',
|
||||
'',
|
||||
'}',
|
||||
'<!-- beautify ignore:end -->',
|
||||
' <!-- beautify ignore:end -->',
|
||||
'',
|
||||
'<header class="layout-header">',
|
||||
' <header class="layout-header">',
|
||||
'',
|
||||
' <h2 id="logo"><a href="/">Logo</a></h2>',
|
||||
' <h2 id="logo"><a href="/">Logo</a></h2>',
|
||||
'',
|
||||
' <ul class="social">',
|
||||
' <ul class="social">',
|
||||
'',
|
||||
' <li class="facebook"><a href="#">Facebook</a></li>',
|
||||
' <li class="twitter"><a href="#">Twitter</a></li>',
|
||||
' <li class="facebook"><a href="#">Facebook</a></li>',
|
||||
' <li class="twitter"><a href="#">Twitter</a></li>',
|
||||
'',
|
||||
' </ul>',
|
||||
' </ul>',
|
||||
'',
|
||||
'</header>'
|
||||
' </header>',
|
||||
'</div>'
|
||||
]
|
||||
}]
|
||||
}, {
|
||||
@ -1606,7 +1646,7 @@ exports.test_data = {
|
||||
' </div>',
|
||||
'</body>'
|
||||
],
|
||||
//--------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
|
||||
//.---------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
|
||||
output: [
|
||||
'<body>',
|
||||
' <div>',
|
||||
|
@ -1459,12 +1459,16 @@ exports.test_data = {
|
||||
comment: 'Directive: ignore',
|
||||
unchanged: "/* beautify ignore:start */\n/* beautify ignore:end */"
|
||||
},
|
||||
{ unchanged: "/* beautify ignore:start */\n var a,,,{ 1;\n/* beautify ignore:end */" },
|
||||
{ unchanged: "/* beautify ignore:start */\n var a,,,{ 1;\n /* beautify ignore:end */" },
|
||||
{ unchanged: "var a = 1;\n/* beautify ignore:start */\n var a = 1;\n/* beautify ignore:end */" },
|
||||
{ unchanged: "/* beautify ignore:start */ {asdklgh;y;+++;dd2d}/* beautify ignore:end */" },
|
||||
{
|
||||
input_: "var a = 1;\n/* beautify ignore:start */\n var a,,,{ 1;\n/* beautify ignore:end */",
|
||||
output: "var a = 1;\n/* beautify ignore:start */\n var a,,,{ 1;\n/* beautify ignore:end */"
|
||||
comment: 'ignore starts _after_ the start comment, ends after the end comment',
|
||||
unchanged: "/* beautify ignore:start */ {asdklgh;y;+++;dd2d}/* beautify ignore:end */"
|
||||
},
|
||||
{ unchanged: "/* beautify ignore:start */ {asdklgh;y;+++;dd2d} /* beautify ignore:end */" },
|
||||
{
|
||||
input_: "var a = 1;\n/* beautify ignore:start */\n var a,,,{ 1;\n/*beautify ignore:end*/",
|
||||
output: "var a = 1;\n/* beautify ignore:start */\n var a,,,{ 1;\n/*beautify ignore:end*/"
|
||||
},
|
||||
{
|
||||
input_: "var a = 1;\n /* beautify ignore:start */\n var a,,,{ 1;\n/* beautify ignore:end */",
|
||||
|
Loading…
x
Reference in New Issue
Block a user