Start migrating the tests

This commit is contained in:
Kovid Goyal 2016-11-23 15:47:22 +05:30
parent f14e7037e2
commit cdd58207a3
2 changed files with 19 additions and 10 deletions

View File

@ -56,7 +56,7 @@ static void _report_error(PyObject *dump_callback, const char *fmt, ...) {
// Normal mode {{{ // Normal mode {{{
static inline void static inline void
handle_normal_mode_char(Screen *screen, uint32_t ch, PyObject DUMP_UNUSED *dump_callback) { handle_normal_mode_char(Screen *screen, uint32_t ch, PyObject DUMP_UNUSED *dump_callback) {
#define CALL_SCREEN_HANDLER(name) REPORT_COMMAND(#name, ch); name(screen); break; #define CALL_SCREEN_HANDLER(name) REPORT_COMMAND(name, ch); name(screen); break;
switch(ch) { switch(ch) {
case BEL: case BEL:
CALL_SCREEN_HANDLER(screen_bell); CALL_SCREEN_HANDLER(screen_bell);
@ -67,6 +67,7 @@ handle_normal_mode_char(Screen *screen, uint32_t ch, PyObject DUMP_UNUSED *dump_
case LF: case LF:
case VT: case VT:
case FF: case FF:
case NEL:
CALL_SCREEN_HANDLER(screen_linefeed); CALL_SCREEN_HANDLER(screen_linefeed);
case CR: case CR:
CALL_SCREEN_HANDLER(screen_carriage_return); CALL_SCREEN_HANDLER(screen_carriage_return);
@ -78,8 +79,6 @@ handle_normal_mode_char(Screen *screen, uint32_t ch, PyObject DUMP_UNUSED *dump_
CALL_SCREEN_HANDLER(screen_index); CALL_SCREEN_HANDLER(screen_index);
case RI: case RI:
CALL_SCREEN_HANDLER(screen_reverse_index); CALL_SCREEN_HANDLER(screen_reverse_index);
case NEL:
CALL_SCREEN_HANDLER(screen_linefeed);
case HTS: case HTS:
CALL_SCREEN_HANDLER(screen_set_tab_stop); CALL_SCREEN_HANDLER(screen_set_tab_stop);
case ESC: case ESC:

View File

@ -42,11 +42,21 @@ class TestParser(BaseTest):
cd = CmdDump() cd = CmdDump()
if isinstance(x, str): if isinstance(x, str):
x = x.encode('utf-8') x = x.encode('utf-8')
if isinstance(s, str): cmds = tuple(('draw', x) if isinstance(x, str) else x for x in cmds)
s = s.encode('utf-8')
cmds = tuple(('draw', x.encode('utf-8')) if isinstance(x, str) else x for x in cmds)
parse_bytes_dump(cd, s, x) parse_bytes_dump(cd, s, x)
self.ae(tuple(cd), cmds) current = ''
q = []
for args in cd:
if args[0] == 'draw':
current += args[1]
else:
if current:
q.append(('draw', current))
current = ''
q.append(args)
if current:
q.append(('draw', current))
self.ae(tuple(q), cmds)
def test_simple_parsing(self): def test_simple_parsing(self):
s = self.create_screen() s = self.create_screen()
@ -72,11 +82,11 @@ class TestParser(BaseTest):
def test_esc_codes(self): def test_esc_codes(self):
s = self.create_screen() s = self.create_screen()
pb = partial(self.parse_bytes_dump, s) pb = partial(self.parse_bytes_dump, s)
pb('12\033Da', '12', ('screen_index',), 'a') pb('12\033Da', '12', ('screen_index', ord('D')), 'a')
self.ae(str(s.line(0)), '12 ') self.ae(str(s.line(0)), '12 ')
self.ae(str(s.line(1)), ' a ') self.ae(str(s.line(1)), ' a ')
pb('\033x', ('Unknown char in escape_dispatch: %d' % ord('x'),)) pb('\033x', ('Unknown char after ESC: 0x%x' % ord('x'),))
pb('\033c123', ('screen_reset',), '123') pb('\033c123', ('screen_reset', ord('c')), '123')
self.ae(str(s.line(0)), '123 ') self.ae(str(s.line(0)), '123 ')
def test_csi_codes(self): def test_csi_codes(self):