Use variadic macros for kak_assert to remove the need for COMMA
This commit is contained in:
parent
3b6d6956e2
commit
f51ba6089c
|
@ -15,15 +15,14 @@ void on_assert_failed(const char* message);
|
|||
|
||||
#define STRINGIFY(X) #X
|
||||
#define TOSTRING(X) STRINGIFY(X)
|
||||
#define COMMA ,
|
||||
|
||||
#ifdef KAK_DEBUG
|
||||
#define kak_assert(condition) \
|
||||
if (not (condition)) \
|
||||
on_assert_failed("assert failed \"" #condition \
|
||||
#define kak_assert(...) \
|
||||
if (not (__VA_ARGS__)) \
|
||||
on_assert_failed("assert failed \"" #__VA_ARGS__ \
|
||||
"\" at " __FILE__ ":" TOSTRING(__LINE__))
|
||||
#else
|
||||
#define kak_assert(condition)
|
||||
#define kak_assert(...)
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -639,13 +639,13 @@ UnitTest test_buffer{[]()
|
|||
BufferIterator pos = buffer.begin();
|
||||
kak_assert(*pos == 'a');
|
||||
pos += 6;
|
||||
kak_assert(pos.coord() == ByteCoord{0 COMMA 6});
|
||||
kak_assert(pos.coord() == ByteCoord{0, 6});
|
||||
++pos;
|
||||
kak_assert(pos.coord() == ByteCoord{1 COMMA 0});
|
||||
kak_assert(pos.coord() == ByteCoord{1, 0});
|
||||
--pos;
|
||||
kak_assert(pos.coord() == ByteCoord{0 COMMA 6});
|
||||
kak_assert(pos.coord() == ByteCoord{0, 6});
|
||||
pos += 1;
|
||||
kak_assert(pos.coord() == ByteCoord{1 COMMA 0});
|
||||
kak_assert(pos.coord() == ByteCoord{1, 0});
|
||||
buffer.insert(pos.coord(), "tchou kanaky\n");
|
||||
kak_assert(buffer.line_count() == 5);
|
||||
BufferIterator pos2 = buffer.end();
|
||||
|
|
|
@ -110,7 +110,7 @@ UnitTest test_line_modifications{[]()
|
|||
buffer.erase({1, 0}, {2, 0});
|
||||
|
||||
auto modifs = compute_line_modifications(buffer, ts);
|
||||
kak_assert(modifs.size() == 1 and modifs[0] == LineModification{ 1 COMMA 1 COMMA 1 COMMA 0 });
|
||||
kak_assert(modifs.size() == 1 and modifs[0] == LineModification{ 1, 1, 1, 0 });
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -119,7 +119,7 @@ UnitTest test_line_modifications{[]()
|
|||
buffer.insert({1, 7}, "line 3");
|
||||
|
||||
auto modifs = compute_line_modifications(buffer, ts);
|
||||
kak_assert(modifs.size() == 1 and modifs[0] == LineModification{ 2 COMMA 2 COMMA 0 COMMA 1 });
|
||||
kak_assert(modifs.size() == 1 and modifs[0] == LineModification{ 2, 2, 0, 1 });
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -130,7 +130,7 @@ UnitTest test_line_modifications{[]()
|
|||
buffer.erase({0, 0}, {1, 0});
|
||||
|
||||
auto modifs = compute_line_modifications(buffer, ts);
|
||||
kak_assert(modifs.size() == 1 and modifs[0] == LineModification{ 0 COMMA 0 COMMA 2 COMMA 2 });
|
||||
kak_assert(modifs.size() == 1 and modifs[0] == LineModification{ 0, 0, 2, 2 });
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -142,13 +142,13 @@ UnitTest test_line_modifications{[]()
|
|||
buffer.erase({0,0}, {1,0});
|
||||
{
|
||||
auto modifs = compute_line_modifications(buffer, ts);
|
||||
kak_assert(modifs.size() == 1 and modifs[0] == LineModification{ 0 COMMA 0 COMMA 4 COMMA 3 });
|
||||
kak_assert(modifs.size() == 1 and modifs[0] == LineModification{ 0, 0, 4, 3 });
|
||||
}
|
||||
buffer.insert({3,0}, "newline 4\n");
|
||||
|
||||
{
|
||||
auto modifs = compute_line_modifications(buffer, ts);
|
||||
kak_assert(modifs.size() == 1 and modifs[0] == LineModification{ 0 COMMA 0 COMMA 4 COMMA 4 });
|
||||
kak_assert(modifs.size() == 1 and modifs[0] == LineModification{ 0, 0, 4, 4 });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ UnitTest test_line_modifications{[]()
|
|||
buffer.insert({0,1}, "e");
|
||||
buffer.insert({0,2}, "w");
|
||||
auto modifs = compute_line_modifications(buffer, ts);
|
||||
kak_assert(modifs.size() == 1 and modifs[0] == LineModification{ 0 COMMA 0 COMMA 1 COMMA 1 });
|
||||
kak_assert(modifs.size() == 1 and modifs[0] == LineModification{ 0, 0, 1, 1 });
|
||||
}
|
||||
}};
|
||||
|
||||
|
|
|
@ -611,7 +611,7 @@ void NCursesUI::draw_menu()
|
|||
draw_line(m_menu.win, item, 0, column_width,
|
||||
item_idx == m_menu.selected_item ? m_menu.fg : m_menu.bg);
|
||||
const CharCount pad = column_width - item.length();
|
||||
add_str(m_menu.win, String{' ' COMMA pad});
|
||||
add_str(m_menu.win, String{' ', pad});
|
||||
}
|
||||
const bool is_mark = line >= mark_line and
|
||||
line < mark_line + mark_height;
|
||||
|
|
|
@ -693,41 +693,41 @@ UnitTest test_find_surrounding{[]()
|
|||
{
|
||||
auto res = find_surrounding(s, s.begin() + 10, '{', '}',
|
||||
ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0);
|
||||
kak_assert(res and StringView{res->first COMMA res->second+1} == "{ toi[] }");
|
||||
kak_assert(res and StringView{res->first, res->second+1} == "{ toi[] }");
|
||||
}
|
||||
{
|
||||
auto res = find_surrounding(s, s.begin() + 10, '[', ']',
|
||||
ObjectFlags::ToBegin | ObjectFlags::ToEnd | ObjectFlags::Inner, 0);
|
||||
kak_assert(res and StringView{res->first COMMA res->second+1} == "salut { toi[] }");
|
||||
kak_assert(res and StringView{res->first, res->second+1} == "salut { toi[] }");
|
||||
}
|
||||
{
|
||||
auto res = find_surrounding(s, s.begin(), '[', ']',
|
||||
ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0);
|
||||
kak_assert(res and StringView{res->first COMMA res->second+1} == "[salut { toi[] }]");
|
||||
kak_assert(res and StringView{res->first, res->second+1} == "[salut { toi[] }]");
|
||||
}
|
||||
{
|
||||
auto res = find_surrounding(s, s.begin()+7, '{', '}',
|
||||
ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0);
|
||||
kak_assert(res and StringView{res->first COMMA res->second+1} == "{ toi[] }");
|
||||
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 COMMA res->second+1} == "]");
|
||||
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 COMMA res->second+1} == "[salut { toi[] }]");
|
||||
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 COMMA res->first+1} == "[s");
|
||||
kak_assert(res and StringView{res->second, res->first+1} == "[s");
|
||||
}
|
||||
s = "[]";
|
||||
{
|
||||
auto res = find_surrounding(s, s.begin() + 1, '[', ']', ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0);
|
||||
kak_assert(res and StringView{res->first COMMA res->second+1} == "[]");
|
||||
kak_assert(res and StringView{res->first, res->second+1} == "[]");
|
||||
}
|
||||
s = "[*][] hehe";
|
||||
{
|
||||
|
@ -738,7 +738,7 @@ UnitTest test_find_surrounding{[]()
|
|||
{
|
||||
auto res = find_surrounding(s, s.begin() + 6, "begin", "end",
|
||||
ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0);
|
||||
kak_assert(res and StringView{res->first COMMA res->second+1} == s);
|
||||
kak_assert(res and StringView{res->first, res->second+1} == s);
|
||||
}
|
||||
}};
|
||||
|
||||
|
|
|
@ -163,17 +163,17 @@ UnitTest test_word_db{[]()
|
|||
WordDB word_db(buffer);
|
||||
auto res = word_db.find_matching("");
|
||||
std::sort(res.begin(), res.end(), cmp_words);
|
||||
kak_assert(eq(res, WordList{ "allo" COMMA "kanaky" COMMA "mutch" COMMA "tchaa" COMMA "tchou" }));
|
||||
kak_assert(eq(res, WordList{ "allo", "kanaky", "mutch", "tchaa", "tchou" }));
|
||||
kak_assert(word_db.get_word_occurences("tchou") == 3);
|
||||
kak_assert(word_db.get_word_occurences("allo") == 1);
|
||||
buffer.erase({1, 6}, {4, 0});
|
||||
res = word_db.find_matching("");
|
||||
std::sort(res.begin(), res.end(), cmp_words);
|
||||
kak_assert(eq(res, WordList{ "allo" COMMA "mutch" COMMA "tchou" }));
|
||||
kak_assert(eq(res, WordList{ "allo", "mutch", "tchou" }));
|
||||
buffer.insert({1, 0}, "re");
|
||||
res = word_db.find_matching("");
|
||||
std::sort(res.begin(), res.end(), cmp_words);
|
||||
kak_assert(eq(res, WordList{ "allo" COMMA "mutch" COMMA "retchou" COMMA "tchou" }));
|
||||
kak_assert(eq(res, WordList{ "allo", "mutch", "retchou", "tchou" }));
|
||||
}};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user