Browse Source

clang-format: [JS] wrap and indent `goog.setTestOnly` calls.

Summary:
While `goog.setTestOnly` usually appears in the imports section of a file, it is
not actually an import, and also usually doesn't take long parameters (nor
namespaces as a parameter, it's a description/message that should be wrapped).

This fixes a regression where a `goog.setTestOnly` call nested in a function was
not wrapped.

Reviewers: djasper

Subscribers: klimek

Differential Revision: https://reviews.llvm.org/D37685

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312918 91177308-0d34-0410-b5e6-96231b3b80d8
Martin Probst 8 years ago
parent
commit
aae8a30c39
2 changed files with 6 additions and 3 deletions
  1. 0 1
      lib/Format/TokenAnnotator.cpp
  2. 6 2
      unittests/Format/FormatTestJS.cpp

+ 0 - 1
lib/Format/TokenAnnotator.cpp

@@ -960,7 +960,6 @@ private:
            Tok.Next->Next && (Tok.Next->Next->TokenText == "module" ||
                               Tok.Next->Next->TokenText == "provide" ||
                               Tok.Next->Next->TokenText == "require" ||
-                              Tok.Next->Next->TokenText == "setTestOnly" ||
                               Tok.Next->Next->TokenText == "forwardDeclare") &&
            Tok.Next->Next->Next && Tok.Next->Next->Next->is(tok::l_paren);
   }

+ 6 - 2
unittests/Format/FormatTestJS.cpp

@@ -558,8 +558,6 @@ TEST_F(FormatTestJS, GoogModules) {
                getGoogleJSStyleWithColumns(40));
   verifyFormat("var long = goog.require('this.is.really.absurdly.long');",
                getGoogleJSStyleWithColumns(40));
-  verifyFormat("goog.setTestOnly('this.is.really.absurdly.long');",
-               getGoogleJSStyleWithColumns(40));
   verifyFormat("goog.forwardDeclare('this.is.really.absurdly.long');",
                getGoogleJSStyleWithColumns(40));
 
@@ -567,6 +565,12 @@ TEST_F(FormatTestJS, GoogModules) {
   verifyFormat(
       "var MyLongClassName =\n"
       "    goog.module.get('my.long.module.name.followedBy.MyLongClassName');");
+  verifyFormat("function a() {\n"
+               "  goog.setTestOnly();\n"
+               "}\n",
+               "function a() {\n"
+               "goog.setTestOnly();\n"
+               "}\n");
 }
 
 TEST_F(FormatTestJS, FormatsNamespaces) {