Example #1
0
def test_convert_ops_with_constant():
    oplist, messages = convert_ops([SET(Token.R(1), Token.Sym("n"))], {"n": 100})

    assert len(messages.errors) == 0
    assert oplist == [
        SETLO(Token.R(1), Token.Int(100)),
        SETHI(Token.R(1), Token.Int(0)),
    ]
Example #2
0
def test_substitute_label_with_other_op():
    program = INC(Token.R(1), Token.Sym("N"))
    labels = {"N": 10}
    assert substitute_label(program, labels) == INC(Token.R(1), Token.Int(10))
Example #3
0
def test_substitute_label_with_SETHI():
    program = SETHI(Token.R(1), Token.Sym("N"))
    labels = {"N": 10}
    assert substitute_label(program, labels) == SETHI(Token.R(1),
                                                      Token.Int(10))
Example #4
0
def test_get_labels_with_invalid_code(settings):
    labels, messages = get_labels([CALL(Token.Sym("l"))], settings)

    assert len(labels) == 0
    assert len(messages.errors) == 0
Example #5
0
def test_operation_length_of_CALL_with_label():
    assert operation_length(CALL(Token.R(12), Token.Sym("l"))) == 3
Example #6
0
def test_operation_length_of_register_branch_with_label():
    assert operation_length(BNZ(Token.Sym("l"))) == 3
def branch_helper(vm, branchname):
    op = name_to_class[branchname](Token.Sym("l"))
    return op.should(vm)
Example #8
0
def test_parse_label_starting_with_register_name():
    program = valid("LABEL(R1_INIT)")

    assert program == [LABEL(Token.Sym("R1_INIT"))]
Example #9
0
def test_convert_ops_does_not_report_error_for_valid_relative_branch():
    data = [INTEGER(Token.Int(1))] * 200
    oplist, messages = convert_ops(data + [BRR(Token.Sym("l"))], {"l": 1})

    assert len(messages.errors) == 0
    assert oplist == data + [BRR(Token.Int(1))]
Example #10
0
def test_convert_ops_reports_error_for_invalid_relative_branch():
    oplist, messages = convert_ops([BRR(Token.Sym("l"))], {"l": 9000})

    assert len(messages.errors) == 1
    assert "too far" in messages.errors[0][0]