]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Add tests to ensure clang-format doesn't break code
authorDaniel Jasper <djasper@google.com>
Fri, 12 Jun 2015 04:58:27 +0000 (04:58 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 12 Jun 2015 04:58:27 +0000 (04:58 +0000)
by triggering automatic semicolon insertion changes.

NFC intended. Patch by Martin Probst.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239594 91177308-0d34-0410-b5e6-96231b3b80d8

unittests/Format/FormatTestJS.cpp

index 0f9f38240a3687a3208cd36299550db0ad3a346e..888d73d48ee3b129e3dcd4ad7d7e3985b9176a10 100644 (file)
@@ -521,6 +521,18 @@ TEST_F(FormatTestJS, ReturnStatements) {
                "}");
 }
 
+TEST_F(FormatTestJS, AutomaticSemicolonInsertion) {
+  // The following statements must not wrap, as otherwise the program meaning
+  // would change due to automatic semicolon insertion.
+  // See http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1.
+  verifyFormat("return aaaaa;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("continue aaaaa;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("break aaaaa;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("throw aaaaa;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("aaaaaaaaa++;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("aaaaaaaaa--;", getGoogleJSStyleWithColumns(10));
+}
+
 TEST_F(FormatTestJS, ClosureStyleCasts) {
   verifyFormat("var x = /** @type {foo} */ (bar);");
 }