ce49d99c2f
Since we switched from autotools to Meson in commit
94592c1406
, we don't need to include
`config.h` early to properly enable large file support. Meson passes
the required macros on the compiler command line instead of defining
them in `config.h`.
This means we can include `config.h` at any time, whenever we want to
check its macros, and there are no ordering constraints.
57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
/*
|
|
* Unit tests for src/util/
|
|
*/
|
|
|
|
#include "util/SplitString.hxx"
|
|
#include "util/Macros.hxx"
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
TEST(SplitString, Basic)
|
|
{
|
|
constexpr char input[] = "foo.bar";
|
|
const char *const output[] = { "foo", "bar" };
|
|
size_t i = 0;
|
|
for (auto p : SplitString(input, '.')) {
|
|
EXPECT_LT(i, ARRAY_SIZE(output));
|
|
EXPECT_EQ(p, output[i]);
|
|
++i;
|
|
}
|
|
|
|
EXPECT_EQ(ARRAY_SIZE(output), i);
|
|
}
|
|
|
|
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, '.')) {
|
|
EXPECT_LT(i, ARRAY_SIZE(output));
|
|
EXPECT_EQ(p, output[i]);
|
|
++i;
|
|
}
|
|
|
|
EXPECT_EQ(ARRAY_SIZE(output), i);
|
|
}
|
|
|
|
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)) {
|
|
EXPECT_LT(i, ARRAY_SIZE(output));
|
|
EXPECT_EQ(p, output[i]);
|
|
++i;
|
|
}
|
|
|
|
EXPECT_EQ(ARRAY_SIZE(output), i);
|
|
}
|
|
|
|
TEST(SplitString, Empty)
|
|
{
|
|
EXPECT_TRUE(SplitString("", '.').empty());
|
|
}
|