#include <gtest/gtest.h>
#include "nodes.h"
#include <vector>
#include <string>
using namespace macrodown;
TEST(NodeTest, ForEachIteration)
{
// Create a tree:
// Group
// Text("a")
// Macro("m")
// Group
// Text("b")
Group root;
root.addChild(std::make_unique<Node>(Text{"a"}));
Macro m;
m.name = "m";
Group arg_group;
arg_group.addChild(std::make_unique<Node>(Text{"b"}));
m.arguments.push_back(std::make_unique<Node>(std::move(arg_group)));
root.addChild(std::make_unique<Node>(std::move(m)));
Node root_node(std::move(root));
std::vector<std::string> visited_types;
root_node.forEach([&](const Node& n) {
if (std::holds_alternative<Text>(n.data)) visited_types.push_back("Text");
else if (std::holds_alternative<Macro>(n.data)) visited_types.push_back("Macro");
else if (std::holds_alternative<Group>(n.data)) visited_types.push_back("Group");
});
std::vector<std::string> expected = {"Group", "Text", "Macro", "Group", "Text"};
EXPECT_EQ(visited_types, expected);
}