mirror of
https://github.com/beautifier/js-beautify.git
synced 2024-11-23 04:40:06 +00:00
Add tests for indent scripts option
*Add indent_scripts to README
This commit is contained in:
parent
234369df03
commit
096a070ab3
@ -335,6 +335,7 @@ HTML Beautifier Options:
|
||||
-T, --content_unformatted List of tags (defaults to pre) whose content should not be reformatted
|
||||
-E, --extra_liners List of tags (defaults to [head,body,/html] that should have an extra newline before them.
|
||||
--editorconfig Use EditorConfig to set up the options
|
||||
--indent_scripts Sets indent level inside script tags ("normal", "keep", "separate")
|
||||
```
|
||||
|
||||
## Directives to Ignore or Preserve sections (Javascript beautifier only)
|
||||
|
@ -5942,6 +5942,116 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
|
||||
'</body>');
|
||||
|
||||
|
||||
//============================================================
|
||||
// Tests script indent behavior - (indent_scripts = ""normal"")
|
||||
reset_options();
|
||||
set_name('Tests script indent behavior - (indent_scripts = ""normal"")');
|
||||
opts.indent_scripts = 'normal';
|
||||
test_fragment(
|
||||
'<head>\n' +
|
||||
'<script>\n' +
|
||||
'if (a == b) {\n' +
|
||||
'test();\n' +
|
||||
'}\n' +
|
||||
'</script>\n' +
|
||||
'<style>\n' +
|
||||
'.selector {\n' +
|
||||
'font-size: 12px;\n' +
|
||||
'}\n' +
|
||||
'</style>\n' +
|
||||
'</head>',
|
||||
// -- output --
|
||||
'<head>\n' +
|
||||
' <script>\n' +
|
||||
' if (a == b) {\n' +
|
||||
' test();\n' +
|
||||
' }\n' +
|
||||
' </script>\n' +
|
||||
' <style>\n' +
|
||||
' .selector {\n' +
|
||||
' font-size: 12px;\n' +
|
||||
' }\n' +
|
||||
' </style>\n' +
|
||||
'</head>');
|
||||
test_fragment(
|
||||
'<body>\n' +
|
||||
' <script src="one.js"></script> <!-- one -->\n' +
|
||||
' <script src="two.js"></script> <!-- two-->\n' +
|
||||
'</body>');
|
||||
|
||||
// Tests script indent behavior - (indent_scripts = ""keep"")
|
||||
reset_options();
|
||||
set_name('Tests script indent behavior - (indent_scripts = ""keep"")');
|
||||
opts.indent_scripts = 'keep';
|
||||
test_fragment(
|
||||
'<head>\n' +
|
||||
'<script>\n' +
|
||||
'if (a == b) {\n' +
|
||||
'test();\n' +
|
||||
'}\n' +
|
||||
'</script>\n' +
|
||||
'<style>\n' +
|
||||
'.selector {\n' +
|
||||
'font-size: 12px;\n' +
|
||||
'}\n' +
|
||||
'</style>\n' +
|
||||
'</head>',
|
||||
// -- output --
|
||||
'<head>\n' +
|
||||
' <script>\n' +
|
||||
' if (a == b) {\n' +
|
||||
' test();\n' +
|
||||
' }\n' +
|
||||
' </script>\n' +
|
||||
' <style>\n' +
|
||||
' .selector {\n' +
|
||||
' font-size: 12px;\n' +
|
||||
' }\n' +
|
||||
' </style>\n' +
|
||||
'</head>');
|
||||
test_fragment(
|
||||
'<body>\n' +
|
||||
' <script src="one.js"></script> <!-- one -->\n' +
|
||||
' <script src="two.js"></script> <!-- two-->\n' +
|
||||
'</body>');
|
||||
|
||||
// Tests script indent behavior - (indent_scripts = ""separate"")
|
||||
reset_options();
|
||||
set_name('Tests script indent behavior - (indent_scripts = ""separate"")');
|
||||
opts.indent_scripts = 'separate';
|
||||
test_fragment(
|
||||
'<head>\n' +
|
||||
'<script>\n' +
|
||||
'if (a == b) {\n' +
|
||||
'test();\n' +
|
||||
'}\n' +
|
||||
'</script>\n' +
|
||||
'<style>\n' +
|
||||
'.selector {\n' +
|
||||
'font-size: 12px;\n' +
|
||||
'}\n' +
|
||||
'</style>\n' +
|
||||
'</head>',
|
||||
// -- output --
|
||||
'<head>\n' +
|
||||
' <script>\n' +
|
||||
'if (a == b) {\n' +
|
||||
' test();\n' +
|
||||
'}\n' +
|
||||
' </script>\n' +
|
||||
' <style>\n' +
|
||||
'.selector {\n' +
|
||||
' font-size: 12px;\n' +
|
||||
'}\n' +
|
||||
' </style>\n' +
|
||||
'</head>');
|
||||
test_fragment(
|
||||
'<body>\n' +
|
||||
' <script src="one.js"></script> <!-- one -->\n' +
|
||||
' <script src="two.js"></script> <!-- two-->\n' +
|
||||
'</body>');
|
||||
|
||||
|
||||
//============================================================
|
||||
// underscore.js formatting
|
||||
reset_options();
|
||||
|
@ -1684,6 +1684,78 @@ exports.test_data = {
|
||||
]
|
||||
}
|
||||
]
|
||||
}, {
|
||||
name: "Tests script indent behavior",
|
||||
description: "Tests script indenting behavior",
|
||||
matrix: [{
|
||||
options: [
|
||||
{ name: "indent_scripts", value: "'normal'" }
|
||||
],
|
||||
h: ' ',
|
||||
c: ' ',
|
||||
j: ' ',
|
||||
hscript: ' '
|
||||
},
|
||||
{
|
||||
options: [
|
||||
{ name: "indent_scripts", value: "'keep'" }
|
||||
],
|
||||
h: ' ',
|
||||
c: ' ',
|
||||
j: ' ',
|
||||
hscript: ' '
|
||||
},
|
||||
{
|
||||
options: [
|
||||
{ name: "indent_scripts", value: "'separate'" }
|
||||
],
|
||||
h: ' ',
|
||||
c: ' ',
|
||||
j: ' ',
|
||||
hscript: ''
|
||||
}
|
||||
],
|
||||
tests: [{
|
||||
fragment: true,
|
||||
input: [
|
||||
'<head>',
|
||||
'<script>',
|
||||
'if (a == b) {',
|
||||
'test();',
|
||||
'}',
|
||||
'</script>',
|
||||
'<style>',
|
||||
'.selector {',
|
||||
'font-size: 12px;',
|
||||
'}',
|
||||
'</style>',
|
||||
'</head>'
|
||||
],
|
||||
output: [
|
||||
'<head>',
|
||||
'{{h}}<script>',
|
||||
'{{hscript}}if (a == b) {',
|
||||
'{{hscript}}{{j}}test();',
|
||||
'{{hscript}}}',
|
||||
'{{h}}</script>',
|
||||
'{{h}}<style>',
|
||||
'{{hscript}}.selector {',
|
||||
'{{hscript}}{{c}}font-size: 12px;',
|
||||
'{{hscript}}}',
|
||||
'{{h}}</style>',
|
||||
'</head>'
|
||||
]
|
||||
},
|
||||
{
|
||||
fragment: true,
|
||||
unchanged: [
|
||||
'<body>',
|
||||
'{{h}}<script src="one.js"></script> <!-- one -->',
|
||||
'{{h}}<script src="two.js"></script> <!-- two-->',
|
||||
'</body>'
|
||||
]
|
||||
}
|
||||
]
|
||||
}, {
|
||||
name: "underscore.js formatting",
|
||||
description: "underscore.js templates (<% ... %>) treated as comments.",
|
||||
|
Loading…
Reference in New Issue
Block a user