Allow specification beautify options in tests
authorRichard van Velzen <rvanvelzen@experty.com>
Wed, 28 Oct 2015 19:50:01 +0000 (20:50 +0100)
committerRichard van Velzen <rvanvelzen@experty.com>
Wed, 28 Oct 2015 19:50:01 +0000 (20:50 +0100)
Caught an error in #847 as well - `output` wasn't passed anywhere which led to an exception. `options` was available though.

lib/output.js
test/compress/screw-ie8.js [new file with mode: 0644]
test/run-tests.js

index 5d75e70..b7f6971 100644 (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 '"';
diff --git a/test/compress/screw-ie8.js b/test/compress/screw-ie8.js
new file mode 100644 (file)
index 0000000..527aea0
--- /dev/null
@@ -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
index 1e9eb3c..7f6166f 100755 (executable)
@@ -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 + ")")();
 }