diff options
author | Manuel Klimek <klimek@google.com> | 2013-04-12 14:13:36 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-04-12 14:13:36 +0000 |
commit | 67d080dafa74c7d126da522fec333a6e52a5ae35 (patch) | |
tree | 38ccb556d560e92047cf105088bdef83646b7f18 /unittests/Format/FormatTest.cpp | |
parent | 7a9ed44173f9291534d935c5e4b11ddd24c01f29 (diff) |
Revamps structural error detection / handling.
Previously we'd only detect structural errors on the very first level.
This leads to incorrectly balanced braces not being discovered, and thus
incorrect indentation.
This change fixes the problem by:
- changing the parser to use an error state that can be detected
anywhere inside the productions, for example if we get an eof on
SOME_MACRO({ some block <eof>
- previously we'd never break lines when we discovered a structural
error; now we break even in the case of a structural error if there
are two unwrapped lines within the same line; thus,
void f() { while (true) { g(); y(); } }
will still be re-formatted, even if there's missing braces somewhere
in the file
- still exclude macro definitions from generating structural error;
macro definitions are inbalanced snippets
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179379 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 91b8f81080..8dadd032ab 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -430,6 +430,7 @@ TEST_F(FormatTest, FormatsSwitchStatement) { verifyFormat("switch (x) {\n" "default: {\n" " // Do nothing.\n" + "}\n" "}"); verifyFormat("switch (x) {\n" "// comment\n" @@ -3563,8 +3564,18 @@ TEST_F(FormatTest, ObjCLiterals) { verifyFormat("@{ @\"one\" : @1 }"); verifyFormat("return @{ @\"one\" : @1 };"); verifyFormat("@{ @\"one\" : @1, }"); - verifyFormat("@{ @\"one\" : @{ @2 : @1 } }"); - verifyFormat("@{ @\"one\" : @{ @2 : @1 }, }"); + + // FIXME: Breaking in cases where we think there's a structural error + // showed that we're incorrectly parsing this code. We need to fix the + // parsing here. + verifyFormat("@{ @\"one\" : @\n" + "{ @2 : @1 }\n" + "}"); + verifyFormat("@{ @\"one\" : @\n" + "{ @2 : @1 }\n" + ",\n" + "}"); + verifyFormat("@{ 1 > 2 ? @\"one\" : @\"two\" : 1 > 2 ? @1 : @2 }"); verifyFormat("[self setDict:@{}"); verifyFormat("[self setDict:@{ @1 : @2 }"); |