summaryrefslogtreecommitdiffstats
path: root/tests/CompositeChat/CompositeChatTest.cpp
diff options
context:
space:
mode:
author12xx12 <44411062+12xx12@users.noreply.github.com>2021-02-05 03:05:14 +0100
committerTiger Wang <ziwei.tiger@outlook.com>2021-02-08 13:41:30 +0100
commit2481190d9c9f25fac2f97708c752990f873f44f0 (patch)
tree0b50f6cde0e1bd34b54ab11a933b678c30d30999 /tests/CompositeChat/CompositeChatTest.cpp
parentExplodinator performance optimisations (diff)
downloadcuberite-2481190d9c9f25fac2f97708c752990f873f44f0.tar
cuberite-2481190d9c9f25fac2f97708c752990f873f44f0.tar.gz
cuberite-2481190d9c9f25fac2f97708c752990f873f44f0.tar.bz2
cuberite-2481190d9c9f25fac2f97708c752990f873f44f0.tar.lz
cuberite-2481190d9c9f25fac2f97708c752990f873f44f0.tar.xz
cuberite-2481190d9c9f25fac2f97708c752990f873f44f0.tar.zst
cuberite-2481190d9c9f25fac2f97708c752990f873f44f0.zip
Diffstat (limited to 'tests/CompositeChat/CompositeChatTest.cpp')
-rw-r--r--tests/CompositeChat/CompositeChatTest.cpp82
1 files changed, 48 insertions, 34 deletions
diff --git a/tests/CompositeChat/CompositeChatTest.cpp b/tests/CompositeChat/CompositeChatTest.cpp
index 08733d661..636a5c95a 100644
--- a/tests/CompositeChat/CompositeChatTest.cpp
+++ b/tests/CompositeChat/CompositeChatTest.cpp
@@ -15,16 +15,20 @@ static void TestParser1(void)
{
cCompositeChat Msg;
Msg.ParseText("Testing @2color codes and http://links parser");
- const cCompositeChat::cParts & Parts = Msg.GetParts();
+ const auto & Parts = Msg.GetParts();
TEST_EQUAL(Parts.size(), 4);
- TEST_EQUAL(Parts[0]->m_PartType, cCompositeChat::ptText);
- TEST_EQUAL(Parts[1]->m_PartType, cCompositeChat::ptText);
- TEST_EQUAL(Parts[2]->m_PartType, cCompositeChat::ptUrl);
- TEST_EQUAL(Parts[3]->m_PartType, cCompositeChat::ptText);
- TEST_EQUAL(Parts[0]->m_Style, "");
- TEST_EQUAL(Parts[1]->m_Style, "@2");
- TEST_EQUAL(Parts[2]->m_Style, "@2");
- TEST_EQUAL(Parts[3]->m_Style, "@2");
+
+ TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[0]));
+ TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[0]).Style, "");
+
+ TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[1]));
+ TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[1]).Style, "@2");
+
+ TEST_TRUE(std::holds_alternative<cCompositeChat::UrlPart>(Parts[2]));
+ TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[2]).Style, "@2");
+
+ TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[3]));
+ TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[3]).Style, "@2");
}
@@ -35,16 +39,20 @@ static void TestParser2(void)
{
cCompositeChat Msg;
Msg.ParseText("@3Advanced stuff: @5overriding color codes and http://links.with/@4color-in-them handling");
- const cCompositeChat::cParts & Parts = Msg.GetParts();
+ const auto & Parts = Msg.GetParts();
TEST_EQUAL(Parts.size(), 4);
- TEST_EQUAL(Parts[0]->m_PartType, cCompositeChat::ptText);
- TEST_EQUAL(Parts[1]->m_PartType, cCompositeChat::ptText);
- TEST_EQUAL(Parts[2]->m_PartType, cCompositeChat::ptUrl);
- TEST_EQUAL(Parts[3]->m_PartType, cCompositeChat::ptText);
- TEST_EQUAL(Parts[0]->m_Style, "@3");
- TEST_EQUAL(Parts[1]->m_Style, "@5");
- TEST_EQUAL(Parts[2]->m_Style, "@5");
- TEST_EQUAL(Parts[3]->m_Style, "@5");
+
+ TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[0]));
+ TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[0]).Style, "@3");
+
+ TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[1]));
+ TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[1]).Style, "@5");
+
+ TEST_TRUE(std::holds_alternative<cCompositeChat::UrlPart>(Parts[2]));
+ TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[2]).Style, "@5");
+
+ TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[3]));
+ TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[3]).Style, "@5");
}
@@ -55,12 +63,14 @@ static void TestParser3(void)
{
cCompositeChat Msg;
Msg.ParseText("http://links.starting the text");
- const cCompositeChat::cParts & Parts = Msg.GetParts();
+ const auto & Parts = Msg.GetParts();
TEST_EQUAL(Parts.size(), 2);
- TEST_EQUAL(Parts[0]->m_PartType, cCompositeChat::ptUrl);
- TEST_EQUAL(Parts[1]->m_PartType, cCompositeChat::ptText);
- TEST_EQUAL(Parts[0]->m_Style, "");
- TEST_EQUAL(Parts[1]->m_Style, "");
+
+ TEST_TRUE(std::holds_alternative<cCompositeChat::UrlPart>(Parts[0]));
+ TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[0]).Style, "");
+
+ TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[1]));
+ TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[1]).Style, "");
}
@@ -71,12 +81,14 @@ static void TestParser4(void)
{
cCompositeChat Msg;
Msg.ParseText("links finishing the text: http://some.server");
- const cCompositeChat::cParts & Parts = Msg.GetParts();
+ const auto & Parts = Msg.GetParts();
TEST_EQUAL(Parts.size(), 2);
- TEST_EQUAL(Parts[0]->m_PartType, cCompositeChat::ptText);
- TEST_EQUAL(Parts[1]->m_PartType, cCompositeChat::ptUrl);
- TEST_EQUAL(Parts[0]->m_Style, "");
- TEST_EQUAL(Parts[1]->m_Style, "");
+
+ TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[0]));
+ TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[0]).Style, "");
+
+ TEST_TRUE(std::holds_alternative<cCompositeChat::UrlPart>(Parts[1]));
+ TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[1]).Style, "");
}
@@ -87,10 +99,11 @@ static void TestParser5(void)
{
cCompositeChat Msg;
Msg.ParseText("http://only.links");
- const cCompositeChat::cParts & Parts = Msg.GetParts();
+ const auto & Parts = Msg.GetParts();
TEST_EQUAL(Parts.size(), 1);
- TEST_EQUAL(Parts[0]->m_PartType, cCompositeChat::ptUrl);
- TEST_EQUAL(Parts[0]->m_Style, "");
+
+ TEST_TRUE(std::holds_alternative<cCompositeChat::UrlPart>(Parts[0]));
+ TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[0]).Style, "");
}
@@ -100,10 +113,11 @@ static void TestParser6(void)
{
cCompositeChat Msg;
Msg.ParseText("Hello World");
- const cCompositeChat::cParts & Parts = Msg.GetParts();
+ const auto & Parts = Msg.GetParts();
TEST_EQUAL(Parts.size(), 1);
- TEST_EQUAL(Parts[0]->m_PartType, cCompositeChat::ptText);
- TEST_EQUAL(Parts[0]->m_Style, "");
+
+ TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[0]));
+ TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[0]).Style, "");
}