def test_is_next_char(): stream = CharStream('a3') assert stream.get(0).value == 'a' assert not stream.get(1).value == 'C' assert stream.get(1).value == '3'
def test_char_values(): text = 'i76hj-' stream = CharStream(text) values = ''.join([stream.get(i).value for i, _ in enumerate(text)]) assert values == text
def test_empty_text_is_eof(): stream = CharStream() assert stream.get().is_eof()
def test_char_column(): text = 'ab\nc\n\nd' stream = CharStream(text) lines = [stream.get(i).column for i, _ in enumerate(text)] assert lines == [0, 1, 2, 0, 1, 0, 0]
def test_char_line(): text = 'ab\nc\n\nd' stream = CharStream(text) lines = [stream.get(i).line for i, _ in enumerate(text)] assert lines == [0, 0, 0, 1, 1, 2, 3]
def test_char_type(test_input, method): stream = CharStream(test_input) ch = stream.get() assert getattr(ch, method)()