diff --git a/test/test_parser.cpp b/test/test_parser.cpp index f95065e..ac9cbd4 100644 --- a/test/test_parser.cpp +++ b/test/test_parser.cpp @@ -54,6 +54,17 @@ TEST(ParseInlineLatexTest, Only) { auto link = p->children().at(0); ASSERT_EQ(link->type(), NodeType::inline_latex); } +TEST(ParseItalicTest, Only) { + Parser parser; + auto nodes = parser.parse("*666*"); + ASSERT_EQ(nodes.size(), 1); + auto node = nodes[0]; + ASSERT_EQ(node->type(), NodeType::paragraph); + auto p = (Paragraph*)node; + ASSERT_EQ(p->children().size(), 1); + auto link = p->children().at(0); + ASSERT_EQ(link->type(), NodeType::italic); +} TEST(ParseBoldTest, Only) { Parser parser; auto nodes = parser.parse("**666**"); @@ -64,4 +75,109 @@ TEST(ParseBoldTest, Only) { ASSERT_EQ(p->children().size(), 1); auto link = p->children().at(0); ASSERT_EQ(link->type(), NodeType::bold); -} \ No newline at end of file +} + +TEST(ParseItalicBoldBoldTest, Only) { + Parser parser; + auto nodes = parser.parse("***666***"); + ASSERT_EQ(nodes.size(), 1); + auto node = nodes[0]; + ASSERT_EQ(node->type(), NodeType::paragraph); + auto p = (Paragraph*)node; + ASSERT_EQ(p->children().size(), 1); + auto link = p->children().at(0); + ASSERT_EQ(link->type(), NodeType::italic_bold); +} + +TEST(ParseLinkTest, Middle) { + Parser parser; + auto nodes = parser.parse("before[666](http://www.666.com)after"); + ASSERT_EQ(nodes.size(), 1); + auto node = nodes[0]; + ASSERT_EQ(node->type(), NodeType::paragraph); + auto p = (Paragraph*)node; + ASSERT_EQ(p->children().size(), 3); + auto before = p->children().at(0); + ASSERT_EQ(before->type(), NodeType::text); + auto link = p->children().at(1); + ASSERT_EQ(link->type(), NodeType::link); + auto after = p->children().at(2); + ASSERT_EQ(after->type(), NodeType::text); +} +TEST(ParseInlineCodeTest, Middle) { + Parser parser; + auto nodes = parser.parse("before`#include`after"); + ASSERT_EQ(nodes.size(), 1); + auto node = nodes[0]; + ASSERT_EQ(node->type(), NodeType::paragraph); + auto p = (Paragraph*)node; + ASSERT_EQ(p->children().size(), 3); + auto before = p->children().at(0); + ASSERT_EQ(before->type(), NodeType::text); + auto ic = p->children().at(1); + ASSERT_EQ(ic->type(), NodeType::inline_code); + auto after = p->children().at(2); + ASSERT_EQ(after->type(), NodeType::text); +} +TEST(ParseInlineLatexTest, Middle) { + Parser parser; + auto nodes = parser.parse("before$a^2$after"); + ASSERT_EQ(nodes.size(), 1); + auto node = nodes[0]; + ASSERT_EQ(node->type(), NodeType::paragraph); + auto p = (Paragraph*)node; + ASSERT_EQ(p->children().size(), 3); + auto before = p->children().at(0); + ASSERT_EQ(before->type(), NodeType::text); + auto il = p->children().at(1); + ASSERT_EQ(il->type(), NodeType::inline_latex); + auto after = p->children().at(2); + ASSERT_EQ(after->type(), NodeType::text); +} +TEST(ParseItalicTest, Middle) { + Parser parser; + auto nodes = parser.parse("before*666*after"); + ASSERT_EQ(nodes.size(), 1); + auto node = nodes[0]; + ASSERT_EQ(node->type(), NodeType::paragraph); + auto p = (Paragraph*)node; + ASSERT_EQ(p->children().size(), 3); + auto before = p->children().at(0); + ASSERT_EQ(before->type(), NodeType::text); + auto i = p->children().at(1); + ASSERT_EQ(i->type(), NodeType::italic); + auto after = p->children().at(2); + ASSERT_EQ(after->type(), NodeType::text); +} +TEST(ParseBoldTest, Middle) { + Parser parser; + auto nodes = parser.parse("before**666**after"); + ASSERT_EQ(nodes.size(), 1); + auto node = nodes[0]; + ASSERT_EQ(node->type(), NodeType::paragraph); + auto p = (Paragraph*)node; + ASSERT_EQ(p->children().size(), 3); + auto before = p->children().at(0); + ASSERT_EQ(before->type(), NodeType::text); + auto b = p->children().at(1); + ASSERT_EQ(b->type(), NodeType::bold); + auto after = p->children().at(2); + ASSERT_EQ(after->type(), NodeType::text); +} + +TEST(ParseItalicBoldBoldTest, Middle) { + Parser parser; + auto nodes = parser.parse("before***666***after"); + ASSERT_EQ(nodes.size(), 1); + auto node = nodes[0]; + ASSERT_EQ(node->type(), NodeType::paragraph); + auto p = (Paragraph*)node; + ASSERT_EQ(p->children().size(), 3); + auto before = p->children().at(0); + ASSERT_EQ(before->type(), NodeType::text); + auto it = p->children().at(1); + ASSERT_EQ(it->type(), NodeType::italic_bold); + auto after = p->children().at(2); + ASSERT_EQ(after->type(), NodeType::text); +} +