From e6918187568dbd01842d8d1d2c808ce16a894239 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:54:28 +0200 Subject: Adding upstream version 18.2.2. Signed-off-by: Daniel Baumann --- src/test/test_str_list.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/test_str_list.cc (limited to 'src/test/test_str_list.cc') 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::vector>; + +template +struct SplitTest : ::testing::Test { + void test(const char* input, const char *delim, + const std::list& expected) { + EXPECT_EQ(expected, get_str_list(input, delim)); + } + void test(const char* input, const char *delim, + const std::vector& 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"}); +} -- cgit v1.2.3