def test_cursor_position(): screen = Screen(10, 10) # a) testing that we expect 1-indexed values screen.cursor_position(5, 10) assert (screen.cursor.y, screen.cursor.x) == (4, 9) # b) but (0, 0) is also accepted and should be the same as (1, 1) screen.cursor_position(0, 10) assert (screen.cursor.y, screen.cursor.x) == (0, 9) # c) moving outside the margins constrains to within the screen # bounds screen.cursor_position(100, 5) assert (screen.cursor.y, screen.cursor.x) == (9, 4) screen.cursor_position(5, 100) assert (screen.cursor.y, screen.cursor.x) == (4, 9) # d) DECOM on screen.set_margins(5, 9) screen.set_mode(mo.DECOM) screen.cursor_position() assert (screen.cursor.y, screen.cursor.x) == (4, 0) screen.cursor_position(2, 0) assert (screen.cursor.y, screen.cursor.x) == (5, 0) # Note that cursor position doesn't change. screen.cursor_position(10, 0) assert (screen.cursor.y, screen.cursor.x) == (5, 0)
def test_resize(): screen = Screen(2, 2) screen.set_mode(mo.DECOM) screen.set_margins(0, 1) assert screen.size == (2, 2) assert len(screen) == 2 assert len(screen[0]) == 2 assert screen == [[screen.default_char, screen.default_char]] * 2 screen.resize(3, 3) assert screen.size == (3, 3) assert len(screen) == 3 assert len(screen[0]) == 3 assert screen == [[screen.default_char, screen.default_char, screen.default_char]] * 3 assert mo.DECOM not in screen.mode assert screen.margins == (0, 2) screen.resize(2, 2) assert screen.size == (2, 2) assert len(screen) == 2 assert len(screen[0]) == 2 assert screen == [[screen.default_char, screen.default_char]] * 2 # quirks: # a) if the current display is thinner than the requested size, # new columns should be added to the right. screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(2, 3) assert screen.display == ["bo ", "sh "] # b) if the current display is wider than the requested size, # columns should be removed from the right... screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(2, 1) assert screen.display == ["b", "s"] # c) if the current display is shorter than the requested # size, new rows should be added on the bottom. screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(3, 2) assert screen.display == ["bo", "sh", " "] # d) if the current display is taller than the requested # size, rows should be removed from the top. screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(1, 2) assert screen.display == ["sh"]
def test_resize(): screen = Screen(2, 2) screen.set_mode(mo.DECOM) screen.set_margins(0, 1) assert screen.size == (2, 2) assert len(screen) == 2 assert len(screen[0]) == 2 assert screen == [[screen.default_char, screen.default_char]] * 2 screen.resize(3, 3) assert screen.size == (3, 3) assert len(screen) == 3 assert len(screen[0]) == 3 assert screen == [[ screen.default_char, screen.default_char, screen.default_char ]] * 3 assert mo.DECOM not in screen.mode assert screen.margins == (0, 2) screen.resize(2, 2) assert screen.size == (2, 2) assert len(screen) == 2 assert len(screen[0]) == 2 assert screen == [[screen.default_char, screen.default_char]] * 2 # quirks: # a) if the current display is thinner than the requested size, # new columns should be added to the right. screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(2, 3) assert screen.display == ["bo ", "sh "] # b) if the current display is wider than the requested size, # columns should be removed from the right... screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(2, 1) assert screen.display == ["b", "s"] # c) if the current display is shorter than the requested # size, new rows should be added on the bottom. screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(3, 2) assert screen.display == ["bo", "sh", " "] # d) if the current display is taller than the requested # size, rows should be removed from the top. screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(1, 2) assert screen.display == ["sh"]
def test_restore_cursor_out_of_bounds(): screen = Screen(10, 10) # a) origin mode off. screen.cursor_position(5, 5) screen.save_cursor() screen.resize(3, 3) screen.reset() screen.restore_cursor() assert (screen.cursor.y, screen.cursor.x) == (2, 2) # b) origin mode is on. screen.resize(10, 10) screen.cursor_position(8, 8) screen.save_cursor() screen.resize(5, 5) screen.reset() screen.set_mode(mo.DECOM) screen.set_margins(2, 3) screen.restore_cursor() assert (screen.cursor.y, screen.cursor.x) == (2, 4)
def test_set_margins(): screen = Screen(10, 10) assert screen.margins == (0, 9) # a) ok-case screen.set_margins(1, 5) assert screen.margins == (0, 4) # b) one of the margins is out of bounds screen.set_margins(100, 10) assert screen.margins != (99, 9) assert screen.margins == (0, 4) # c) no margins provided screen.set_margins() assert screen.margins != (None, None) assert screen.margins == (0, 4)