[Pkg-javascript-commits] [uglifyjs] 104/228: support multi-line string in tests (#1590)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:21 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository uglifyjs.

commit be80f7e706cd6eb1c5f06e433804fda589a8968a
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Fri Mar 10 11:27:30 2017 +0800

    support multi-line string in tests (#1590)
    
    `expect_exact` sometimes have multiple lines and `\n` are hard to read.
    
    Use array of strings to emulate line breaks and improve readability.
---
 test/compress/loops.js        | 50 +++++++++++++++++++++++++++++++++++++++----
 test/compress/max_line_len.js | 15 +++++++++++--
 test/run-tests.js             | 24 +++++++++++++++------
 3 files changed, 77 insertions(+), 12 deletions(-)

diff --git a/test/compress/loops.js b/test/compress/loops.js
index df3011c..7581e75 100644
--- a/test/compress/loops.js
+++ b/test/compress/loops.js
@@ -295,7 +295,15 @@ issue_186_beautify: {
         else
             bar();
     }
-    expect_exact: 'var x = 3;\n\nif (foo()) do {\n    do {\n        alert(x);\n    } while (--x);\n} while (x); else bar();'
+    expect_exact: [
+        'var x = 3;',
+        '',
+        'if (foo()) do {',
+        '    do {',
+        '        alert(x);',
+        '    } while (--x);',
+        '} while (x); else bar();',
+    ]
 }
 
 issue_186_beautify_ie8: {
@@ -314,7 +322,17 @@ issue_186_beautify_ie8: {
         else
             bar();
     }
-    expect_exact: 'var x = 3;\n\nif (foo()) {\n    do {\n        do {\n            alert(x);\n        } while (--x);\n    } while (x);\n} else bar();'
+    expect_exact: [
+        'var x = 3;',
+        '',
+        'if (foo()) {',
+        '    do {',
+        '        do {',
+        '            alert(x);',
+        '        } while (--x);',
+        '    } while (x);',
+        '} else bar();',
+    ]
 }
 
 issue_186_bracketize: {
@@ -374,7 +392,19 @@ issue_186_beautify_bracketize: {
         else
             bar();
     }
-    expect_exact: 'var x = 3;\n\nif (foo()) {\n    do {\n        do {\n            alert(x);\n        } while (--x);\n    } while (x);\n} else {\n    bar();\n}'
+    expect_exact: [
+        'var x = 3;',
+        '',
+        'if (foo()) {',
+        '    do {',
+        '        do {',
+        '            alert(x);',
+        '        } while (--x);',
+        '    } while (x);',
+        '} else {',
+        '    bar();',
+        '}',
+    ]
 }
 
 issue_186_beautify_bracketize_ie8: {
@@ -394,5 +424,17 @@ issue_186_beautify_bracketize_ie8: {
         else
             bar();
     }
-    expect_exact: 'var x = 3;\n\nif (foo()) {\n    do {\n        do {\n            alert(x);\n        } while (--x);\n    } while (x);\n} else {\n    bar();\n}'
+    expect_exact: [
+        'var x = 3;',
+        '',
+        'if (foo()) {',
+        '    do {',
+        '        do {',
+        '            alert(x);',
+        '        } while (--x);',
+        '    } while (x);',
+        '} else {',
+        '    bar();',
+        '}',
+    ]
 }
diff --git a/test/compress/max_line_len.js b/test/compress/max_line_len.js
index b9e0917..7ad9ee0 100644
--- a/test/compress/max_line_len.js
+++ b/test/compress/max_line_len.js
@@ -7,7 +7,13 @@ too_short: {
             return { c: 42, d: a(), e: "foo"};
         }
     }
-    expect_exact: 'function f(a){\nreturn{\nc:42,\nd:a(),\ne:"foo"}}'
+    expect_exact: [
+        'function f(a){',
+        'return{',
+        'c:42,',
+        'd:a(),',
+        'e:"foo"}}',
+    ]
     expect_warnings: [
         "WARN: Output exceeds 10 characters"
     ]
@@ -22,7 +28,12 @@ just_enough: {
             return { c: 42, d: a(), e: "foo"};
         }
     }
-    expect_exact: 'function f(a){\nreturn{c:42,\nd:a(),e:"foo"}\n}'
+    expect_exact: [
+        'function f(a){',
+        'return{c:42,',
+        'd:a(),e:"foo"}',
+        '}',
+    ]
     expect_warnings: [
     ]
 }
diff --git a/test/run-tests.js b/test/run-tests.js
index 15a12c6..36d26ef 100755
--- a/test/run-tests.js
+++ b/test/run-tests.js
@@ -214,6 +214,23 @@ function parse_test(file) {
         }));
     }
 
+    function read_string(stat) {
+        if (stat.TYPE === "SimpleStatement") {
+            var body = stat.body;
+            out: switch(body.TYPE) {
+              case "String":
+                return body.value;
+              case "Array":
+                return body.elements.map(function(element) {
+                    if (element.TYPE !== "String")
+                        throw new Error("Should be array of strings");
+                    return element.value;
+                }).join("\n");
+            }
+        }
+        throw new Error("Should be string or array of strings");
+    }
+
     function get_one_test(name, block) {
         var test = { name: name, options: {} };
         var tw = new U.TreeWalker(function(node, descend){
@@ -240,12 +257,7 @@ function parse_test(file) {
                     else if (stat.body.length == 0) stat = new U.AST_EmptyStatement();
                 }
                 if (node.label.name === "expect_exact") {
-                    if (!(stat.TYPE === "SimpleStatement" && stat.body.TYPE === "String")) {
-                        throw new Error(
-                            "The value of the expect_exact clause should be a string, " +
-                            "like `expect_exact: \"some.exact.javascript;\"`");
-                    }
-                    test[node.label.name] = stat.body.start.value
+                    test[node.label.name] = read_string(stat);
                 } else {
                     test[node.label.name] = stat;
                 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list