Add testing for command dumping as well
This commit is contained in:
parent
5069b50fb2
commit
44a8cc062e
2 changed files with 21 additions and 6 deletions
|
|
@ -118,7 +118,8 @@ parse_bytes(PyObject UNUSED *self, PyObject *args) {
|
|||
Py_buffer pybuf;
|
||||
Screen *screen;
|
||||
#ifdef DUMP_COMMANDS
|
||||
if (!PyArg_ParseTuple(args, "OO!y*", &dump_callback, &Screen_Type, &screen, &pybuf)) return NULL;
|
||||
if (!PyArg_ParseTuple(args, "O!y*O", &Screen_Type, &screen, &pybuf, &dump_callback)) return NULL;
|
||||
if (!PyCallable_Check(dump_callback)) { PyErr_SetString(PyExc_TypeError, "The dump callback must be a callable object"); return NULL; }
|
||||
#else
|
||||
if (!PyArg_ParseTuple(args, "O!y*", &Screen_Type, &screen, &pybuf)) return NULL;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -4,19 +4,33 @@
|
|||
|
||||
from . import BaseTest
|
||||
|
||||
from kitty.fast_data_types import parse_bytes
|
||||
from kitty.fast_data_types import parse_bytes, parse_bytes_dump
|
||||
|
||||
|
||||
class CmdDump(list):
|
||||
|
||||
def __call__(self, *a):
|
||||
self.append(a)
|
||||
|
||||
|
||||
class TestScreen(BaseTest):
|
||||
|
||||
def test_simple_parsing(self):
|
||||
s = self.create_screen()
|
||||
parse_bytes(s, b'12')
|
||||
|
||||
def pb(x, *cmds):
|
||||
cd = CmdDump()
|
||||
if isinstance(x, str):
|
||||
x = x.encode('utf-8')
|
||||
parse_bytes_dump(s, x, cd)
|
||||
self.ae(tuple(cd), cmds)
|
||||
|
||||
pb('12')
|
||||
self.ae(str(s.line(0)), '12 ')
|
||||
parse_bytes(s, b'3456')
|
||||
pb('3456')
|
||||
self.ae(str(s.line(0)), '12345')
|
||||
self.ae(str(s.line(1)), '6 ')
|
||||
parse_bytes(s, b'\n123\n\r45')
|
||||
pb(b'\n123\n\r45', ('linefeed', '\n'), ('linefeed', '\n'), ('carriage_return', '\r'))
|
||||
self.ae(str(s.line(1)), '6 ')
|
||||
self.ae(str(s.line(2)), ' 123 ')
|
||||
self.ae(str(s.line(3)), '45 ')
|
||||
|
|
@ -24,5 +38,5 @@ def test_simple_parsing(self):
|
|||
self.ae(str(s.line(3)), 'abcde')
|
||||
parse_bytes(s, '\rßxyz1'.encode('utf-8'))
|
||||
self.ae(str(s.line(3)), 'ßxyz1')
|
||||
parse_bytes(s, 'ニチ '.encode('utf-8'))
|
||||
pb('ニチ '.encode('utf-8'))
|
||||
self.ae(str(s.line(4)), 'ニチ ')
|
||||
|
|
|
|||
Loading…
Reference in a new issue