2018-10-16 19:01:13 +02:00
|
|
|
/*
|
|
|
|
* Unit tests for src/util/
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "util/SplitString.hxx"
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2019-08-03 13:10:49 +02:00
|
|
|
#include <iterator>
|
2018-10-16 19:01:13 +02:00
|
|
|
|
|
|
|
TEST(SplitString, Basic)
|
|
|
|
{
|
|
|
|
constexpr char input[] = "foo.bar";
|
|
|
|
const char *const output[] = { "foo", "bar" };
|
|
|
|
size_t i = 0;
|
|
|
|
for (auto p : SplitString(input, '.')) {
|
2019-08-03 13:10:49 +02:00
|
|
|
EXPECT_LT(i, std::size(output));
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_EQ(p, output[i]);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2019-08-03 13:10:49 +02:00
|
|
|
EXPECT_EQ(std::size(output), i);
|
2018-10-16 19:01:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SplitString, Strip)
|
|
|
|
{
|
|
|
|
constexpr char input[] = " foo\t.\r\nbar\r\n2";
|
|
|
|
const char *const output[] = { "foo", "bar\r\n2" };
|
|
|
|
size_t i = 0;
|
|
|
|
for (auto p : SplitString(input, '.')) {
|
2019-08-03 13:10:49 +02:00
|
|
|
EXPECT_LT(i, std::size(output));
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_EQ(p, output[i]);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2019-08-03 13:10:49 +02:00
|
|
|
EXPECT_EQ(std::size(output), i);
|
2018-10-16 19:01:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SplitString, NoStrip)
|
|
|
|
{
|
|
|
|
constexpr char input[] = " foo\t.\r\nbar\r\n2";
|
|
|
|
const char *const output[] = { " foo\t", "\r\nbar\r\n2" };
|
|
|
|
size_t i = 0;
|
|
|
|
for (auto p : SplitString(input, '.', false)) {
|
2019-08-03 13:10:49 +02:00
|
|
|
EXPECT_LT(i, std::size(output));
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_EQ(p, output[i]);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2019-08-03 13:10:49 +02:00
|
|
|
EXPECT_EQ(std::size(output), i);
|
2018-10-16 19:01:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SplitString, Empty)
|
|
|
|
{
|
|
|
|
EXPECT_TRUE(SplitString("", '.').empty());
|
|
|
|
}
|