Skip to content

Commit

Permalink
test: 添加测试
Browse files Browse the repository at this point in the history
  • Loading branch information
PikachuHy committed May 15, 2021
1 parent caa0980 commit 1b6a315
Showing 1 changed file with 175 additions and 0 deletions.
175 changes: 175 additions & 0 deletions test/test_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,181 @@
#include "Token.h"
#include "gtest/gtest.h"


TEST(ParseUnorderedListTest, OnlyText) {
Parser parser;
auto nodes = parser.parse("- hhh");
ASSERT_EQ(nodes.size(), 1);
auto node = nodes[0];
ASSERT_EQ(node->type(), NodeType::ul);
auto ul = (UnorderedList*)node;
ASSERT_EQ(ul->children().size(), 1);
auto item = ul->children().at(0);
ASSERT_EQ(item->type(), NodeType::ul_item);
auto ul_item = (UnorderedListItem*)item;
ASSERT_EQ(ul_item->children().size(), 1);
auto text = ul_item->children().at(0);
ASSERT_EQ(text->type(), NodeType::text);
}

TEST(ParseUnorderedListTest, OnlyLink) {
Parser parser;
auto nodes = parser.parse("- [666](http://www.666.com)");
ASSERT_EQ(nodes.size(), 1);
auto node = nodes[0];
ASSERT_EQ(node->type(), NodeType::ul);
auto ul = (UnorderedList*)node;
ASSERT_EQ(ul->children().size(), 1);
auto item = ul->children().at(0);
ASSERT_EQ(item->type(), NodeType::ul_item);
auto ul_item = (UnorderedListItem*)item;
ASSERT_EQ(ul_item->children().size(), 1);
auto link = ul_item->children().at(0);
ASSERT_EQ(link->type(), NodeType::link);
}


TEST(ParseUnorderedListTest, TextAndLink) {
Parser parser;
auto nodes = parser.parse("- sdfg[666](http://www.666.com)sdfg");
ASSERT_EQ(nodes.size(), 1);
auto node = nodes[0];
ASSERT_EQ(node->type(), NodeType::ul);
auto ul = (UnorderedList*)node;
ASSERT_EQ(ul->children().size(), 1);
auto item = ul->children().at(0);
ASSERT_EQ(item->type(), NodeType::ul_item);
auto ul_item = (UnorderedListItem*)item;
ASSERT_EQ(ul_item->children().size(), 3);
{
auto text = ul_item->children().at(0);
ASSERT_EQ(text->type(), NodeType::text);
}
auto link = ul_item->children().at(1);
ASSERT_EQ(link->type(), NodeType::link);
{
auto text = ul_item->children().at(2);
ASSERT_EQ(text->type(), NodeType::text);
}
}


TEST(ParseOrderedListTest, OnlyText) {
Parser parser;
auto nodes = parser.parse("1. hhh");
ASSERT_EQ(nodes.size(), 1);
auto node = nodes[0];
ASSERT_EQ(node->type(), NodeType::ol);
auto ol = (OrderedList*)node;
ASSERT_EQ(ol->children().size(), 1);
auto item = ol->children().at(0);
ASSERT_EQ(item->type(), NodeType::ol_item);
auto ul_item = (OrderedListItem*)item;
ASSERT_EQ(ul_item->children().size(), 1);
auto text = ul_item->children().at(0);
ASSERT_EQ(text->type(), NodeType::text);
}

TEST(ParseOrderedListTest, OnlyLink) {
Parser parser;
auto nodes = parser.parse("1. [666](http://www.666.com)");
ASSERT_EQ(nodes.size(), 1);
auto node = nodes[0];
ASSERT_EQ(node->type(), NodeType::ol);
auto ol = (OrderedList*)node;
ASSERT_EQ(ol->children().size(), 1);
auto item = ol->children().at(0);
ASSERT_EQ(item->type(), NodeType::ol_item);
auto ol_item = (OrderedListItem*)item;
ASSERT_EQ(ol_item->children().size(), 1);
auto link = ol_item->children().at(0);
ASSERT_EQ(link->type(), NodeType::link);
}


TEST(ParseOrderedListTest, TextAndLink) {
Parser parser;
auto nodes = parser.parse("1. sdfg[666](http://www.666.com)sdfg");
ASSERT_EQ(nodes.size(), 1);
auto node = nodes[0];
ASSERT_EQ(node->type(), NodeType::ol);
auto ul = (OrderedList*)node;
ASSERT_EQ(ul->children().size(), 1);
auto item = ul->children().at(0);
ASSERT_EQ(item->type(), NodeType::ol_item);
auto ol_item = (OrderedListItem*)item;
ASSERT_EQ(ol_item->children().size(), 3);
{
auto text = ol_item->children().at(0);
ASSERT_EQ(text->type(), NodeType::text);
}
auto link = ol_item->children().at(1);
ASSERT_EQ(link->type(), NodeType::link);
{
auto text = ol_item->children().at(2);
ASSERT_EQ(text->type(), NodeType::text);
}
}


TEST(ParseCheckboxListTest, OnlyText) {
Parser parser;
auto nodes = parser.parse("- [ ] hhh");
ASSERT_EQ(nodes.size(), 1);
auto node = nodes[0];
ASSERT_EQ(node->type(), NodeType::checkbox);
auto ol = (OrderedList*)node;
ASSERT_EQ(ol->children().size(), 1);
auto item = ol->children().at(0);
ASSERT_EQ(item->type(), NodeType::checkbox_item);
auto ul_item = (OrderedListItem*)item;
ASSERT_EQ(ul_item->children().size(), 1);
auto text = ul_item->children().at(0);
ASSERT_EQ(text->type(), NodeType::text);
}

TEST(ParseCheckboxListTest, OnlyLink) {
Parser parser;
auto nodes = parser.parse("- [ ] [666](http://www.666.com)");
ASSERT_EQ(nodes.size(), 1);
auto node = nodes[0];
ASSERT_EQ(node->type(), NodeType::checkbox);
auto ol = (OrderedList*)node;
ASSERT_EQ(ol->children().size(), 1);
auto item = ol->children().at(0);
ASSERT_EQ(item->type(), NodeType::checkbox_item);
auto ol_item = (OrderedListItem*)item;
ASSERT_EQ(ol_item->children().size(), 1);
auto link = ol_item->children().at(0);
ASSERT_EQ(link->type(), NodeType::link);
}


TEST(ParseCheckboxListTest, TextAndLink) {
Parser parser;
auto nodes = parser.parse("- [ ] sdfg[666](http://www.666.com)sdfg");
ASSERT_EQ(nodes.size(), 1);
auto node = nodes[0];
ASSERT_EQ(node->type(), NodeType::checkbox);
auto ul = (OrderedList*)node;
ASSERT_EQ(ul->children().size(), 1);
auto item = ul->children().at(0);
ASSERT_EQ(item->type(), NodeType::checkbox_item);
auto ol_item = (OrderedListItem*)item;
ASSERT_EQ(ol_item->children().size(), 3);
{
auto text = ol_item->children().at(0);
ASSERT_EQ(text->type(), NodeType::text);
}
auto link = ol_item->children().at(1);
ASSERT_EQ(link->type(), NodeType::link);
{
auto text = ol_item->children().at(2);
ASSERT_EQ(text->type(), NodeType::text);
}
}


TEST(ParseImageTest, Only) {
Parser parser;
auto nodes = parser.parse("![666](http://www.666.com)");
Expand Down

0 comments on commit 1b6a315

Please sign in to comment.