================
@@ -0,0 +1,180 @@
+//===- AnalyzerFormattingTest.cpp - SA Formatting test 
--------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains tests for printFormattedEntry function, which is used for
+// printing available analyzers and their descriptions.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+
+using namespace clang::ento;
+
+static void runPrintFormattedEntry(
+    std::pair<llvm::StringRef, llvm::StringRef> EntryDescPair,
+    size_t InitialPad, size_t EntryWidth, size_t MinLineWidth,
+    llvm::SmallString<256> &OutBuffer) {
+  llvm::raw_svector_ostream Out(OutBuffer);
+  clang::AnalyzerOptions::printFormattedEntry(Out, EntryDescPair, InitialPad,
+                                              EntryWidth, MinLineWidth);
+}
+
+// No wrapping after checker's name.
+// No initial pad.
+TEST(PrintFormattedEntryTest, SimplePrint) {
+  llvm::SmallString<256> Buffer;
+  runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", "A description"},
+                         /*InitialPad=*/0,
+                         /*EntryWidth=*/20,
+                         /*MinLineWidth=*/0,
+                         /*OutBuffer=*/Buffer);
+
+  EXPECT_EQ(Buffer, "Checkers            A description");
+}
+
+// With wrapping after checker's name.
+// No initial pad.
+TEST(PrintFormattedEntryTest, EntryLongerThanWidth) {
+  llvm::SmallString<256> Buffer;
+  runPrintFormattedEntry(
+      {/*EntryDescPair=*/"VeryLongCheckerName", "A description"},
+      /*InitialPad=*/0,
+      /*EntryWidth=*/10,
+      /*MinLineWidth=*/0,
+      /*OutBuffer=*/Buffer);
+
+  EXPECT_EQ(Buffer, "VeryLongCheckerName\n"
+                    "          A description");
+}
+
+// With wrapping after checker's name.
+// No initial pad.
+// Corner case, when checker's name length equal to EntryWidth.
+TEST(PrintFormattedEntryTest, ExactFillWidth) {
+  llvm::SmallString<256> Buffer;
+  runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", "A description"},
+                         /*InitialPad=*/0,
+                         /*EntryWidth=*/8,
+                         /*MinLineWidth=*/0,
+                         /*OutBuffer=*/Buffer);
+
+  EXPECT_EQ(Buffer, "Checkers\n"
+                    "        A description");
+}
+
+// No wrapping after checker's name.
+// With initial pad.
+TEST(PrintFormattedEntryTest, WithInitialPadding) {
+  llvm::SmallString<256> Buffer;
+  runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", "A description"},
+                         /*InitialPad=*/2,
+                         /*EntryWidth=*/20,
+                         /*MinLineWidth=*/0,
+                         /*OutBuffer=*/Buffer);
+
+  EXPECT_EQ(Buffer, "  Checkers            A description");
+}
+
+// No wrapping after checker's name.
+// With initial pad.
+// With wrapping in checker's description (MinLineWidth > 0).
+TEST(PrintFormattedEntryTest, WrapDescription) {
+  llvm::SmallString<256> Buffer;
+  llvm::StringRef Desc =
+      "This is a long description that should be wrapped into multiple lines.";
+  runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", Desc},
+                         /*InitialPad=*/2,
+                         /*EntryWidth=*/20,
+                         /*MinLineWidth=*/40,
+                         /*OutBuffer=*/Buffer);
+
+  llvm::StringRef Expected =
+      "  Checkers            This is a long description\n"
+      "                      that should be wrapped\n"
+      "                      into multiple lines.";
+  EXPECT_EQ(Buffer, Expected);
+}
+
+// No wrapping after checker's name.
+// With initial pad.
+// No wrapping in checker's descriptions (MinLineWdth = 0).
----------------
JustinStitt wrote:

nit:

`s/MinLineWdth/MinLineWidth`

https://github.com/llvm/llvm-project/pull/190570
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to