summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp90
1 files changed, 89 insertions, 1 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index eacb389400b..cef2b0b2755 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6134,7 +6134,48 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
"void\n"
"A::operator>>() {}\n"
"void\n"
- "A::operator+() {}\n",
+ "A::operator+() {}\n"
+ "void\n"
+ "A::operator*() {}\n"
+ "void\n"
+ "A::operator->() {}\n"
+ "void\n"
+ "A::operator void *() {}\n"
+ "void\n"
+ "A::operator void &() {}\n"
+ "void\n"
+ "A::operator void &&() {}\n"
+ "void\n"
+ "A::operator char *() {}\n"
+ "void\n"
+ "A::operator[]() {}\n"
+ "void\n"
+ "A::operator!() {}\n",
+ Style);
+ verifyFormat("constexpr auto\n"
+ "operator()() const -> reference {}\n"
+ "constexpr auto\n"
+ "operator>>() const -> reference {}\n"
+ "constexpr auto\n"
+ "operator+() const -> reference {}\n"
+ "constexpr auto\n"
+ "operator*() const -> reference {}\n"
+ "constexpr auto\n"
+ "operator->() const -> reference {}\n"
+ "constexpr auto\n"
+ "operator++() const -> reference {}\n"
+ "constexpr auto\n"
+ "operator void *() const -> reference {}\n"
+ "constexpr auto\n"
+ "operator void &() const -> reference {}\n"
+ "constexpr auto\n"
+ "operator void &&() const -> reference {}\n"
+ "constexpr auto\n"
+ "operator char *() const -> reference {}\n"
+ "constexpr auto\n"
+ "operator!() const -> reference {}\n"
+ "constexpr auto\n"
+ "operator[]() const -> reference {}\n",
Style);
verifyFormat("void *operator new(std::size_t s);", // No break here.
Style);
@@ -14755,6 +14796,53 @@ TEST_F(FormatTest, STLWhileNotDefineChed) {
"#endif // while");
}
+TEST_F(FormatTest, OperatorSpacing) {
+ FormatStyle Style = getLLVMStyle();
+ Style.PointerAlignment = FormatStyle::PAS_Right;
+ verifyFormat("Foo::operator*();", Style);
+ verifyFormat("Foo::operator void *();", Style);
+ verifyFormat("Foo::operator()(void *);", Style);
+ verifyFormat("Foo::operator*(void *);", Style);
+ verifyFormat("Foo::operator*();", Style);
+ verifyFormat("operator*(int (*)(), class Foo);", Style);
+
+ verifyFormat("Foo::operator&();", Style);
+ verifyFormat("Foo::operator void &();", Style);
+ verifyFormat("Foo::operator()(void &);", Style);
+ verifyFormat("Foo::operator&(void &);", Style);
+ verifyFormat("Foo::operator&();", Style);
+ verifyFormat("operator&(int (&)(), class Foo);", Style);
+
+ verifyFormat("Foo::operator&&();", Style);
+ verifyFormat("Foo::operator void &&();", Style);
+ verifyFormat("Foo::operator()(void &&);", Style);
+ verifyFormat("Foo::operator&&(void &&);", Style);
+ verifyFormat("Foo::operator&&();", Style);
+ verifyFormat("operator&&(int(&&)(), class Foo);", Style);
+
+ Style.PointerAlignment = FormatStyle::PAS_Left;
+ verifyFormat("Foo::operator*();", Style);
+ verifyFormat("Foo::operator void*();", Style);
+ verifyFormat("Foo::operator()(void*);", Style);
+ verifyFormat("Foo::operator*(void*);", Style);
+ verifyFormat("Foo::operator*();", Style);
+ verifyFormat("operator*(int (*)(), class Foo);", Style);
+
+ verifyFormat("Foo::operator&();", Style);
+ verifyFormat("Foo::operator void&();", Style);
+ verifyFormat("Foo::operator()(void&);", Style);
+ verifyFormat("Foo::operator&(void&);", Style);
+ verifyFormat("Foo::operator&();", Style);
+ verifyFormat("operator&(int (&)(), class Foo);", Style);
+
+ verifyFormat("Foo::operator&&();", Style);
+ verifyFormat("Foo::operator void&&();", Style);
+ verifyFormat("Foo::operator()(void&&);", Style);
+ verifyFormat("Foo::operator&&(void&&);", Style);
+ verifyFormat("Foo::operator&&();", Style);
+ verifyFormat("operator&&(int(&&)(), class Foo);", Style);
+}
+
} // namespace
} // namespace format
} // namespace clang
OpenPOWER on IntegriCloud