From f51ba6089c53f07fdbfb9e89ebf0c44f8e44936b Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 17 May 2016 19:39:55 +0100 Subject: [PATCH] Use variadic macros for kak_assert to remove the need for COMMA --- src/assert.hh | 9 ++++----- src/buffer.cc | 8 ++++---- src/line_modification.cc | 12 ++++++------ src/ncurses_ui.cc | 2 +- src/selectors.cc | 18 +++++++++--------- src/word_db.cc | 6 +++--- 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/assert.hh b/src/assert.hh index 16501e4c..4d6c3782 100644 --- a/src/assert.hh +++ b/src/assert.hh @@ -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 diff --git a/src/buffer.cc b/src/buffer.cc index 3ad10fe5..a5b72246 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -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(); diff --git a/src/line_modification.cc b/src/line_modification.cc index d9ebcab8..3d6617dd 100644 --- a/src/line_modification.cc +++ b/src/line_modification.cc @@ -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 }); } }}; diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index eec9f863..94c733cc 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -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; diff --git a/src/selectors.cc b/src/selectors.cc index b240e7a7..d4725c5e 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -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); } }}; diff --git a/src/word_db.cc b/src/word_db.cc index 2e9581cb..f7ff11da 100644 --- a/src/word_db.cc +++ b/src/word_db.cc @@ -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" })); }}; }