summaryrefslogtreecommitdiffstats
path: root/tests/CompositeChat/CompositeChatTest.cpp
blob: 636a5c95ae3e62540183a3fde3161d387b6d92dc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

// CompositeChatTest.cpp

// Implements the main app entrypoint for the cCompositeChat class test

#include "Globals.h"
#include "../TestHelpers.h"
#include "CompositeChat.h"





static void TestParser1(void)
{
	cCompositeChat Msg;
	Msg.ParseText("Testing @2color codes and http://links parser");
	const auto & Parts = Msg.GetParts();
	TEST_EQUAL(Parts.size(), 4);

	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");
}





static void TestParser2(void)
{
	cCompositeChat Msg;
	Msg.ParseText("@3Advanced stuff: @5overriding color codes and http://links.with/@4color-in-them handling");
	const auto & Parts = Msg.GetParts();
	TEST_EQUAL(Parts.size(), 4);

	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");
}





static void TestParser3(void)
{
	cCompositeChat Msg;
	Msg.ParseText("http://links.starting the text");
	const auto & Parts = Msg.GetParts();
	TEST_EQUAL(Parts.size(), 2);

	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, "");
}





static void TestParser4(void)
{
	cCompositeChat Msg;
	Msg.ParseText("links finishing the text: http://some.server");
	const auto & Parts = Msg.GetParts();
	TEST_EQUAL(Parts.size(), 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::UrlPart>(Parts[1]));
	TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[1]).Style, "");
}





static void TestParser5(void)
{
	cCompositeChat Msg;
	Msg.ParseText("http://only.links");
	const auto & Parts = Msg.GetParts();
	TEST_EQUAL(Parts.size(), 1);

	TEST_TRUE(std::holds_alternative<cCompositeChat::UrlPart>(Parts[0]));
	TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[0]).Style, "");
}




static void TestParser6(void)
{
	cCompositeChat Msg;
	Msg.ParseText("Hello World");
	const auto & Parts = Msg.GetParts();
	TEST_EQUAL(Parts.size(), 1);

	TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[0]));
	TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[0]).Style, "");
}





IMPLEMENT_TEST_MAIN("CompositeChat",
	TestParser1();
	TestParser2();
	TestParser3();
	TestParser4();
	TestParser5();
	TestParser6();
)