diff options
| author | Reuben Thomas <reuben.thomas@me.com> | 2019-03-30 12:32:35 +0000 |
|---|---|---|
| committer | Reuben Thomas <reuben.thomas@me.com> | 2019-03-30 12:32:35 +0000 |
| commit | 08a940d629fa218670caaa949095bc5026f019b3 (patch) | |
| tree | 5f6f2644cc3aaebdad6d6c92daa967f247b482ec /clang/unittests/Format/FormatTest.cpp | |
| parent | c4ac74fb4987c083fa8e7e10f0f978ecee9402c0 (diff) | |
| download | bcm5719-llvm-08a940d629fa218670caaa949095bc5026f019b3.tar.gz bcm5719-llvm-08a940d629fa218670caaa949095bc5026f019b3.zip | |
[clang-format]: Add NonEmptyParentheses spacing option
This patch aims to add support for the following rules from the JUCE coding standards:
- Always put a space before an open parenthesis that contains text - e.g. foo (123);
- Never put a space before an empty pair of open/close parenthesis - e.g. foo();
Patch by Reuben Thomas
Differential Revision: https://reviews.llvm.org/D55170
llvm-svn: 357344
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 6453d243867..7859f96a9af 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -9627,6 +9627,60 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) { verifyFormat("T A::operator() ();", Space); verifyFormat("X A::operator++ (T);", Space); verifyFormat("auto lambda = [] () { return 0; };", Space); + verifyFormat("int x = int (y);", Space); + + FormatStyle SomeSpace = getLLVMStyle(); + SomeSpace.SpaceBeforeParens = FormatStyle::SBPO_NonEmptyParentheses; + + verifyFormat("[]() -> float {}", SomeSpace); + verifyFormat("[] (auto foo) {}", SomeSpace); + verifyFormat("[foo]() -> int {}", SomeSpace); + verifyFormat("int f();", SomeSpace); + verifyFormat("void f (int a, T b) {\n" + " while (true)\n" + " continue;\n" + "}", + SomeSpace); + verifyFormat("if (true)\n" + " f();\n" + "else if (true)\n" + " f();", + SomeSpace); + verifyFormat("do {\n" + " do_something();\n" + "} while (something());", + SomeSpace); + verifyFormat("switch (x) {\n" + "default:\n" + " break;\n" + "}", + SomeSpace); + verifyFormat("A::A() : a (1) {}", SomeSpace); + verifyFormat("void f() __attribute__ ((asdf));", SomeSpace); + verifyFormat("*(&a + 1);\n" + "&((&a)[1]);\n" + "a[(b + c) * d];\n" + "(((a + 1) * 2) + 3) * 4;", + SomeSpace); + verifyFormat("#define A(x) x", SomeSpace); + verifyFormat("#define A (x) x", SomeSpace); + verifyFormat("#if defined(x)\n" + "#endif", + SomeSpace); + verifyFormat("auto i = std::make_unique<int> (5);", SomeSpace); + verifyFormat("size_t x = sizeof (x);", SomeSpace); + verifyFormat("auto f (int x) -> decltype (x);", SomeSpace); + verifyFormat("int f (T x) noexcept (x.create());", SomeSpace); + verifyFormat("alignas (128) char a[128];", SomeSpace); + verifyFormat("size_t x = alignof (MyType);", SomeSpace); + verifyFormat("static_assert (sizeof (char) == 1, \"Impossible!\");", + SomeSpace); + verifyFormat("int f() throw (Deprecated);", SomeSpace); + verifyFormat("typedef void (*cb) (int);", SomeSpace); + verifyFormat("T A::operator()();", SomeSpace); + verifyFormat("X A::operator++ (T);", SomeSpace); + verifyFormat("int x = int (y);", SomeSpace); + verifyFormat("auto lambda = []() { return 0; };", SomeSpace); } TEST_F(FormatTest, ConfigurableSpacesInParentheses) { @@ -11413,6 +11467,8 @@ TEST_F(FormatTest, ParsesConfiguration) { FormatStyle::SBPO_Always); CHECK_PARSE("SpaceBeforeParens: ControlStatements", SpaceBeforeParens, FormatStyle::SBPO_ControlStatements); + CHECK_PARSE("SpaceBeforeParens: NonEmptyParentheses", SpaceBeforeParens, + FormatStyle::SBPO_NonEmptyParentheses); // For backward compatibility: CHECK_PARSE("SpaceAfterControlStatementKeyword: false", SpaceBeforeParens, FormatStyle::SBPO_Never); |

