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<FormatStyle> &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"); + checkLanguage(Style, FormatStyle::LK_ObjC); + + Style = getStyle("{}", "a.h", "none", "extern NSInteger Foo();\n"); + checkLanguage(Style, FormatStyle::LK_ObjC); } TEST_F(FormatTestObjC, FormatObjCTryCatch) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits