From 096a070ab3dc02323e136d246c7c8b713acadbf7 Mon Sep 17 00:00:00 2001 From: "L. D. MacKrell" Date: Thu, 27 Sep 2018 14:36:55 -0700 Subject: [PATCH] Add tests for indent scripts option *Add indent_scripts to README --- README.md | 1 + js/test/generated/beautify-html-tests.js | 110 +++++++++++++++++++++++ test/data/html/tests.js | 72 +++++++++++++++ 3 files changed, 183 insertions(+) diff --git a/README.md b/README.md index 17da4bc21..51f1bad1a 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/js/test/generated/beautify-html-tests.js b/js/test/generated/beautify-html-tests.js index 475b57d29..dc41a3421 100644 --- a/js/test/generated/beautify-html-tests.js +++ b/js/test/generated/beautify-html-tests.js @@ -5942,6 +5942,116 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be ''); + //============================================================ + // Tests script indent behavior - (indent_scripts = ""normal"") + reset_options(); + set_name('Tests script indent behavior - (indent_scripts = ""normal"")'); + opts.indent_scripts = 'normal'; + test_fragment( + '\n' + + '\n' + + '\n' + + '', + // -- output -- + '\n' + + ' \n' + + ' \n' + + ''); + test_fragment( + '\n' + + ' \n' + + ' \n' + + ''); + + // Tests script indent behavior - (indent_scripts = ""keep"") + reset_options(); + set_name('Tests script indent behavior - (indent_scripts = ""keep"")'); + opts.indent_scripts = 'keep'; + test_fragment( + '\n' + + '\n' + + '\n' + + '', + // -- output -- + '\n' + + ' \n' + + ' \n' + + ''); + test_fragment( + '\n' + + ' \n' + + ' \n' + + ''); + + // Tests script indent behavior - (indent_scripts = ""separate"") + reset_options(); + set_name('Tests script indent behavior - (indent_scripts = ""separate"")'); + opts.indent_scripts = 'separate'; + test_fragment( + '\n' + + '\n' + + '\n' + + '', + // -- output -- + '\n' + + ' \n' + + ' \n' + + ''); + test_fragment( + '\n' + + ' \n' + + ' \n' + + ''); + + //============================================================ // underscore.js formatting reset_options(); diff --git a/test/data/html/tests.js b/test/data/html/tests.js index 962839284..90a1e50b1 100644 --- a/test/data/html/tests.js +++ b/test/data/html/tests.js @@ -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: [ + '', + '', + '', + '' + ], + output: [ + '', + '{{h}}', + '{{h}}', + '' + ] + }, + { + fragment: true, + unchanged: [ + '', + '{{h}} ', + '{{h}} ', + '' + ] + } + ] }, { name: "underscore.js formatting", description: "underscore.js templates (<% ... %>) treated as comments.",