ClickHouse/base/common/tests/gtest_find_symbols.cpp

39 lines
1.4 KiB
C++
Raw Normal View History

#include <string>
2020-03-21 02:52:37 +00:00
#include <vector>
#include <common/find_symbols.h>
#include <gtest/gtest.h>
2020-03-09 01:50:33 +00:00
TEST(FindSymbols, SimpleTest)
{
std::string s = "Hello, world! Goodbye...";
const char * begin = s.data();
const char * end = s.data() + s.size();
ASSERT_EQ(find_first_symbols<'a'>(begin, end), end);
ASSERT_EQ(find_first_symbols<'e'>(begin, end), begin + 1);
ASSERT_EQ(find_first_symbols<'.'>(begin, end), begin + 21);
ASSERT_EQ(find_first_symbols<' '>(begin, end), begin + 6);
ASSERT_EQ(find_first_symbols<'H'>(begin, end), begin);
ASSERT_EQ((find_first_symbols<'a', 'e'>(begin, end)), begin + 1);
ASSERT_EQ(find_last_symbols_or_null<'a'>(begin, end), nullptr);
ASSERT_EQ(find_last_symbols_or_null<'e'>(begin, end), end - 4);
ASSERT_EQ(find_last_symbols_or_null<'.'>(begin, end), end - 1);
ASSERT_EQ(find_last_symbols_or_null<' '>(begin, end), end - 11);
ASSERT_EQ(find_last_symbols_or_null<'H'>(begin, end), begin);
ASSERT_EQ((find_last_symbols_or_null<'a', 'e'>(begin, end)), end - 4);
2020-03-21 02:52:37 +00:00
{
std::vector<std::string> vals;
splitInto<' ', ','>(vals, "hello, world", true);
ASSERT_EQ(vals, (std::vector<std::string>{"hello", "world"}));
}
{
std::vector<std::string> vals;
splitInto<' ', ','>(vals, "s String", true);
ASSERT_EQ(vals, (std::vector<std::string>{"s", "String"}));
}
}