aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-03-10 11:27:30 +0800
committerGitHub <noreply@github.com>2017-03-10 11:27:30 +0800
commitbe80f7e706cd6eb1c5f06e433804fda589a8968a (patch)
tree736f9545e201a14e6aaf461d7289061f6687a0a4 /test
parentcf45e2f79b543ebae60c5de54166b20da4522c25 (diff)
downloadtracifyjs-be80f7e706cd6eb1c5f06e433804fda589a8968a.tar.gz
tracifyjs-be80f7e706cd6eb1c5f06e433804fda589a8968a.zip
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.
Diffstat (limited to 'test')
-rw-r--r--test/compress/loops.js50
-rw-r--r--test/compress/max_line_len.js15
-rwxr-xr-xtest/run-tests.js24
3 files changed, 77 insertions, 12 deletions
diff --git a/test/compress/loops.js b/test/compress/loops.js
index df3011cd..7581e758 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 b9e09178..7ad9ee0e 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 15a12c6b..36d26ef7 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;
}