def test_Lexer_init(self): lex = lexer2.Lexer("I am source text", SyntaxError) assert lex.src == "I am source text" assert lex.pos == 0 assert lex.syntax_error_ctor == SyntaxError assert isinstance(lex, lexer2.LexerCore) assert isinstance(lex, lexer2.Lexer)
def test_next_id_if(self, src, check, newline, expected, newpos): lex = lexer2.Lexer(src, SyntaxError) rv = lex.next_id_if(check, prior_newline_allowed=newline) assert rv == expected assert lex.current_position() == newpos
def test_next_token(self, src, newpos, tok): lex = lexer2.Lexer(src, SyntaxError) token = lex.next_token() assert token == tok assert lex.current_position() == newpos
def test_peek_token(self, count, expected): lex = lexer2.Lexer("one two three", SyntaxError) rv = lex.peek_token(count) assert rv == expected
def test_position(self): lex = lexer2.Lexer("I am source text", SyntaxError) assert lex.current_position() == 0 lex.reset_position(5) assert lex.current_position() == 5
def test_Lexer_repr(self, source_text, where, expected): lex = lexer2.Lexer(source_text, SyntaxError) lex.reset_position(where) rv = f"{lex!r}" assert rv == expected