Exemple #1
0
def test_calc_finds_eof_token_after_int():
    """
    Test that after consuming a solitary an INTEGER :class:`Token` a
    :class:`Calc` will correctly tokenize an EOF :class:`Token`.
    """
    input_text = "1"
    calc = Calc(text=input_text)
    token = calc._next_token()
    assert token.type == INTEGER
    assert token.value == 1
    assert calc._next_token().type == EOF
Exemple #2
0
def test_calc_finds_eof_token_at_end_of_line():
    """
    Test that, upon finding an end of line, a :class:`Calc` correctly tokenizes
    an EOF :class:`Token`.
    """
    input_text = ""
    calc = Calc(text=input_text)
    assert calc._next_token().type == EOF
Exemple #3
0
def test_calc_can_consume_valid_token():
    """Test that a :class:`Calc` can consume a valid :class:`Token`."""
    input_text = "1+1"
    calc = Calc(text=input_text)
    # Note: Since _next_token advances position one cannot simply
    # >>> calc.current_token = Token(INTEGER, 1)
    # The _next_token method MUST be called or this test will fail.
    calc.current_token = calc._next_token()
    calc._consume_token(INTEGER)
    assert calc.current_token.type == PLUS