From 4238fedee7b79292981dd3e462b8e8d72f139e3f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 11 Jan 2024 12:29:00 +0530 Subject: [PATCH] More tests --- kitty/simd-string-impl.h | 3 ++- kitty_tests/parser.py | 29 ++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/kitty/simd-string-impl.h b/kitty/simd-string-impl.h index 46f89198e..b6ba3976d 100644 --- a/kitty/simd-string-impl.h +++ b/kitty/simd-string-impl.h @@ -157,7 +157,8 @@ static inline integer_t shuffle_impl256(const integer_t value, const integer_t s #define shuffle_epi8 shuffle_impl256 #define sum_bytes(x) (sum_bytes_128(simde_mm256_extracti128_si256(x, 0)) + sum_bytes_128(simde_mm256_extracti128_si256(x, 1))) #endif -#if 1 + +#if 0 #define print_register_as_bytes(r) { \ printf("%s:\n", #r); \ alignas(64) uint8_t data[sizeof(r)]; \ diff --git a/kitty_tests/parser.py b/kitty_tests/parser.py index 456f0f5cc..d07a3935a 100644 --- a/kitty_tests/parser.py +++ b/kitty_tests/parser.py @@ -184,9 +184,27 @@ class TestParser(BaseTest): def reset_state(): test_utf8_decode_to_sentinel(b'', -1) - def t(x, which=2): - expected = test_utf8_decode_to_sentinel(x, 1) - actual = test_utf8_decode_to_sentinel(x, which) + def asbytes(x): + if isinstance(x, str): + x = x.encode() + return x + + def t(*a, which=2): + + def parse_parts(which): + esc_found = False + parts = [] + for x in a: + found_sentinel, x = test_utf8_decode_to_sentinel(asbytes(x), which) + if found_sentinel: + esc_found = found_sentinel + parts.append(x) + return esc_found, ''.join(parts) + + reset_state() + actual = parse_parts(1) + reset_state() + expected = parse_parts(which) self.ae(expected, actual, msg=f'Failed for {x!r} with {which=}\n{expected!r} !=\n{actual!r}') def double_test(x): @@ -197,11 +215,16 @@ class TestParser(BaseTest): x = double_test x('2:α3') + x('2:α\x1b3') x('2:α3:≤4:😸|') x('abcd1234efgh5678') x('abc\x1bd1234efgh5678') x('abcd1234efgh5678ijklABCDmnopEFGH') + for which in (2, 3): + t('abcdef', 'ghij') + t('2:α3', ':≤4:😸|') + def test_esc_codes(self): s = self.create_screen() pb = partial(self.parse_bytes_dump, s)