From 335e349314963e1761f7531656a64efaff548ceb Mon Sep 17 00:00:00 2001 From: Richard van Velzen Date: Wed, 28 Oct 2015 20:50:01 +0100 Subject: [PATCH] Allow specification beautify options in tests Caught an error in #847 as well - `output` wasn't passed anywhere which led to an exception. `options` was available though. --- lib/output.js | 2 +- test/compress/screw-ie8.js | 18 ++++++++++++++++++ test/run-tests.js | 17 +++++++++-------- 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 test/compress/screw-ie8.js diff --git a/lib/output.js b/lib/output.js index 5d75e703..b7f69717 100644 --- a/lib/output.js +++ b/lib/output.js @@ -95,7 +95,7 @@ function OutputStream(options) { case "\f": return "\\f"; case "\n": return "\\n"; case "\r": return "\\r"; - case "\x0B": return output.option("screw_ie8") ? "\\v" : "\\x0B"; + case "\x0B": return options.screw_ie8 ? "\\v" : "\\x0B"; case "\u2028": return "\\u2028"; case "\u2029": return "\\u2029"; case '"': ++dq; return '"'; diff --git a/test/compress/screw-ie8.js b/test/compress/screw-ie8.js new file mode 100644 index 00000000..527aea04 --- /dev/null +++ b/test/compress/screw-ie8.js @@ -0,0 +1,18 @@ +do_screw: { + options = { screw_ie8: true }; + beautify = { + screw_ie8: true, + ascii_only: true + }; + + input: f("\v"); + expect_exact: 'f("\\v");'; +} + +dont_screw: { + options = { screw_ie8: false }; + beautify = { screw_ie8: false, ascii_only: true }; + + input: f("\v"); + expect_exact: 'f("\\x0B");'; +} \ No newline at end of file diff --git a/test/run-tests.js b/test/run-tests.js index 1e9eb3cb..7f6166fe 100755 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -87,20 +87,21 @@ function run_compress_tests() { warnings: false }); var cmp = new U.Compressor(options, true); + var output_options = test.beautify || {}; var expect; if (test.expect) { - expect = make_code(as_toplevel(test.expect), false); + expect = make_code(as_toplevel(test.expect), output_options); } else { expect = test.expect_exact; } var input = as_toplevel(test.input); - var input_code = make_code(test.input); + var input_code = make_code(test.input, { beautify: true }); if (test.mangle_props) { input = U.mangle_properties(input, test.mangle_props); } var output = input.transform(cmp); output.figure_out_scope(); - output = make_code(output, false); + output = make_code(output, output_options); if (expect != output) { log("!!! failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n---EXPECTED---\n{expected}\n\n", { input: input_code, @@ -144,7 +145,7 @@ function parse_test(file) { file: file, line: node.start.line, col: node.start.col, - code: make_code(node, false) + code: make_code(node, { beautify: false }) })); } @@ -191,15 +192,15 @@ function parse_test(file) { }; } -function make_code(ast, beautify) { - if (arguments.length == 1) beautify = true; - var stream = U.OutputStream({ beautify: beautify, inline_script: true }); +function make_code(ast, options) { + options.inline_script = true; + var stream = U.OutputStream(options); ast.print(stream); return stream.get(); } function evaluate(code) { if (code instanceof U.AST_Node) - code = make_code(code); + code = make_code(code, { beautify: true }); return new Function("return(" + code + ")")(); } -- 2.34.1