From 44a8cc062ec269dc28452e7f8c8f7e7de5383851 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 14 Nov 2016 20:40:54 +0530 Subject: [PATCH] Add testing for command dumping as well --- kitty/parser.c | 3 ++- kitty_tests/parser.py | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/kitty/parser.c b/kitty/parser.c index 4381edddc..0c84c823c 100644 --- a/kitty/parser.c +++ b/kitty/parser.c @@ -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 diff --git a/kitty_tests/parser.py b/kitty_tests/parser.py index 270476ebf..0c3ed7c7c 100644 --- a/kitty_tests/parser.py +++ b/kitty_tests/parser.py @@ -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 @@ class TestScreen(BaseTest): 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)), 'ニチ ')