clang-format: [JS] tests for async wrapping.
authorMartin Probst <martin@probst.io>
Mon, 18 Nov 2019 09:07:32 +0000 (10:07 +0100)
committerMartin Probst <martin@probst.io>
Thu, 16 Jan 2020 10:23:11 +0000 (11:23 +0100)
Summary:
Adds tests to ensure that `async method() ...` does not wrap between async and
the method name, which would cause automatic semicolon insertion.

Reviewers: krasimir

Subscribers: cfe-commits

Tags: #clang

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

clang/unittests/Format/FormatTestJS.cpp

index 619a19f1a22db97cd3e3a3be7bd560bbe9b99e2a..f5be0d7a4ab17612a72886cad2097d8bc3f59d4b 100644 (file)
@@ -737,6 +737,22 @@ TEST_F(FormatTestJS, AsyncFunctions) {
                "   function a() {\n"
                "  return   1;\n"
                "}  \n");
+  // clang-format must not insert breaks between async and function, otherwise
+  // automatic semicolon insertion may trigger (in particular in a class body).
+  verifyFormat("async function\n"
+               "hello(\n"
+               "    myparamnameiswaytooloooong) {\n"
+               "}",
+               "async function hello(myparamnameiswaytooloooong) {}",
+               getGoogleJSStyleWithColumns(10));
+  verifyFormat("class C {\n"
+               "  async hello(\n"
+               "      myparamnameiswaytooloooong) {\n"
+               "  }\n"
+               "}",
+               "class C {\n"
+               "  async hello(myparamnameiswaytooloooong) {} }",
+               getGoogleJSStyleWithColumns(10));
   verifyFormat("async function* f() {\n"
                "  yield fetch(x);\n"
                "}");