Refactor surround unit test code

This commit is contained in:
Maxime Coste 2017-03-04 17:43:24 +00:00
parent 2bcfd51bc4
commit 887232987c

View File

@ -969,56 +969,30 @@ void split_selections(SelectionList& selections, const Regex& regex, int capture
UnitTest test_find_surrounding{[]() UnitTest test_find_surrounding{[]()
{ {
StringView s("[salut { toi[] }]"); StringView s("[salut { toi[] }]");
{ auto check_equal = [&](const char* pos, StringView opening, StringView closing,
auto res = find_surrounding(s, s.begin() + 10, '{', '}', ObjectFlags flags, int init_level, StringView expected) {
ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0); auto res = find_surrounding(s, pos, opening, closing, flags, init_level);
kak_assert(res and StringView{res->first, res->second+1} == "{ toi[] }"); auto min = std::min(res->first, res->second),
} max = std::max(res->first, res->second);
{ kak_assert(res and StringView{min, max+1} == expected);
auto res = find_surrounding(s, s.begin() + 10, '[', ']', };
ObjectFlags::ToBegin | ObjectFlags::ToEnd | ObjectFlags::Inner, 0);
kak_assert(res and StringView{res->first, res->second+1} == "salut { toi[] }"); check_equal(s.begin() + 10, '{', '}', ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0, "{ toi[] }");
} check_equal(s.begin() + 10, '[', ']', ObjectFlags::ToBegin | ObjectFlags::ToEnd | ObjectFlags::Inner, 0, "salut { toi[] }");
{ check_equal(s.begin(), '[', ']', ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0, "[salut { toi[] }]");
auto res = find_surrounding(s, s.begin(), '[', ']', check_equal(s.begin()+7, '{', '}', ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0, "{ toi[] }");
ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0); check_equal(s.begin() + 12, '[', ']', ObjectFlags::ToBegin | ObjectFlags::ToEnd | ObjectFlags::Inner, 0, "]");
kak_assert(res and StringView{res->first, res->second+1} == "[salut { toi[] }]"); check_equal(s.begin() + 14, '[', ']', ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0, "[salut { toi[] }]");
} check_equal(s.begin() + 1, '[', ']', ObjectFlags::ToBegin, 0, "[s");
{
auto res = find_surrounding(s, s.begin()+7, '{', '}',
ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0);
kak_assert(res and StringView{res->first, res->second+1} == "{ toi[] }");
}
{
auto res = find_surrounding(s, s.begin() + 12, '[', ']',
ObjectFlags::ToBegin | ObjectFlags::ToEnd | ObjectFlags::Inner, 0);
kak_assert(res and StringView{res->first, res->second+1} == "]");
}
{
auto res = find_surrounding(s, s.begin() + 14, '[', ']',
ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0);
kak_assert(res and StringView{res->first, res->second+1} == "[salut { toi[] }]");
}
{
auto res = find_surrounding(s, s.begin() + 1, '[', ']', ObjectFlags::ToBegin, 0);
kak_assert(res and StringView{res->second, res->first+1} == "[s");
}
s = "[]"; s = "[]";
{ check_equal(s.begin() + 1, '[', ']', ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0, "[]");
auto res = find_surrounding(s, s.begin() + 1, '[', ']', ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0);
kak_assert(res and StringView{res->first, res->second+1} == "[]");
}
s = "[*][] hehe"; s = "[*][] hehe";
{ kak_assert(not find_surrounding(s, s.begin() + 6, '[', ']', ObjectFlags::ToBegin, 0));
auto res = find_surrounding(s, s.begin() + 6, '[', ']', ObjectFlags::ToBegin, 0);
kak_assert(not res);
}
s = "begin tchou begin tchaa end end"; s = "begin tchou begin tchaa end end";
{ check_equal(s.begin() + 6, "begin", "end", ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0, s);
auto res = find_surrounding(s, s.begin() + 6, "begin", "end",
ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0);
kak_assert(res and StringView{res->first, res->second+1} == s);
}
}}; }};
} }