[clang-format] Propagate inferred language to getLLVMStyle() in getPredefinedStyle()
authorJordan Rupprecht <rupprecht@google.com>
Wed, 13 Mar 2019 21:13:01 +0000 (21:13 +0000)
committerJordan Rupprecht <rupprecht@google.com>
Wed, 13 Mar 2019 21:13:01 +0000 (21:13 +0000)
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().

llvm-svn: 356099

clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp

index ce67b82..e73bcba 100644 (file)
@@ -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")) {
index 7fcff46..09c49b4 100644 (file)
@@ -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) {