Beispiel #1
0
def test_functions_are_lexed():
    assert (do_lex(":S3") == [
        FunctionCallToken(),
        SymbolToken("S"),
        NumberToken("3"),
    ])
    assert (do_lex("3:S") == [
        NumberToken("3"),
        FunctionCallToken(),
        SymbolToken("S"),
    ])
Beispiel #2
0
def test_operators_are_lexed():
    assert (do_lex("3=d") == [
        NumberToken("3"),
        OperatorToken("="),
        SymbolToken("d")
    ])
    assert (do_lex("3-d") == [
        NumberToken("3"),
        OperatorToken("-"),
        SymbolToken("d")
    ])
    assert (do_lex("3/d") == [
        NumberToken("3"),
        OperatorToken("/"),
        SymbolToken("d")
    ])
Beispiel #3
0
def test_function_call_then_add_is_lexed():
    assert (do_lex(":S95+_ab_c") == [
        FunctionCallToken(),
        SymbolToken("S"),
        NumberToken("95"),
        OperatorToken("+"),
        SymbolToken("_ab_c"),
    ])
Beispiel #4
0
def test_braces_are_lexed():
    assert do_lex("{") == [StartFunctionDefToken()]
    assert (do_lex("34{:S}") == [
        NumberToken("34"),
        StartFunctionDefToken(),
        FunctionCallToken(),
        SymbolToken("S"),
        EndFunctionDefToken(),
    ])
Beispiel #5
0
def test_decimals_are_lexed():
    assert do_lex("1.1d") == [NumberToken("1.1"), SymbolToken("d")]
Beispiel #6
0
def test_negative_sign_is_lexed_as_operator_number():
    assert do_lex("-90") == [OperatorToken("-"), NumberToken("90")]
    assert do_lex("-0.03") == [OperatorToken("-"), NumberToken("0.03")]
Beispiel #7
0
def test_operator_followed_by_number_makes_two_tokens():
    assert (do_lex("3+90") == [
        NumberToken("3"),
        OperatorToken("+"),
        NumberToken("90")
    ])
Beispiel #8
0
def test_number_and_symbol_are_lexed_separately():
    assert do_lex("3d") == [NumberToken("3"), SymbolToken("d")]