From: Jordan Rupprecht Date: Wed, 13 Mar 2019 21:13:01 +0000 (+0000) Subject: [clang-format] Propagate inferred language to getLLVMStyle() in getPredefinedStyle() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=937655622bbdb31649924efac7e751d1e03f7515;p=clang [clang-format] Propagate inferred language to getLLVMStyle() in getPredefinedStyle() rC355158 added an optional language parameter to getLLVMStyle(), but this parameter was not used in getPredefinedStyle(). Because unit tests directly specify the style, this codepath wasn't tested. Add an additional unit test for getStyle(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356099 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index ce67b82e10..e73bcba795 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -961,7 +961,7 @@ FormatStyle getNoStyle() { bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style) { if (Name.equals_lower("llvm")) { - *Style = getLLVMStyle(); + *Style = getLLVMStyle(Language); } else if (Name.equals_lower("chromium")) { *Style = getChromiumStyle(Language); } else if (Name.equals_lower("mozilla")) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 7fcff46f58..09c49b4408 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -12714,6 +12714,11 @@ TEST(FormatStyle, GetStyleOfFile) { auto Style7 = getStyle("file", "/d/.clang-format", "LLVM", "", &FS); ASSERT_FALSE((bool)Style7); llvm::consumeError(Style7.takeError()); + + // Test 8: inferred per-language defaults apply. + auto StyleTd = getStyle("file", "x.td", "llvm", "", &FS); + ASSERT_TRUE((bool)StyleTd); + ASSERT_EQ(*StyleTd, getLLVMStyle(FormatStyle::LK_TableGen)); } TEST_F(ReplacementTest, FormatCodeAfterReplacements) {