]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
7c673cae | 3 | |
7c673cae FG |
4 | #include "include/str_list.h" |
5 | ||
7c673cae FG |
6 | #include "gtest/gtest.h" |
7 | ||
11fdf7f2 TL |
8 | // SplitTest is parameterized for list/vector/set |
9 | using Types = ::testing::Types<std::list<std::string>, | |
f67539c2 | 10 | std::vector<std::string>>; |
7c673cae | 11 | |
11fdf7f2 TL |
12 | template <typename T> |
13 | struct SplitTest : ::testing::Test { | |
14 | void test(const char* input, const char *delim, | |
15 | const std::list<std::string>& expected) { | |
16 | EXPECT_EQ(expected, get_str_list(input, delim)); | |
17 | } | |
18 | void test(const char* input, const char *delim, | |
19 | const std::vector<std::string>& expected) { | |
20 | EXPECT_EQ(expected, get_str_vec(input, delim)); | |
21 | } | |
7c673cae FG |
22 | }; |
23 | ||
9f95a23c | 24 | TYPED_TEST_SUITE(SplitTest, Types); |
7c673cae | 25 | |
11fdf7f2 | 26 | TYPED_TEST(SplitTest, Get) |
7c673cae | 27 | { |
11fdf7f2 TL |
28 | this->test("", " ", TypeParam{}); |
29 | this->test(" ", " ", TypeParam{}); | |
30 | this->test("foo", " ", TypeParam{"foo"}); | |
31 | this->test("foo bar", " ", TypeParam{"foo","bar"}); | |
32 | this->test(" foo bar", " ", TypeParam{"foo","bar"}); | |
33 | this->test("foo bar ", " ", TypeParam{"foo","bar"}); | |
34 | this->test("foo bar ", " ", TypeParam{"foo","bar"}); | |
35 | ||
36 | // default delimiter | |
37 | const char *delims = ";,= \t"; | |
38 | this->test(" ; , = \t ", delims, TypeParam{}); | |
39 | this->test(" ; foo = \t ", delims, TypeParam{"foo"}); | |
40 | this->test("a,b,c", delims, TypeParam{"a","b","c"}); | |
41 | this->test("a\tb\tc\t", delims, TypeParam{"a","b","c"}); | |
42 | this->test("a, b, c", delims, TypeParam{"a","b","c"}); | |
43 | this->test("a b c", delims, TypeParam{"a","b","c"}); | |
44 | this->test("a=b=c", delims, TypeParam{"a","b","c"}); | |
7c673cae | 45 | } |