aboutsummaryrefslogtreecommitdiff
path: root/unittests/Format
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-04-25 13:31:51 +0000
committerDaniel Jasper <djasper@google.com>2013-04-25 13:31:51 +0000
commitfca24bc45192c254ca92ef1d7cef71a290392f31 (patch)
tree25698f3f76d524e2ae4aa614c54ede9f03cea37c /unittests/Format
parentf49d9c9b858973eb10717f4b3936a4a4384bd355 (diff)
Improve clang-format's memoization behavior.
Deeply nested expressions basically break clang-format's memoization. This patch slightly improves the situations and makes expressions like aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa( aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa( aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa( aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa( aaaaa(aaaaa()))))))))))))))))))))))))))))))))))))))); work. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180264 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format')
-rw-r--r--unittests/Format/FormatTest.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 97d4df8e5e..055b9d1cb2 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1702,8 +1702,30 @@ TEST_F(FormatTest, ConstructorInitializers) {
" : aaaaa(aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaaaa) {}",
OnePerLine);
+}
+
+TEST_F(FormatTest, MemoizationTests) {
+ // This breaks if the memoization lookup does not take \c Indent and
+ // \c LastSpace into account.
+ verifyFormat(
+ "extern CFRunLoopTimerRef\n"
+ "CFRunLoopTimerCreate(CFAllocatorRef allocato, CFAbsoluteTime fireDate,\n"
+ " CFTimeInterval interval, CFOptionFlags flags,\n"
+ " CFIndex order, CFRunLoopTimerCallBack callout,\n"
+ " CFRunLoopTimerContext *context);");
+
+ // Deep nesting somewhat works around our memoization.
+ verifyFormat(
+ "aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(\n"
+ " aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(\n"
+ " aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(\n"
+ " aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(\n"
+ " aaaaa())))))))))))))))))))))))))))))))))))))));",
+ getLLVMStyleWithColumns(65));
// This test takes VERY long when memoization is broken.
+ FormatStyle OnePerLine = getLLVMStyle();
+ OnePerLine.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
OnePerLine.BinPackParameters = false;
std::string input = "Constructor()\n"
" : aaaa(a,\n";