aboutsummaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-07-05 14:23:59 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-07-05 14:23:59 +0000
commitc192b3dcffd5e672a2b2e1730e2440febb4fb192 (patch)
treeac719b5984165053bf83d71142e4d96b609b9784 /unittests
parent2e645aa5697838f16ec570eb07c2bee7e13d0e0b (diff)
downloadsrc-c192b3dcffd5e672a2b2e1730e2440febb4fb192.tar.gz
src-c192b3dcffd5e672a2b2e1730e2440febb4fb192.zip
Notes
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ASTMatchers/ASTMatchersTest.cpp8
-rw-r--r--unittests/CodeGen/BufferSourceTest.cpp2
-rw-r--r--unittests/Format/FormatTest.cpp92
-rw-r--r--unittests/Format/FormatTestJS.cpp30
-rw-r--r--unittests/Format/FormatTestJava.cpp2
-rw-r--r--unittests/Format/FormatTestProto.cpp4
6 files changed, 113 insertions, 25 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp
index ae363e974b5d..8ef3f15e4c08 100644
--- a/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -482,6 +482,10 @@ TEST(DeclarationMatcher, MatchAnyOf) {
EXPECT_TRUE(matches("int F() { return 1 + 2; }", MixedTypes));
EXPECT_TRUE(matches("int F() { if (true) return 1; }", MixedTypes));
EXPECT_TRUE(notMatches("int F() { return 1; }", MixedTypes));
+
+ EXPECT_TRUE(
+ matches("void f() try { } catch (int) { } catch (...) { }",
+ catchStmt(anyOf(hasDescendant(varDecl()), isCatchAll()))));
}
TEST(DeclarationMatcher, MatchHas) {
@@ -3321,6 +3325,10 @@ TEST(ExceptionHandling, SimpleCases) {
throwExpr()));
EXPECT_TRUE(matches("void foo() try { throw 5;} catch(int X) { }",
throwExpr()));
+ EXPECT_TRUE(matches("void foo() try { throw; } catch(...) { }",
+ catchStmt(isCatchAll())));
+ EXPECT_TRUE(notMatches("void foo() try { throw; } catch(int) { }",
+ catchStmt(isCatchAll())));
}
TEST(HasConditionVariableStatement, DoesNotMatchCondition) {
diff --git a/unittests/CodeGen/BufferSourceTest.cpp b/unittests/CodeGen/BufferSourceTest.cpp
index b2a8ba580844..e80e83bd2887 100644
--- a/unittests/CodeGen/BufferSourceTest.cpp
+++ b/unittests/CodeGen/BufferSourceTest.cpp
@@ -62,6 +62,8 @@ TEST(BufferSourceTest, EmitCXXGlobalInitFunc) {
CreateLLVMCodeGen(
compiler.getDiagnostics(),
"EmitCXXGlobalInitFuncTest",
+ compiler.getHeaderSearchOpts(),
+ compiler.getPreprocessorOpts(),
compiler.getCodeGenOpts(),
llvm::getGlobalContext())));
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index ed2658b3c143..0d85789a1ddb 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -2391,6 +2391,27 @@ TEST_F(FormatTest, FormatObjCTryCatch) {
"});\n");
}
+TEST_F(FormatTest, FormatObjCAutoreleasepool) {
+ FormatStyle Style = getLLVMStyle();
+ verifyFormat("@autoreleasepool {\n"
+ " f();\n"
+ "}\n"
+ "@autoreleasepool {\n"
+ " f();\n"
+ "}\n",
+ Style);
+ Style.BreakBeforeBraces = FormatStyle::BS_Allman;
+ verifyFormat("@autoreleasepool\n"
+ "{\n"
+ " f();\n"
+ "}\n"
+ "@autoreleasepool\n"
+ "{\n"
+ " f();\n"
+ "}\n",
+ Style);
+}
+
TEST_F(FormatTest, StaticInitializers) {
verifyFormat("static SomeClass SC = {1, 'a'};");
@@ -3163,6 +3184,8 @@ TEST_F(FormatTest, LayoutNestedBlocks) {
"}, a);",
Style);
+ verifyFormat("SomeFunction({MACRO({ return output; }), b});");
+
verifyNoCrash("^{v^{a}}");
}
@@ -3900,10 +3923,12 @@ TEST_F(FormatTest, BreaksDesireably) {
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
- // Indent consistently independent of call expression.
+ // Indent consistently independent of call expression and unary operator.
+ verifyFormat("aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(\n"
+ " dddddddddddddddddddddddddddddd));");
+ verifyFormat("aaaaaaaaaaa(!bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(\n"
+ " dddddddddddddddddddddddddddddd));");
verifyFormat("aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccc(\n"
- " dddddddddddddddddddddddddddddd));\n"
- "aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(\n"
" dddddddddddddddddddddddddddddd));");
// This test case breaks on an incorrect memoization, i.e. an optimization not
@@ -4595,30 +4620,50 @@ TEST_F(FormatTest, AlignsStringLiterals) {
" \"c\";");
}
-TEST_F(FormatTest, AlwaysBreakAfterDefinitionReturnType) {
- FormatStyle AfterType = getLLVMStyle();
- AfterType.AlwaysBreakAfterDefinitionReturnType = true;
+TEST_F(FormatTest, DefinitionReturnTypeBreakingStyle) {
+ FormatStyle Style = getLLVMStyle();
+ Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_TopLevel;
+ verifyFormat("class C {\n"
+ " int f() { return 1; }\n"
+ "};\n"
+ "int\n"
+ "f() {\n"
+ " return 1;\n"
+ "}",
+ Style);
+ Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
+ verifyFormat("class C {\n"
+ " int\n"
+ " f() {\n"
+ " return 1;\n"
+ " }\n"
+ "};\n"
+ "int\n"
+ "f() {\n"
+ " return 1;\n"
+ "}",
+ Style);
verifyFormat("const char *\n"
"f(void) {\n" // Break here.
" return \"\";\n"
"}\n"
"const char *bar(void);\n", // No break here.
- AfterType);
+ Style);
verifyFormat("template <class T>\n"
"T *\n"
"f(T &c) {\n" // Break here.
" return NULL;\n"
"}\n"
"template <class T> T *f(T &c);\n", // No break here.
- AfterType);
- AfterType.BreakBeforeBraces = FormatStyle::BS_Stroustrup;
+ Style);
+ Style.BreakBeforeBraces = FormatStyle::BS_Stroustrup;
verifyFormat("const char *\n"
"f(void)\n" // Break here.
"{\n"
" return \"\";\n"
"}\n"
"const char *bar(void);\n", // No break here.
- AfterType);
+ Style);
verifyFormat("template <class T>\n"
"T *\n" // Problem here: no line break
"f(T &c)\n" // Break here.
@@ -4626,7 +4671,7 @@ TEST_F(FormatTest, AlwaysBreakAfterDefinitionReturnType) {
" return NULL;\n"
"}\n"
"template <class T> T *f(T &c);\n", // No break here.
- AfterType);
+ Style);
}
TEST_F(FormatTest, AlwaysBreakBeforeMultilineStrings) {
@@ -5169,7 +5214,7 @@ TEST_F(FormatTest, DoesNotIndentRelativeToUnaryOperators) {
" aaaaa)) {\n"
"}");
verifyFormat("aaaaaaaaaa(!aaaaaaaaaa( // break\n"
- " aaaaa));");
+ " aaaaa));");
verifyFormat("*aaa = aaaaaaa( // break\n"
" bbbbbb);");
}
@@ -5213,11 +5258,6 @@ TEST_F(FormatTest, UnderstandsOverloadedOperators) {
verifyGoogleFormat("operator ::A();");
verifyFormat("using A::operator+;");
-
- verifyFormat("string // break\n"
- "operator()() & {}");
- verifyFormat("string // break\n"
- "operator()() && {}");
}
TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
@@ -5481,6 +5521,14 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyFormat("A = new SomeType *[Length]();", PointerMiddle);
verifyFormat("A = new SomeType *[Length];", PointerMiddle);
verifyFormat("T ** t = new T *;", PointerMiddle);
+
+ // Member function reference qualifiers aren't binary operators.
+ verifyFormat("string // break\n"
+ "operator()() & {}");
+ verifyFormat("string // break\n"
+ "operator()() && {}");
+ verifyGoogleFormat("template <typename T>\n"
+ "auto x() & -> int {}");
}
TEST_F(FormatTest, UnderstandsAttributes) {
@@ -9018,7 +9066,6 @@ TEST_F(FormatTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
CHECK_PARSE_BOOL(AllowShortIfStatementsOnASingleLine);
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
- CHECK_PARSE_BOOL(AlwaysBreakAfterDefinitionReturnType);
CHECK_PARSE_BOOL(AlwaysBreakTemplateDeclarations);
CHECK_PARSE_BOOL(BinPackParameters);
CHECK_PARSE_BOOL(BinPackArguments);
@@ -9151,6 +9198,15 @@ TEST_F(FormatTest, ParsesConfiguration) {
FormatStyle::BS_Allman);
CHECK_PARSE("BreakBeforeBraces: GNU", BreakBeforeBraces, FormatStyle::BS_GNU);
+ Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
+ CHECK_PARSE("AlwaysBreakAfterDefinitionReturnType: None",
+ AlwaysBreakAfterDefinitionReturnType, FormatStyle::DRTBS_None);
+ CHECK_PARSE("AlwaysBreakAfterDefinitionReturnType: All",
+ AlwaysBreakAfterDefinitionReturnType, FormatStyle::DRTBS_All);
+ CHECK_PARSE("AlwaysBreakAfterDefinitionReturnType: TopLevel",
+ AlwaysBreakAfterDefinitionReturnType,
+ FormatStyle::DRTBS_TopLevel);
+
Style.NamespaceIndentation = FormatStyle::NI_All;
CHECK_PARSE("NamespaceIndentation: None", NamespaceIndentation,
FormatStyle::NI_None);
diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp
index 15d62eb66c33..e6c12f4ce0f1 100644
--- a/unittests/Format/FormatTestJS.cpp
+++ b/unittests/Format/FormatTestJS.cpp
@@ -579,6 +579,7 @@ TEST_F(FormatTestJS, RegexLiteralClassification) {
verifyFormat("var x = a && /abc/.test(y);");
verifyFormat("var x = a || /abc/.test(y);");
verifyFormat("var x = a + /abc/.search(y);");
+ verifyFormat("/abc/.search(y);");
verifyFormat("var regexs = {/abc/, /abc/};");
verifyFormat("return /abc/;");
@@ -624,10 +625,23 @@ TEST_F(FormatTestJS, RegexLiteralSpecialCharacters) {
verifyFormat("var regex = /\a\\//g;");
verifyFormat("var regex = /a\\//;\n"
"var x = 0;");
+ EXPECT_EQ("var regex = /'/g;", format("var regex = /'/g ;"));
+ EXPECT_EQ("var regex = /'/g; //'", format("var regex = /'/g ; //'"));
EXPECT_EQ("var regex = /\\/*/;\n"
"var x = 0;",
format("var regex = /\\/*/;\n"
"var x=0;"));
+ EXPECT_EQ("var x = /a\\//;", format("var x = /a\\// \n;"));
+ verifyFormat("var regex = /\"/;", getGoogleJSStyleWithColumns(16));
+ verifyFormat("var regex =\n"
+ " /\"/;",
+ getGoogleJSStyleWithColumns(15));
+ verifyFormat("var regex = //\n"
+ " /a/;");
+ verifyFormat("var regexs = [\n"
+ " /d/, //\n"
+ " /aa/, //\n"
+ "];");
}
TEST_F(FormatTestJS, RegexLiteralModifiers) {
@@ -789,15 +803,11 @@ TEST_F(FormatTestJS, TemplateStrings) {
" ${ name }\n"
" !`;"));
- // FIXME: +1 / -1 offsets are to work around clang-format miscalculating
- // widths for unknown tokens that are not whitespace (e.g. '`'). Remove when
- // the code is corrected.
-
verifyFormat("var x =\n"
" `hello ${world}` >= some();",
getGoogleJSStyleWithColumns(34)); // Barely doesn't fit.
verifyFormat("var x = `hello ${world}` >= some();",
- getGoogleJSStyleWithColumns(35 + 1)); // Barely fits.
+ getGoogleJSStyleWithColumns(35)); // Barely fits.
EXPECT_EQ("var x = `hello\n"
" ${world}` >=\n"
" some();",
@@ -812,10 +822,14 @@ TEST_F(FormatTestJS, TemplateStrings) {
" ${world}` >= some();",
getGoogleJSStyleWithColumns(22))); // Barely fits.
- verifyFormat("var x =\n `h`;", getGoogleJSStyleWithColumns(13 - 1));
+ verifyFormat("var x =\n"
+ " `h`;",
+ getGoogleJSStyleWithColumns(11));
EXPECT_EQ(
"var x =\n `multi\n line`;",
- format("var x = `multi\n line`;", getGoogleJSStyleWithColumns(14 - 1)));
+ format("var x = `multi\n line`;", getGoogleJSStyleWithColumns(13)));
+ verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+ " `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`);");
// Make sure template strings get a proper ColumnWidth assigned, even if they
// are first token in line.
@@ -869,6 +883,8 @@ TEST_F(FormatTestJS, TypeArguments) {
verifyFormat("class C extends D<E> implements F<G>, H<I> {}");
verifyFormat("function f(a: List<any> = null) {}");
verifyFormat("function f(): List<any> {}");
+ verifyFormat("function aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa():\n"
+ " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb {}");
}
TEST_F(FormatTestJS, OptionalTypes) {
diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp
index 4c161e0180af..8e590879f6e2 100644
--- a/unittests/Format/FormatTestJava.cpp
+++ b/unittests/Format/FormatTestJava.cpp
@@ -67,6 +67,8 @@ TEST_F(FormatTestJava, FormatsInstanceOfLikeOperators) {
verifyFormat("return aaaaaaaaaaaaaaaaaaaaaaaaaaaaa instanceof\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;",
Style);
+ verifyFormat("return aaaaaaaaaaaaaaaaaaa instanceof bbbbbbbbbbbbbbbbbbbbbbb\n"
+ " && ccccccccccccccccccc instanceof dddddddddddddddddddddd;");
}
TEST_F(FormatTestJava, Chromium) {
diff --git a/unittests/Format/FormatTestProto.cpp b/unittests/Format/FormatTestProto.cpp
index ac8fcbdda4fc..74f7005b219f 100644
--- a/unittests/Format/FormatTestProto.cpp
+++ b/unittests/Format/FormatTestProto.cpp
@@ -63,6 +63,10 @@ TEST_F(FormatTestProto, FormatsMessages) {
"}");
}
+TEST_F(FormatTestProto, KeywordsInOtherLanguages) {
+ verifyFormat("optional string operator = 1;");
+}
+
TEST_F(FormatTestProto, FormatsEnums) {
verifyFormat("enum Type {\n"
" UNKNOWN = 0;\n"