[PATCH] D43231: [clang-format] Refactor ObjC tests

2018-02-13 Thread Jacek Olesiak via Phabricator via cfe-commits
jolesiak abandoned this revision.
jolesiak added a comment.

In https://reviews.llvm.org/D43231#1006123, @krasimir wrote:

> I don't believe this is needed: test fails before would fail at the line 
> where test instance is checked, and after they will fail at the checkLanguage 
> function.


Thank you for the comment!
That's a valid argument. I'm reverting as a macro is a no go.


Repository:
  rC Clang

https://reviews.llvm.org/D43231



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43231: [clang-format] Refactor ObjC tests

2018-02-13 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

I don't believe this is needed: test fails before would fail at the line where 
test instance is checked, and after they will fail at the checkLanguage 
function.


Repository:
  rC Clang

https://reviews.llvm.org/D43231



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43231: [clang-format] Refactor ObjC tests

2018-02-13 Thread Jacek Olesiak via Phabricator via cfe-commits
jolesiak created this revision.
Herald added subscribers: cfe-commits, klimek.

Simplifies ObjC style tests.


Repository:
  rC Clang

https://reviews.llvm.org/D43231

Files:
  unittests/Format/FormatTestObjC.cpp

Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -68,92 +68,84 @@
   FormatStyle Style;
 };
 
+// Checks whether language detected after running \p getStyle is expected.
+// \p Style cannot be a reference to const as casting to bool can change
+// internal state.
+void checkLanguage(llvm::Expected &Style,
+   FormatStyle::LanguageKind ExpectedLanguage) {
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(ExpectedLanguage, Style->Language);
+}
+
 TEST(FormatTestObjCStyle, DetectsObjCInHeaders) {
   auto Style = getStyle("LLVM", "a.h", "none", "@interface\n"
"- (id)init;");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_ObjC);
 
   Style = getStyle("LLVM", "a.h", "none", "@interface\n"
   "+ (id)init;");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_ObjC);
 
   Style = getStyle("LLVM", "a.h", "none", "@interface\n"
   "@end\n"
   "//comment");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_ObjC);
 
   Style = getStyle("LLVM", "a.h", "none", "@interface\n"
   "@end //comment");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_ObjC);
 
   // No recognizable ObjC.
   Style = getStyle("LLVM", "a.h", "none", "void f() {}");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_Cpp);
 
   Style = getStyle("{}", "a.h", "none", "@interface Foo\n@end\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_ObjC);
 
   Style = getStyle("{}", "a.h", "none",
"const int interface = 1;\nconst int end = 2;\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_Cpp);
 
   Style = getStyle("{}", "a.h", "none", "@protocol Foo\n@end\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_ObjC);
 
   Style = getStyle("{}", "a.h", "none",
"const int protocol = 1;\nconst int end = 2;\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
-
-  Style = getStyle("{}", "a.h", "none", "extern NSString *kFoo;\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_Cpp);
 
   Style =
   getStyle("{}", "a.h", "none", "typedef NS_ENUM(NSInteger, Foo) {};\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_ObjC);
 
   Style = getStyle("{}", "a.h", "none", "enum Foo {};");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
-
-  Style = getStyle("{}", "a.h", "none", "extern NSInteger Foo();\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_Cpp);
 
   Style =
   getStyle("{}", "a.h", "none", "inline void Foo() { Log(@\"Foo\"); }\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_ObjC);
 
   Style =
   getStyle("{}", "a.h", "none", "inline void Foo() { Log(\"Foo\"); }\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_Cpp);
 
   Style =
   getStyle("{}", "a.h", "none", "inline void Foo() { id = @[1, 2, 3]; }\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_ObjC);
 
   Style = getStyle("{}", "a.h", "none",
"inline void Foo() { id foo = @{1: 2, 3: 4, 5: 6}; }\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_ObjC);
 
   Style = getStyle("{}", "a.h", "none",
"inline void Foo() { int foo[] = {1, 2, 3}; }\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
+  checkLanguage(Style, FormatStyle::LK_Cpp);
+
+  // ObjC specific types.
+  Style = getStyle("{}", "a.h", "none", "extern NSString *kFoo;\n");
+  checkLangua