From 1b6a315d71d8099225a826bc13462ef1f5bc4583 Mon Sep 17 00:00:00 2001 From: PikachuHy Date: Sat, 15 May 2021 14:25:04 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test_parser.cpp | 175 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) diff --git a/test/test_parser.cpp b/test/test_parser.cpp index 26e0959..eb31daf 100644 --- a/test/test_parser.cpp +++ b/test/test_parser.cpp @@ -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)");