コード例 #1
0
 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)
コード例 #2
0
 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
コード例 #3
0
 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
コード例 #4
0
 def test_peek_token(self, count, expected):
     lex = lexer2.Lexer("one two three", SyntaxError)
     rv = lex.peek_token(count)
     assert rv == expected
コード例 #5
0
 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
コード例 #6
0
    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