summaryrefslogtreecommitdiff
path: root/unittests/Format
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/Format')
-rw-r--r--unittests/Format/FormatTest.cpp29
-rw-r--r--unittests/Format/FormatTestJS.cpp75
2 files changed, 100 insertions, 4 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 1c100c3b9b067..c4aa712ba1d58 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1337,6 +1337,16 @@ TEST_F(FormatTest, SplitsLongCxxComments) {
"// one line",
format("// A comment that doesn't fit on one line",
getLLVMStyleWithColumns(20)));
+ EXPECT_EQ("/// A comment that\n"
+ "/// doesn't fit on\n"
+ "/// one line",
+ format("/// A comment that doesn't fit on one line",
+ getLLVMStyleWithColumns(20)));
+ EXPECT_EQ("//! A comment that\n"
+ "//! doesn't fit on\n"
+ "//! one line",
+ format("//! A comment that doesn't fit on one line",
+ getLLVMStyleWithColumns(20)));
EXPECT_EQ("// a b c d\n"
"// e f g\n"
"// h i j k",
@@ -1357,6 +1367,12 @@ TEST_F(FormatTest, SplitsLongCxxComments) {
EXPECT_EQ("// Add leading\n"
"// whitespace",
format("//Add leading whitespace", getLLVMStyleWithColumns(20)));
+ EXPECT_EQ("/// Add leading\n"
+ "/// whitespace",
+ format("///Add leading whitespace", getLLVMStyleWithColumns(20)));
+ EXPECT_EQ("//! Add leading\n"
+ "//! whitespace",
+ format("//!Add leading whitespace", getLLVMStyleWithColumns(20)));
EXPECT_EQ("// whitespace", format("//whitespace", getLLVMStyle()));
EXPECT_EQ("// Even if it makes the line exceed the column\n"
"// limit",
@@ -3956,6 +3972,9 @@ TEST_F(FormatTest, TrailingReturnType) {
verifyFormat("auto SomeFunction(A aaaaaaaaaaaaaaaaaaaaa) const\n"
" -> decltype(f(aaaaaaaaaaaaaaaaaaaaa)) {}");
verifyFormat("auto doSomething(Aaaaaa *aaaaaa) -> decltype(aaaaaa->f()) {}");
+ verifyFormat("template <typename T>\n"
+ "auto aaaaaaaaaaaaaaaaaaaaaa(T t)\n"
+ " -> decltype(eaaaaaaaaaaaaaaa<T>(t.a).aaaaaaaa());");
// Not trailing return types.
verifyFormat("void f() { auto a = b->c(); }");
@@ -4965,6 +4984,9 @@ TEST_F(FormatTest, AlignsPipes) {
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaaa)\n"
" << aaaaaaaaaaaaaaaaaaaaaaaaaa;");
+ verifyFormat("LOG_IF(aaa == //\n"
+ " bbb)\n"
+ " << a << b;");
// Breaking before the first "<<" is generally not desirable.
verifyFormat(
@@ -6603,6 +6625,7 @@ TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) {
// FIXME: This is still incorrectly handled at the formatter side.
verifyFormat("template <> struct X < 15, i<3 && 42 < 50 && 33 < 28> {};");
+ verifyFormat("int i = SomeFunction(a<b, a> b);");
// FIXME:
// This now gets parsed incorrectly as class definition.
@@ -7585,9 +7608,9 @@ TEST_F(FormatTest, ObjCArrayLiterals) {
" index:(NSUInteger)index\n"
" nonDigitAttributes:\n"
" (NSDictionary *)noDigitAttributes;");
- verifyFormat(
- "[someFunction someLooooooooooooongParameter:\n"
- " @[ NSBundle.mainBundle.infoDictionary[@\"a\"] ]];");
+ verifyFormat("[someFunction someLooooooooooooongParameter:@[\n"
+ " NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
+ "]];");
}
TEST_F(FormatTest, ReformatRegionAdjustsIndent) {
diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp
index a06daac24ecf9..efa845cd90bef 100644
--- a/unittests/Format/FormatTestJS.cpp
+++ b/unittests/Format/FormatTestJS.cpp
@@ -151,6 +151,14 @@ TEST_F(FormatTestJS, ContainerLiterals) {
// Arrow functions in object literals.
verifyFormat("var x = {y: (a) => { return a; }};");
verifyFormat("var x = {y: (a) => a};");
+
+ // Computed keys.
+ verifyFormat("var x = {[a]: 1, b: 2, [c]: 3};");
+ verifyFormat("var x = {\n"
+ " [a]: 1,\n"
+ " b: 2,\n"
+ " [c]: 3,\n"
+ "};");
}
TEST_F(FormatTestJS, MethodsInObjectLiterals) {
@@ -239,6 +247,33 @@ TEST_F(FormatTestJS, FormatsFreestandingFunctions) {
"}");
}
+TEST_F(FormatTestJS, ArrayLiterals) {
+ verifyFormat(
+ "var aaaaa: List<SomeThing> =\n"
+ " [new SomeThingAAAAAAAAAAAA(), new SomeThingBBBBBBBBB()];");
+ verifyFormat("return [\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
+ " ccccccccccccccccccccccccccc\n"
+ "];");
+ verifyFormat("var someVariable = SomeFuntion([\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
+ " ccccccccccccccccccccccccccc\n"
+ "]);");
+ verifyFormat("var someVariable = SomeFuntion([\n"
+ " [aaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbb],\n"
+ "]);",
+ getGoogleJSStyleWithColumns(51));
+ verifyFormat("var someVariable = SomeFuntion(aaaa, [\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
+ " ccccccccccccccccccccccccccc\n"
+ "]);");
+
+ verifyFormat("someFunction([], {a: a});");
+}
+
TEST_F(FormatTestJS, FunctionLiterals) {
verifyFormat("doFoo(function() {});");
verifyFormat("doFoo(function() { return 1; });");
@@ -322,6 +357,14 @@ TEST_F(FormatTestJS, FunctionLiterals) {
" doSomething();\n"
" doSomething();\n"
" }, this));");
+
+ // FIXME: This is bad, we should be wrapping before "function() {".
+ verifyFormat("someFunction(function() {\n"
+ " doSomething(); // break\n"
+ "})\n"
+ " .doSomethingElse(\n"
+ " // break\n"
+ " );");
}
TEST_F(FormatTestJS, InliningFunctionLiterals) {
@@ -440,7 +483,28 @@ TEST_F(FormatTestJS, ArrowFunctions) {
" return a;\n"
"};");
verifyFormat("var x = (a) => a;");
- verifyFormat("var x = (a) => a;");
+ verifyFormat("return () => [];");
+ verifyFormat("var aaaaaaaaaaaaaaaaaaaa = {\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaa:\n"
+ " (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) =>\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ "};");
+ verifyFormat(
+ "var a = a.aaaaaaa((a: a) => aaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) &&\n"
+ " aaaaaaaaaaaaaaaaaaaaa(bbbbbbb));");
+ verifyFormat(
+ "var a = a.aaaaaaa((a: a) => aaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) ?\n"
+ " aaaaaaaaaaaaaaaaaaaaa(bbbbbbb) :\n"
+ " aaaaaaaaaaaaaaaaaaaaa(bbbbbbb));");
+
+ // FIXME: This is bad, we should be wrapping before "() => {".
+ verifyFormat("someFunction(() => {\n"
+ " doSomething(); // break\n"
+ "})\n"
+ " .doSomethingElse(\n"
+ " // break\n"
+ " );");
}
TEST_F(FormatTestJS, ReturnStatements) {
@@ -579,6 +643,15 @@ TEST_F(FormatTestJS, ClassDeclarations) {
verifyFormat("class C {\n static x(): string { return 'asd'; }\n}");
verifyFormat("class C extends P implements I {}");
verifyFormat("class C extends p.P implements i.I {}");
+
+ // ':' is not a type declaration here.
+ verifyFormat("class X {\n"
+ " subs = {\n"
+ " 'b': {\n"
+ " 'c': 1,\n"
+ " },\n"
+ " };\n"
+ "}");
}
TEST_F(FormatTestJS, InterfaceDeclarations) {