summaryrefslogtreecommitdiffstats
path: root/clang/unittests
diff options
context:
space:
mode:
authorMartin Probst <martin@probst.io>2016-06-13 16:39:50 +0000
committerMartin Probst <martin@probst.io>2016-06-13 16:39:50 +0000
commit0cd74ee87557836ca25604c9895c546e0a6e648e (patch)
tree8a7ee83c3f079c67401530a1cb24e9a5555a5107 /clang/unittests
parentdb176c11dc3d78b3cfbf623eb3fe71532a80a91f (diff)
downloadbcm5719-llvm-0cd74ee87557836ca25604c9895c546e0a6e648e.tar.gz
bcm5719-llvm-0cd74ee87557836ca25604c9895c546e0a6e648e.zip
clang-format: [JS] Introduce JavaScriptWrapImports option.
Summary: When turned on, clang-format wraps JavaScript imports (and importing exports), instead of forcing the entire import statement onto one line. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D21273 llvm-svn: 272558
Diffstat (limited to 'clang/unittests')
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp27
-rw-r--r--clang/unittests/Format/SortImportsTestJS.cpp8
2 files changed, 28 insertions, 7 deletions
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index ffcc34d971f..36c3dd08cba 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -1007,9 +1007,6 @@ TEST_F(FormatTestJS, Modules) {
verifyFormat("import SomeThing from 'some/module.js';");
verifyFormat("import {X, Y} from 'some/module.js';");
verifyFormat("import a, {X, Y} from 'some/module.js';");
- verifyFormat("import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,"
- " VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying"
- "} from 'some/module.js';");
verifyFormat("import {X, Y,} from 'some/module.js';");
verifyFormat("import {X as myLocalX, Y as myLocalY} from 'some/module.js';");
// Ensure Automatic Semicolon Insertion does not break on "as\n".
@@ -1078,6 +1075,30 @@ TEST_F(FormatTestJS, Modules) {
"}");
}
+TEST_F(FormatTestJS, ImportWrapping) {
+ verifyFormat("import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,"
+ " VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying"
+ "} from 'some/module.js';");
+ FormatStyle Style = getGoogleJSStyleWithColumns(80);
+ Style.JavaScriptWrapImports = true;
+ verifyFormat("import {\n"
+ " VeryLongImportsAreAnnoying,\n"
+ " VeryLongImportsAreAnnoying,\n"
+ " VeryLongImportsAreAnnoying,\n"
+ "} from 'some/module.js';",
+ Style);
+ verifyFormat("import {\n"
+ " A,\n"
+ " A,\n"
+ "} from 'some/module.js';",
+ Style);
+ verifyFormat("export {\n"
+ " A,\n"
+ " A,\n"
+ "} from 'some/module.js';",
+ Style);
+}
+
TEST_F(FormatTestJS, TemplateStrings) {
// Keeps any whitespace/indentation within the template string.
verifyFormat("var x = `hello\n"
diff --git a/clang/unittests/Format/SortImportsTestJS.cpp b/clang/unittests/Format/SortImportsTestJS.cpp
index 17e73b08554..cc408ca9da7 100644
--- a/clang/unittests/Format/SortImportsTestJS.cpp
+++ b/clang/unittests/Format/SortImportsTestJS.cpp
@@ -92,12 +92,12 @@ TEST_F(SortImportsTestJS, SeparateMainCodeBody) {
TEST_F(SortImportsTestJS, Comments) {
verifySort("/** @fileoverview This is a great file. */\n"
"// A very important import follows.\n"
- "import {sym} from 'a'; /* more comments */\n"
- "import {sym} from 'b'; // from //foo:bar\n",
+ "import {sym} from 'a'; /* more comments */\n"
+ "import {sym} from 'b'; // from //foo:bar\n",
"/** @fileoverview This is a great file. */\n"
- "import {sym} from 'b'; // from //foo:bar\n"
+ "import {sym} from 'b'; // from //foo:bar\n"
"// A very important import follows.\n"
- "import {sym} from 'a'; /* more comments */\n");
+ "import {sym} from 'a'; /* more comments */\n");
}
TEST_F(SortImportsTestJS, SortStar) {
OpenPOWER on IntegriCloud