summaryrefslogtreecommitdiff
path: root/clang/unittests
diff options
context:
space:
mode:
authorColin Ogilvie <colin.ogilvie@kdab.com>2023-05-04 02:48:51 -0700
committerOwen Pan <owenpiano@gmail.com>2023-05-04 02:59:05 -0700
commitf3dcd3ad992c82be4f652fd2aac6b0ef414566a2 (patch)
tree0feffcffa537a7d791c4cf3a8262d8191e5d523d /clang/unittests
parentcb7e3da0545219d39e3881c0046c73831f829741 (diff)
downloadllvm-f3dcd3ad992c82be4f652fd2aac6b0ef414566a2.tar.gz
[clang-format] Correctly limit formatted ranges when specifying qualifier alignment
The qualifier alignment fixer appeared to ignore any ranges specified for limiting formatting. This change ensures that it only formats affected lines to avoid unexpected changes. Fixes #54888. Differential Revision: https://reviews.llvm.org/D149643
Diffstat (limited to 'clang/unittests')
-rwxr-xr-xclang/unittests/Format/QualifierFixerTest.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/unittests/Format/QualifierFixerTest.cpp b/clang/unittests/Format/QualifierFixerTest.cpp
index 76800b3fc8e3..9760c80dcc61 100755
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -1343,6 +1343,29 @@ TEST_F(QualifierFixerTest, TemplatesLeft) {
"TemplateType<Container const> t;", Style);
}
+TEST_F(QualifierFixerTest, Ranges) {
+ FormatStyle Style = getLLVMStyle();
+ Style.QualifierAlignment = FormatStyle::QAS_Custom;
+ Style.QualifierOrder = {"const", "volatile", "type"};
+
+ // Only the first line should be formatted; the second should remain as is.
+ verifyFormat("template <typename T> const Foo f();\n"
+ "template <typename T> Foo const f();",
+ "template <typename T> Foo const f();\n"
+ "template <typename T> Foo const f();",
+ Style, {tooling::Range(0, 36)});
+
+ // Only the middle line should be formatted; the first and last should remain
+ // as is.
+ verifyFormat("template <typename T> Foo const f();\n"
+ "template <typename T> const Foo f();\n"
+ "template <typename T> Foo const f();",
+ "template <typename T> Foo const f();\n"
+ "template <typename T> Foo const f();\n"
+ "template <typename T> Foo const f();",
+ Style, {tooling::Range(37, 36)});
+}
+
} // namespace
} // namespace test
} // namespace format