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
|
#include "include/types.h"
#include "include/str_list.h"
#include <list>
#include <vector>
#include <string>
#include "gtest/gtest.h"
const char *tests[][10] = {
{ "foo,bar", "foo", "bar", 0 },
{ "foo", "foo", 0 },
{ "foo;bar", "foo", "bar", 0 },
{ "foo bar", "foo", "bar", 0 },
{ " foo bar", "foo", "bar", 0 },
{ " foo bar ", "foo", "bar", 0 },
{ "a,b,c", "a", "b", "c", 0 },
{ " a\tb\tc\t", "a", "b", "c", 0 },
{ "a, b, c", "a", "b", "c", 0 },
{ "a b c", "a", "b", "c", 0 },
{ "a=b=c", "a", "b", "c", 0 },
{ 0 },
};
TEST(StrList, get_str_list)
{
for (unsigned i=0; tests[i][0]; ++i) {
std::string src = tests[i][0];
std::list<std::string> expected;
for (unsigned j=1; tests[i][j]; ++j)
expected.push_back(tests[i][j]);
std::list<std::string> actual;
get_str_list(src, actual);
std::cout << "'" << src << "' -> " << actual << std::endl;
ASSERT_EQ(actual, expected);
}
}
TEST(StrList, get_str_vec)
{
for (unsigned i=0; tests[i][0]; ++i) {
std::string src = tests[i][0];
std::vector<std::string> expected;
for (unsigned j=1; tests[i][j]; ++j)
expected.push_back(tests[i][j]);
std::vector<std::string> actual;
get_str_vec (src, actual);
std::cout << "'" << src << "' -> " << actual << std::endl;
ASSERT_EQ(actual, expected);
}
}
|