Add tests for ch_and_idx

This commit is contained in:
Kovid Goyal 2024-12-19 05:21:18 +05:30
parent 72d88e75aa
commit f67c58034c
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 23 additions and 2 deletions

View file

@ -9,7 +9,6 @@
#include "text-cache.h"
// TODO: Test setting of ch_and_idx to make sure the right ch_is_idx bit is set
// TODO: Test multiple OS windows with decorations also with changing font size and test on macOS and Linux for re-alloc
// TODO: Test handling of calt ligatures with scale see is_group_calt_ligature()
// TODO: Handle selection with multicell

View file

@ -5260,6 +5260,20 @@ cpu_cells(Screen *self, PyObject *args) {
return Py_NewRef(ans);
}
static PyObject*
test_ch_and_idx(PyObject *self UNUSED, PyObject *val) {
CPUCell c = {0};
if (PyLong_Check(val)) {
unsigned long x = PyLong_AsUnsignedLong(val);
c.ch_and_idx = x;
} else if (PyTuple_Check(val)) {
c.ch_is_idx = PyLong_AsUnsignedLong(PyTuple_GET_ITEM(val, 0));
c.ch_or_idx = PyLong_AsUnsignedLong(PyTuple_GET_ITEM(val, 1));
}
unsigned long is_idx = c.ch_is_idx, idx = c.ch_or_idx, ca = c.ch_and_idx;
return Py_BuildValue("kkk", is_idx, idx, ca);
}
static PyMethodDef methods[] = {
METHODB(test_create_write_buffer, METH_NOARGS),
METHODB(test_commit_write_buffer, METH_VARARGS),
@ -5411,6 +5425,7 @@ PyTypeObject Screen_Type = {
static PyMethodDef module_methods[] = {
{"is_emoji_presentation_base", (PyCFunction)screen_is_emoji_presentation_base, METH_O, ""},
{"truncate_point_for_length", (PyCFunction)screen_truncate_point_for_length, METH_VARARGS, ""},
{"test_ch_and_idx", test_ch_and_idx, METH_O, ""},
{NULL} /* Sentinel */
};

View file

@ -2,7 +2,7 @@
# License: GPLv3 Copyright: 2024, Kovid Goyal <kovid at kovidgoyal.net>
from kitty.fast_data_types import TEXT_SIZE_CODE, wcswidth
from kitty.fast_data_types import TEXT_SIZE_CODE, wcswidth, test_ch_and_idx
from . import BaseTest, parse_bytes
from . import draw_multicell as multicell
@ -37,6 +37,13 @@ def test_multicell(self: TestMulticell) -> None:
if assertions[key] != val:
raise AssertionError(f'{msg}{assertions[key]!r} != {val!r}')
self.ae(test_ch_and_idx(0), (0, 0, 0))
self.ae(test_ch_and_idx(1), (0, 1, 1))
self.ae(test_ch_and_idx(0x80000000), (1, 0, 0x80000000))
self.ae(test_ch_and_idx(0x80000001), (1, 1, 0x80000001))
self.ae(test_ch_and_idx((1, 0)), (1, 0, 0x80000000))
self.ae(test_ch_and_idx((1, 3)), (1, 3, 0x80000003))
ae('x')
ae('y')
ae('width')