aboutsummaryrefslogtreecommitdiff
path: root/test/xml/ParserTest.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-05-10 19:18:32 +0800
committercrupest <crupest@outlook.com>2022-05-10 19:18:32 +0800
commit891bf38d8580b83cdf6ae315cb2650dae7d79006 (patch)
tree3e7714df65147489c88dfc00a656339b29097d90 /test/xml/ParserTest.cpp
parentb846a16e42b30418fe91ba3f06771fad57100624 (diff)
downloadcru-891bf38d8580b83cdf6ae315cb2650dae7d79006.tar.gz
cru-891bf38d8580b83cdf6ae315cb2650dae7d79006.tar.bz2
cru-891bf38d8580b83cdf6ae315cb2650dae7d79006.zip
...
Diffstat (limited to 'test/xml/ParserTest.cpp')
-rw-r--r--test/xml/ParserTest.cpp104
1 files changed, 52 insertions, 52 deletions
diff --git a/test/xml/ParserTest.cpp b/test/xml/ParserTest.cpp
index 8edebeb6..d998abb4 100644
--- a/test/xml/ParserTest.cpp
+++ b/test/xml/ParserTest.cpp
@@ -1,82 +1,82 @@
#include "cru/xml/XmlNode.h"
#include "cru/xml/XmlParser.h"
-#include <gtest/gtest.h>
+#include <catch2/catch_test_macros.hpp>
using namespace cru::xml;
-TEST(CruXmlParserTest, Simple) {
+TEST_CASE("CruXmlParserTest Simple", "[xml]") {
XmlParser parser(u"<root></root>");
auto n = parser.Parse();
- ASSERT_EQ(n->GetTag(), u"root");
- ASSERT_EQ(n->GetAttributes().empty(), true);
- ASSERT_EQ(n->GetChildCount(), 0);
+ REQUIRE(n->GetTag() == u"root");
+ REQUIRE(n->GetAttributes().empty() == true);
+ REQUIRE(n->GetChildCount() == 0);
delete n;
}
-TEST(CruXmlParserTest, SimpleWithAttribute) {
+TEST_CASE("CruXmlParserTest SimpleWithAttribute", "[xml]") {
XmlParser parser(u"<root a1=\"v1\" a2=\"v2\"></root>");
auto n = parser.Parse();
- ASSERT_EQ(n->GetTag(), u"root");
- ASSERT_EQ(n->GetAttributeValue(u"a1"), u"v1");
- ASSERT_EQ(n->GetAttributeValue(u"a2"), u"v2");
- ASSERT_EQ(n->GetChildCount(), 0);
+ REQUIRE(n->GetTag() == u"root");
+ REQUIRE(n->GetAttributeValue(u"a1") == u"v1");
+ REQUIRE(n->GetAttributeValue(u"a2") == u"v2");
+ REQUIRE(n->GetChildCount() == 0);
delete n;
}
-TEST(CruXmlParserTest, SimpleSelfClosing) {
+TEST_CASE("CruXmlParserTest SimpleSelfClosing", "[xml]") {
XmlParser parser(u"<root a1=\"v1\" a2=\"v2\"/>");
auto n = parser.Parse();
- ASSERT_EQ(n->GetTag(), u"root");
- ASSERT_EQ(n->GetAttributeValue(u"a1"), u"v1");
- ASSERT_EQ(n->GetAttributeValue(u"a2"), u"v2");
- ASSERT_EQ(n->GetChildCount(), 0);
+ REQUIRE(n->GetTag() == u"root");
+ REQUIRE(n->GetAttributeValue(u"a1") == u"v1");
+ REQUIRE(n->GetAttributeValue(u"a2") == u"v2");
+ REQUIRE(n->GetChildCount() == 0);
delete n;
}
-TEST(CruXmlParserTest, NestedElement) {
+TEST_CASE("CruXmlParserTest NestedElement", "[xml]") {
XmlParser parser(
u"<root><c1><d1></d1></c1><c2><d2></d2><d3></d3></c2></root>");
auto n = parser.Parse();
- ASSERT_EQ(n->GetChildren().size(), 2);
- ASSERT_EQ(n->GetChildAt(0)->AsElement()->GetTag(), u"c1");
- ASSERT_EQ(n->GetChildAt(1)->AsElement()->GetTag(), u"c2");
- ASSERT_EQ(n->GetChildAt(0)->AsElement()->GetChildCount(), 1);
- ASSERT_EQ(n->GetChildAt(0)->AsElement()->GetChildAt(0)->AsElement()->GetTag(),
- u"d1");
- ASSERT_EQ(n->GetChildAt(1)->AsElement()->GetChildCount(), 2);
- ASSERT_EQ(n->GetChildAt(1)->AsElement()->GetChildAt(0)->AsElement()->GetTag(),
- u"d2");
- ASSERT_EQ(n->GetChildAt(1)->AsElement()->GetChildAt(1)->AsElement()->GetTag(),
- u"d3");
+ REQUIRE(n->GetChildren().size() == 2);
+ REQUIRE(n->GetChildAt(0)->AsElement()->GetTag() == u"c1");
+ REQUIRE(n->GetChildAt(1)->AsElement()->GetTag() == u"c2");
+ REQUIRE(n->GetChildAt(0)->AsElement()->GetChildCount() == 1);
+ REQUIRE(n->GetChildAt(0)->AsElement()->GetChildAt(0)->AsElement()->GetTag() ==
+ u"d1");
+ REQUIRE(n->GetChildAt(1)->AsElement()->GetChildCount() == 2);
+ REQUIRE(n->GetChildAt(1)->AsElement()->GetChildAt(0)->AsElement()->GetTag() ==
+ u"d2");
+ REQUIRE(n->GetChildAt(1)->AsElement()->GetChildAt(1)->AsElement()->GetTag() ==
+ u"d3");
delete n;
}
-TEST(CruXmlParserTest, SimpleText) {
+TEST_CASE("CruXmlParserTest SimpleText", "[xml]") {
XmlParser parser(u"<root>text</root>");
auto n = parser.Parse();
- ASSERT_EQ(n->GetChildCount(), 1);
- ASSERT_EQ(n->GetChildAt(0)->AsText()->GetText(), u"text");
+ REQUIRE(n->GetChildCount() == 1);
+ REQUIRE(n->GetChildAt(0)->AsText()->GetText() == u"text");
delete n;
}
-TEST(CruXmlParserTest, Whitespace) {
+TEST_CASE("CruXmlParserTest Whitespace", "[xml]") {
XmlParser parser(u"\t\t<root>\n\t\t\ttext test\n\t\t</root>\t\t");
auto n = parser.Parse();
- ASSERT_EQ(n->GetChildCount(), 1);
- ASSERT_EQ(n->GetChildAt(0)->AsText()->GetText(), u"text test");
+ REQUIRE(n->GetChildCount() == 1);
+ REQUIRE(n->GetChildAt(0)->AsText()->GetText() == u"text test");
delete n;
}
-TEST(CruXmlParserTest, Comment) {
+TEST_CASE("CruXmlParserTest Comment", "[xml]") {
XmlParser parser(u"<!-- comment -->");
auto n = parser.Parse();
- ASSERT_TRUE(n->IsCommentNode());
- ASSERT_EQ(n->AsComment()->GetText(), u"comment");
+ REQUIRE(n->IsCommentNode());
+ REQUIRE(n->AsComment()->GetText() == u"comment");
delete n;
}
-TEST(CruXmlParserTest, Complex) {
+TEST_CASE("CruXmlParserTest Complex", "[xml]") {
XmlParser parser(
uR"(
<root a1="v1">
@@ -95,22 +95,22 @@ TEST(CruXmlParserTest, Complex) {
</root>
)");
auto n = parser.Parse();
- ASSERT_EQ(n->GetAttributeValue(u"a1"), u"v1");
- ASSERT_EQ(n->GetChildCount(), 3);
- ASSERT_EQ(n->GetChildAt(0)->AsElement()->GetTag(), u"c1");
- ASSERT_EQ(n->GetChildAt(0)->AsElement()->GetChildCount(), 1);
+ REQUIRE(n->GetAttributeValue(u"a1") == u"v1");
+ REQUIRE(n->GetChildCount() == 3);
+ REQUIRE(n->GetChildAt(0)->AsElement()->GetTag() == u"c1");
+ REQUIRE(n->GetChildAt(0)->AsElement()->GetChildCount() == 1);
auto c2 = n->GetChildAt(1)->AsElement();
- ASSERT_EQ(c2->GetTag(), u"c2");
- ASSERT_EQ(c2->GetAttributeValue(u"a2"), u"v2");
- ASSERT_EQ(c2->GetAttributeValue(u"a3"), u"v3");
- ASSERT_EQ(c2->GetChildAt(0)->AsText()->GetText(), u"t1");
+ REQUIRE(c2->GetTag() == u"c2");
+ REQUIRE(c2->GetAttributeValue(u"a2") == u"v2");
+ REQUIRE(c2->GetAttributeValue(u"a3") == u"v3");
+ REQUIRE(c2->GetChildAt(0)->AsText()->GetText() == u"t1");
auto d2 = c2->GetChildAt(1)->AsElement();
- ASSERT_EQ(d2->GetTag(), u"d2");
- ASSERT_EQ(d2->GetAttributeValue(u"a4"), u"v4");
- ASSERT_EQ(c2->GetChildAt(2)->AsText()->GetText(), u"text test");
- ASSERT_EQ(c2->GetChildAt(3)->AsElement()->GetTag(), u"d3");
- ASSERT_EQ(c2->GetChildAt(4)->AsText()->GetText(), u"t2");
- ASSERT_TRUE(n->GetChildAt(2)->IsCommentNode());
- ASSERT_EQ(n->GetChildAt(2)->AsComment()->GetText(), u"comment");
+ REQUIRE(d2->GetTag() == u"d2");
+ REQUIRE(d2->GetAttributeValue(u"a4") == u"v4");
+ REQUIRE(c2->GetChildAt(2)->AsText()->GetText() == u"text test");
+ REQUIRE(c2->GetChildAt(3)->AsElement()->GetTag() == u"d3");
+ REQUIRE(c2->GetChildAt(4)->AsText()->GetText() == u"t2");
+ REQUIRE(n->GetChildAt(2)->IsCommentNode());
+ REQUIRE(n->GetChildAt(2)->AsComment()->GetText() == u"comment");
delete n;
}