-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_util_test.cpp
More file actions
70 lines (57 loc) · 2.35 KB
/
string_util_test.cpp
File metadata and controls
70 lines (57 loc) · 2.35 KB
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
#include <iostream>
#include "string_util.cpp"
void test_startsWith() {
std::string str = "abcdef?=";
std::string prefix = "abc";
bool expected = true;
bool actual = startsWith(str, prefix);
if (expected != actual) {
throw std::invalid_argument("expected and actual are different");
}
}
void test_strToLower() {
std::string str = "ABcdef?=";
std::string expected = "abcdef?=";
std::string actual = strToLower(str);
if (expected != actual) {
throw std::invalid_argument("expected '" + expected + "' but actual was: '" + actual + "'");
}
}
void test_trimPrefix() {
std::string str = "abcdef?=";
std::string prefix = "abc";
std::string expected = "def?=";
std::string actual = trimPrefix(str, prefix);
if (expected != actual) {
throw std::invalid_argument("expected '" + expected + "' but actual was: '" + actual + "'");
}
}
void test_trimSuffix() {
std::string str = "abcdef?=";
std::string suffix = "?=";
std::string expected = "abcdef";
std::string actual = trimSuffix(str, suffix);
if (expected != actual) {
throw std::invalid_argument("expected '" + expected + "' but actual was: '" + actual + "'");
}
}
void test_decodeQuotedPrinted() {
std::string expectedDecoded = "J'interdis aux marchands de vanter trop leurs marchandises. Car ils se font vite pédagogues et t'enseignent comme but ce qui n'est par essence qu'un moyen, et te trompant ainsi sur la route à suivre les voilà bientôt qui te dégradent, car si leur musique est vulgaire ils te fabriquent pour te la vendre une âme vulgaire.";
std::string encoded =
"J'interdis aux marchands de vanter trop leurs marchandises. Car ils se font =\n"
"vite p=C3=A9dagogues et t'enseignent comme but ce qui n'est par essence qu'=\n"
"un moyen, et te trompant ainsi sur la route =C3=A0 suivre les voil=C3=A0 bi=\n"
"ent=C3=B4t qui te d=C3=A9gradent, car si leur musique est vulgaire ils te f=\n"
"abriquent pour te la vendre une =C3=A2me vulgaire.";
auto decoded (decodeQuotedPrinted(encoded));
if (decoded != expectedDecoded) {
throw std::invalid_argument("expected '" + expectedDecoded + "' but actual was: '" + decoded + "'");
}
}
int main() {
test_decodeQuotedPrinted();
test_trimSuffix();
test_trimPrefix();
test_strToLower();
test_startsWith();
}