def test_get_surrounding_lines(self): SRC = SourceString('hello\nworld\nthis\nis\na\ntest') lines = [str(x) for x in SRC.get_surrounding_lines()] assert lines == ['1 |hello\n', '2 |world\n'] lines = ''.join([repr(x) for x in SRC.get_surrounding_lines()]) assert lines == 'hello\nworld\n' SRC.eat_string('hello\nworld\n') lines = [str(x) for x in SRC.get_surrounding_lines()] assert lines == ['2 |world\n', '3 |this\n', '4 |is\n'] lines = ''.join([repr(x) for x in SRC.get_surrounding_lines()]) assert lines == 'world\nthis\nis\n' lines = [str(x) for x in SRC.get_surrounding_lines(1, 0)] assert lines == ['2 |world\n', '3 |this\n'] lines = ''.join([repr(x) for x in SRC.get_surrounding_lines(1, 0)]) assert lines == 'world\nthis\n' SRC.eat_string('this\nis\na\n') lines = [str(x) for x in SRC.get_surrounding_lines()] assert lines == ['5 |a\n', '6 |test'] lines = ''.join([repr(x) for x in SRC.get_surrounding_lines()]) assert lines == 'a\ntest'
def test_eat_string_multiline_chunk(self): SRC = SourceString('hello\nworld') SRC.eat_string('hello\nworld') assert SRC.row == 2 assert SRC.col == 5 assert SRC.get_char() == ''
def test_spew_length(self): SRC = SourceString('hello world') SRC.eat_string('hello world') assert SRC.eos SRC.spew_length(1) assert SRC.get_char() == 'd' SRC.spew_length(10) assert SRC.get_char() == 'h' SRC.spew_length(3) assert SRC.get_char() == 'h'
def test_eat_string_multiline_peices(self): SRC = SourceString('hello\nworld') SRC.eat_string(SRC.get_length(5)) assert SRC.row == 1 assert SRC.col == 5 assert SRC.get_char() == '\n' SRC.eat_string(SRC.get_char()) assert SRC.row == 2 assert SRC.col == 0 SRC.eat_string(SRC.get_length(5)) assert SRC.row == 2 assert SRC.col == 5 assert SRC.get_char() == ''
def test_eat_string(self): SRC = SourceString('hello world') SRC.eat_string('hello world') assert SRC.eos
def test_eol_distance_last(self): SRC = SourceString('hello world') assert SRC.eol_distance_last() == 0 SRC.eat_string('hello') assert SRC.eol_distance_last() == 5
def test_get_current_line(self): SRC = SourceString('hello\nworld\nthis\nis\na\ntest') assert repr(SRC.get_current_line()) == 'hello\n' SRC.eat_string('hello\n') assert repr(SRC.get_current_line()) == 'world\n'