2017-12-06 18:58:19 +01:00
|
|
|
#include "ranges.hh"
|
|
|
|
#include "unit_tests.hh"
|
|
|
|
#include "string.hh"
|
|
|
|
#include "string_utils.hh"
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
UnitTest test_ranges{[] {
|
|
|
|
auto check_equal = [](auto&& container, ConstArrayView<StringView> expected) {
|
|
|
|
kak_assert(std::equal(container.begin(), container.end(), expected.begin(), expected.end()));
|
|
|
|
};
|
|
|
|
check_equal("a,b,c"_sv | split<StringView>(','), {"a", "b", "c"});
|
|
|
|
check_equal(",b,c"_sv | split<StringView>(','), {"", "b", "c"});
|
|
|
|
check_equal(",b,"_sv | split<StringView>(','), {"", "b", ""});
|
|
|
|
check_equal(","_sv | split<StringView>(','), {"", ""});
|
|
|
|
check_equal(""_sv | split<StringView>(','), {});
|
|
|
|
|
2019-01-22 11:04:29 +01:00
|
|
|
check_equal("a,b,c,"_sv | split_after<StringView>(','), {"a,", "b,", "c,"});
|
|
|
|
check_equal("a,b,c"_sv | split_after<StringView>(','), {"a,", "b,", "c"});
|
|
|
|
|
2017-12-06 18:58:19 +01:00
|
|
|
check_equal(R"(a\,,\,b,\,)"_sv | split<StringView>(',', '\\')
|
|
|
|
| transform(unescape<',', '\\'>), {"a,", ",b", ","});
|
|
|
|
check_equal(R"(\,\,)"_sv | split<StringView>(',', '\\')
|
|
|
|
| transform(unescape<',', '\\'>), {",,"});
|
|
|
|
check_equal(R"(\\,\\,)"_sv | split<StringView>(',', '\\')
|
|
|
|
| transform(unescape<',', '\\'>), {R"(\)", R"(\)", ""});
|
|
|
|
}};
|
|
|
|
|
|
|
|
}
|