示例#1
0
def test_conditional():
    e = dut.MacroEvaluator(conditional_macro.split("\n"))
    # COND1 gets removed by undef
    assert "COND1" not in e.symbols.keys()
    assert "COND2" in e.symbols.keys()
    assert "COND3" in e.symbols.keys()
    assert "COND4" not in e.symbols.keys()
示例#2
0
def test_symbol_finding():
    e = dut.MacroEvaluator([macro_str, *multiline_macro.split("\n"), not_macro_str])
    assert "TEST" in e.symbols.keys()
    assert "TEST2" not in e.symbols.keys()
    assert "MACRO" in e.symbols.keys()
    assert "1+2+4+5*3" in e.symbols["MACRO"]
    assert len(e.symbols.keys()) == 2
示例#3
0
def test_include():
    e = dut.MacroEvaluator(
        r"""#include "test/test_c_macro_evaluator.py"
    """.split(
            "\n"
        )
    )
    assert "COND2" in e.symbols.keys()
示例#4
0
def test_file():
    e = dut.MacroEvaluator(file_name="test/test_c_macro_evaluator.py")
    assert "COND2" in e.symbols.keys()
示例#5
0
def test_errors():
    with pytest.raises(UserWarning):
        dut.MacroEvaluator([error])

    with pytest.raises(UserWarning):
        dut.MacroEvaluator([error_msg])
示例#6
0
def test_evaluate():
    e = dut.MacroEvaluator(
        [*multiline_macro.split("\n"), recursive_macro, circular_macro]
    )
    assert e.evaluate_macro("MACRO") == 22
    assert e.evaluate_macro("RECURSIVE") == 23
示例#7
0
def test_include_no_filename():
    with pytest.raises(UserWarning):
        dut.MacroEvaluator(["#include"])