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
|
#include "Util.h"
#define BOOST_TEST_MODULE UtilTest
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(util_get_next_pound_test) {
{
std::string str("9 9 7 ");
std::string substr;
std::vector<std::string> res;
while (!str.empty()) {
getNextPound(str, substr);
res.push_back(substr);
}
BOOST_REQUIRE(res.size() == 3);
BOOST_CHECK_EQUAL("9", res[0]);
BOOST_CHECK_EQUAL("9", res[1]);
BOOST_CHECK_EQUAL("7", res[2]);
}
{
std::string str("ref.0,ref.1,ref.2");
std::string substr;
std::vector<std::string> res;
const std::string delim(",");
while (!str.empty()) {
getNextPound(str, substr, delim);
res.push_back(substr);
}
BOOST_REQUIRE(res.size() == 3);
BOOST_CHECK_EQUAL("ref.0", res[0]);
BOOST_CHECK_EQUAL("ref.1", res[1]);
BOOST_CHECK_EQUAL("ref.2", res[2]);
}
}
BOOST_AUTO_TEST_CASE(util_tokenize_test) {
{
std::vector<std::string> res;
Tokenize("9 9 7", ' ', &res);
BOOST_REQUIRE(res.size() == 3);
BOOST_CHECK_EQUAL("9", res[0]);
BOOST_CHECK_EQUAL("9", res[1]);
BOOST_CHECK_EQUAL("7", res[2]);
}
{
std::vector<std::string> res;
Tokenize("9 8 7 ", ' ', &res);
BOOST_REQUIRE(res.size() == 3);
BOOST_CHECK_EQUAL("9", res[0]);
BOOST_CHECK_EQUAL("8", res[1]);
BOOST_CHECK_EQUAL("7", res[2]);
}
{
std::vector<std::string> res;
Tokenize("ref.0,ref.1,", ',', &res);
BOOST_REQUIRE(res.size() == 2);
BOOST_CHECK_EQUAL("ref.0", res[0]);
BOOST_CHECK_EQUAL("ref.1", res[1]);
}
}
BOOST_AUTO_TEST_CASE(util_ends_with_test) {
BOOST_CHECK(EndsWith("abc:", ":"));
BOOST_CHECK(EndsWith("a b c:", ":"));
BOOST_CHECK(!EndsWith("a", ":"));
BOOST_CHECK(!EndsWith("a:b", ":"));
BOOST_CHECK(EndsWith("ab ", " "));
BOOST_CHECK(!EndsWith("ab", " "));
BOOST_CHECK(!EndsWith("a b", " "));
}
|