forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.cpp
96 lines (77 loc) · 2.58 KB
/
utils.cpp
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
#include <cassert>
#include <cstdlib>
#include "utils.h"
#include "doctest.h"
TEST_SUITE_BEGIN("Utils");
TEST_CASE("Lower") {
REQUIRE_EQ(Utils::LowerCase("EasyRPG"), "easyrpg");
REQUIRE_EQ(Utils::LowerCase("player"), "player");
REQUIRE_EQ(Utils::LowerCase("!A/b"), "!a/b");
}
TEST_CASE("Upper") {
REQUIRE_EQ(Utils::UpperCase("EasyRPG"), "EASYRPG");
REQUIRE_EQ(Utils::UpperCase("player"), "PLAYER");
REQUIRE_EQ(Utils::UpperCase("!A/b"), "!A/B");
}
template <typename T>
static void testStrICmp() {
REQUIRE_EQ(Utils::StrICmp(T("easyrpg"), T("easyrpg")), 0);
REQUIRE_EQ(Utils::StrICmp(T("easyrpg"), T("EASYRPG")), 0);
REQUIRE_EQ(Utils::StrICmp(T("EASYRPG"), T("easyrpg")), 0);
REQUIRE_LT(Utils::StrICmp(T("A"), T("B")), 0);
REQUIRE_LT(Utils::StrICmp(T("a"), T("B")), 0);
REQUIRE_LT(Utils::StrICmp(T("A"), T("b")), 0);
REQUIRE_GT(Utils::StrICmp(T("B"), T("A")), 0);
REQUIRE_GT(Utils::StrICmp(T("b"), T("A")), 0);
REQUIRE_GT(Utils::StrICmp(T("B"), T("a")), 0);
REQUIRE_GT(Utils::StrICmp(T("AA"), T("A")), 0);
REQUIRE_GT(Utils::StrICmp(T("aa"), T("A")), 0);
REQUIRE_GT(Utils::StrICmp(T("AA"), T("a")), 0);
REQUIRE_LT(Utils::StrICmp(T("A"), T("AA")), 0);
REQUIRE_LT(Utils::StrICmp(T("a"), T("AA")), 0);
REQUIRE_LT(Utils::StrICmp(T("A"), T("aa")), 0);
}
TEST_CASE("StrICmp") {
SUBCASE("cstr") {
testStrICmp<const char*>();
}
SUBCASE("sv") {
testStrICmp<StringView>();
}
}
TEST_CASE("ReplaceAll") {
SUBCASE("one") {
REQUIRE(Utils::ReplaceAll("abc", "b", "xyz") == "axyzc");
REQUIRE(Utils::ReplaceAll("abc", "abc", "uvwxyz") == "uvwxyz");
REQUIRE(Utils::ReplaceAll("abc", "c", "xyz") == "abxyz");
}
SUBCASE("url encode") {
REQUIRE(Utils::ReplaceAll("ab+cd", "+", "%2B") == "ab%2Bcd");
REQUIRE(Utils::ReplaceAll("ab%cd", "%", "%25") == "ab%25cd");
}
SUBCASE("many") {
REQUIRE(Utils::ReplaceAll("abba", "b", "xyz") == "axyzxyza");
REQUIRE(Utils::ReplaceAll("abba", "a", "ba") == "babbba");
}
}
TEST_CASE("TrimWhitespace") {
SUBCASE("left") {
REQUIRE(Utils::TrimWhitespace(" le ft") == "le ft");
REQUIRE(Utils::TrimWhitespace(" le ft") == "le ft");
}
SUBCASE("right") {
REQUIRE(Utils::TrimWhitespace("ri ght ") == "ri ght");
REQUIRE(Utils::TrimWhitespace("ri ght ") == "ri ght");
}
SUBCASE("both") {
REQUIRE(Utils::TrimWhitespace(" bot h ") == "bot h");
REQUIRE(Utils::TrimWhitespace(" bot h ") == "bot h");
REQUIRE(Utils::TrimWhitespace(" bot h ") == "bot h");
}
SUBCASE("other") {
REQUIRE(Utils::TrimWhitespace("") == "");
REQUIRE(Utils::TrimWhitespace(" ") == "");
REQUIRE(Utils::TrimWhitespace("T ex t") == "T ex t");
}
}
TEST_SUITE_END();