BareGit
#include <gtest/gtest.h>
#include "macrodown.h"

using namespace macrodown;

TEST(MacroDownTest, TwoStepRendering)
{
    MacroDown md;
    std::string input = "# Hello\n\nWorld";

    // Step 1: Parse
    auto root = md.parse(input);
    ASSERT_NE(root, nullptr);

    // Step 2: Render
    std::string html = md.render(*root);
    EXPECT_EQ(html, "<h1>Hello</h1>\n<p>World</p>\n");
}

TEST(MacroDownTest, CustomMacro)
{
    MacroDown md;
    md.evaluator().define("greet", {"name"}, "Hello, %name!");

    std::string input = "Say %greet{User}";
    auto root = md.parse(input);
    std::string html = md.render(*root);

    EXPECT_EQ(html, "<p>Say Hello, User!</p>\n");
}
TEST(MacroDownTest, MarkdownElements)
{
    MacroDown md;
    // Emphasis
    EXPECT_EQ(md.render(*md.parse("*em*")), "<p><em>em</em></p>\n");

    // Strong
    EXPECT_EQ(md.render(*md.parse("**bold**")), "<p><strong>bold</strong></p>\n");

    // Link
    EXPECT_EQ(md.render(*md.parse("[Link](url)")), "<p><a href=\"url\">Link</a></p>\n");

    // Code
    EXPECT_EQ(md.render(*md.parse("`code`")), "<p><code>code</code></p>\n");
}

TEST(MacroDownTest, BlockQuote)
{
    MacroDown md;
    std::string input = "> Hello\n> World";
    std::string expected = "<blockquote>\n<p>Hello\nWorld</p>\n</blockquote>\n";
    EXPECT_EQ(md.render(*md.parse(input)), expected);
}

TEST(MacroDownTest, MixedContent)
{
    MacroDown md;
    std::string input = "# Header\n\nParagraph with *em* and %code{macros}.";
    std::string expected = "<h1>Header</h1>\n<p>Paragraph with <em>em</em> and <code>macros</code>.</p>\n";
    EXPECT_EQ(md.render(*md.parse(input)), expected);
}

TEST(MacroDownTest, InlineDefinition)
{
    MacroDown md;
    std::string input = "%def[bold]{t}{<b>%t</b>}\n\nThis is %bold{important}.";
    // The first paragraph only contains the definition, which evaluates to empty string.
    // The second paragraph uses the newly defined macro.
    std::string expected = "<p>This is <b>important</b>.</p>\n";
    EXPECT_EQ(md.render(*md.parse(input)), expected);
}