================ @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// 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 "gtest/gtest.h" + +using namespace clang::doc::markdown; +using namespace llvm; + +namespace { + +/// Returns the text of the first TextNode child in the given inline list. +static llvm::StringRef firstChildText(const InlineList &L) { + return llvm::cast<TextNode>(L.front()).getText(); +} + +TEST(MarkdownNodeTest, TextNode) { + TextNode N("hello"); + EXPECT_EQ(N.getKind(), NodeKind::NK_Text); + EXPECT_EQ(N.getText(), "hello"); +} + +TEST(MarkdownNodeTest, FencedCodeNode) { + FencedCodeNode N("cpp", "int x = 0;\nint y = 1;"); + EXPECT_EQ(N.getKind(), NodeKind::NK_FencedCode); + EXPECT_EQ(N.getLang(), "cpp"); + llvm::SmallVector<llvm::StringRef> Lines; + N.getCode().split(Lines, '\n'); + EXPECT_EQ(Lines[0], "int x = 0;"); + EXPECT_EQ(Lines[1], "int y = 1;"); ---------------- ilovepi wrote:
This makes me wonder if `FencedCodeNode` needs a `getRawCode()` that returns the raw string body, and another method to get the lines. For now, this is fine and doesn't require changes, but I think as we move into real parsing this will be important to understand. IIRC clang and clang-doc will not yield a single StringRef, but an array of StringRefs that are discontinuous spans of the raw buffers. I've been thinking that we want some almost Twine like data structure that allows you to operate over these fixed ArrayRefs as if its a single string. https://github.com/llvm/llvm-project/pull/205609 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
