kakoune/src/assert.hh
Tim Allen 50e422659b Add support for the shift modifier.
Because keyboard layouts vary, the shift-modifier `<s-…>` is only supported
for special keys (like `<up>` and `<home>`) and for ASCII lowercase where
we assume the shift-modifier just produces the matching uppercase character.
Even that's not universally true, since in Turkish `i` and `I` are not an
uppercase/lowercase pair, but Kakoune's default keyboard mappings already
assume en-US mappings for mnemonic purposes.

Mappings of the form `<s-x>` are normalized to `<X>` when `x` is an ASCII
character. `<backtab>` is removed, since we can now say `<s-tab>`.
2018-04-11 15:15:45 +10:00

39 lines
1.0 KiB
C++

#ifndef assert_hh_INCLUDED
#define assert_hh_INCLUDED
namespace Kakoune
{
class StringView;
// return true if user asked to ignore the error
bool notify_fatal_error(StringView message);
void on_assert_failed(const char* message);
}
#define STRINGIFY(X) #X
#define TOSTRING(X) STRINGIFY(X)
#ifdef KAK_DEBUG
#define kak_assert(...) do { \
if (not (__VA_ARGS__)) \
on_assert_failed("assert failed \"" #__VA_ARGS__ \
"\" at " __FILE__ ":" TOSTRING(__LINE__)); \
} while (false)
#define kak_expect_throw(exception_type, ...) try {\
__VA_ARGS__; \
on_assert_failed("expression \"" #__VA_ARGS__ \
"\" did not throw \"" #exception_type \
"\" at " __FILE__ ":" TOSTRING(__LINE__)); \
} catch (exception_type &err) {}
#else
#define kak_assert(...) do { (void)sizeof(__VA_ARGS__); } while(false)
#define kak_expect_throw(_, ...) do { (void)sizeof(__VA_ARGS__); } while(false)
#endif
#endif // assert_hh_INCLUDED