示例#1
0
def test_if_with_statement() -> None:
    tokens = "if x less than three then set x to three".split()

    engine = RuleEngine(tokens)

    code = Code()
    code.symbols.add_variable_symbol("x")

    assert engine.parse_if(code) == "if x < 3:"
    assert engine.tokens == "set x to three".split()
示例#2
0
def test_if_basic() -> None:
    tokens = "if x less than y then".split()

    engine = RuleEngine(tokens)

    code = Code()
    code.symbols.add_variable_symbol("x")
    code.symbols.add_variable_symbol("y")

    assert engine.parse_if(code) == "if x < y:"
    assert engine.tokens == []
示例#3
0
def test_if_with_else() -> None:
    tokens = "if x greater than or equal to three then set x to three else set x to zero".split(
    )

    engine = RuleEngine(tokens)

    code = Code()
    code.symbols.add_variable_symbol("x")

    assert engine.parse_if(code) == "if x >= 3:"
    assert engine.tokens == "set x to three else set x to zero".split()