#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 expected) { kak_assert(std::equal(container.begin(), container.end(), expected.begin(), expected.end())); }; check_equal("a,b,c"_sv | split(','), {"a", "b", "c"}); check_equal(",b,c"_sv | split(','), {"", "b", "c"}); check_equal(",b,"_sv | split(','), {"", "b", ""}); check_equal(","_sv | split(','), {"", ""}); check_equal(""_sv | split(','), {}); check_equal("a,b,c,"_sv | split_after(','), {"a,", "b,", "c,"}); check_equal("a,b,c"_sv | split_after(','), {"a,", "b,", "c"}); check_equal(R"(a\,,\,b,\,)"_sv | split(',', '\\') | transform(unescape<',', '\\'>), {"a,", ",b", ","}); check_equal(R"(\,\,)"_sv | split(',', '\\') | transform(unescape<',', '\\'>), {",,"}); check_equal(R"(\\,\\,)"_sv | split(',', '\\') | transform(unescape<',', '\\'>), {R"(\)", R"(\)", ""}); }}; }