================ @@ -0,0 +1,304 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "support/Markdown.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/Casting.h" +#include "gtest/gtest.h" + +using namespace clang::doc::markdown; +using namespace llvm; + +namespace { + +struct MarkdownParserTest : public ::testing::Test { + llvm::BumpPtrAllocator Arena; +}; + +TEST_F(MarkdownParserTest, EmptyInput) { + auto Nodes = parseMarkdown("", Arena); + EXPECT_TRUE(Nodes.empty()); +} + +TEST_F(MarkdownParserTest, WhitespaceOnlyInput) { + auto Nodes = parseMarkdown(" \n \n", Arena); + EXPECT_TRUE(Nodes.empty()); +} + +TEST_F(MarkdownParserTest, PlainText) { + auto Nodes = parseMarkdown("hello world", Arena); + ASSERT_EQ(Nodes.size(), 1u); + auto *N = cast<TextNode>(Nodes[0]); + EXPECT_EQ(N->Text, "hello world"); +} + +TEST_F(MarkdownParserTest, FencedCodeBlock) { + auto Nodes = parseMarkdown(R"(```cpp +int x = 0; +````````)", + Arena); + ASSERT_EQ(Nodes.size(), 1u); + auto *N = cast<FencedCodeNode>(Nodes[0]); + EXPECT_EQ(N->Lang, "cpp"); + ASSERT_EQ(N->Lines.size(), 1u); +} + +TEST_F(MarkdownParserTest, FencedCodeBlockNoLang) { + auto Nodes = parseMarkdown(R"(``` +some code +```````)", + Arena); + ASSERT_EQ(Nodes.size(), 1u); + auto *N = cast<FencedCodeNode>(Nodes[0]); + EXPECT_TRUE(N->Lang.empty()); +} + +TEST_F(MarkdownParserTest, UnterminatedFenceReturnsEmpty) { + auto Nodes = parseMarkdown(R"(```cpp +int x = 0;)", + Arena); + // Unterminated fence should not crash and should produce a code node + // with whatever lines were found. + EXPECT_FALSE(Nodes.empty()); ---------------- Neil-N4 wrote:
Will make the fallback explicit and check the node type https://github.com/llvm/llvm-project/pull/202991 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
