diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/test/test_str_list.cc | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test_str_list.cc')
-rw-r--r-- | src/test/test_str_list.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/test/test_str_list.cc b/src/test/test_str_list.cc new file mode 100644 index 000000000..363395011 --- /dev/null +++ b/src/test/test_str_list.cc @@ -0,0 +1,45 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "include/str_list.h" + +#include "gtest/gtest.h" + +// SplitTest is parameterized for list/vector/set +using Types = ::testing::Types<std::list<std::string>, + std::vector<std::string>>; + +template <typename T> +struct SplitTest : ::testing::Test { + void test(const char* input, const char *delim, + const std::list<std::string>& expected) { + EXPECT_EQ(expected, get_str_list(input, delim)); + } + void test(const char* input, const char *delim, + const std::vector<std::string>& expected) { + EXPECT_EQ(expected, get_str_vec(input, delim)); + } +}; + +TYPED_TEST_SUITE(SplitTest, Types); + +TYPED_TEST(SplitTest, Get) +{ + this->test("", " ", TypeParam{}); + this->test(" ", " ", TypeParam{}); + this->test("foo", " ", TypeParam{"foo"}); + this->test("foo bar", " ", TypeParam{"foo","bar"}); + this->test(" foo bar", " ", TypeParam{"foo","bar"}); + this->test("foo bar ", " ", TypeParam{"foo","bar"}); + this->test("foo bar ", " ", TypeParam{"foo","bar"}); + + // default delimiter + const char *delims = ";,= \t"; + this->test(" ; , = \t ", delims, TypeParam{}); + this->test(" ; foo = \t ", delims, TypeParam{"foo"}); + this->test("a,b,c", delims, TypeParam{"a","b","c"}); + this->test("a\tb\tc\t", delims, TypeParam{"a","b","c"}); + this->test("a, b, c", delims, TypeParam{"a","b","c"}); + this->test("a b c", delims, TypeParam{"a","b","c"}); + this->test("a=b=c", delims, TypeParam{"a","b","c"}); +} |