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.
This commit is contained in:
Richard van Velzen
2015-10-28 20:50:01 +01:00
parent 2a88d07b3a
commit 335e349314
3 changed files with 28 additions and 9 deletions

View File

@@ -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 '"';

View File

@@ -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");';
}

View File

@@ -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 + ")")();
}