Skip to content

Use values in bindings instead of hardcoding numbers in test #4

@yousefmoazzam

Description

@yousefmoazzam

The following test defines some bindings with values in the test expression at the start, but then hardcodes the same values in the expected_ast_node binding value:

c-compiler/src/parse/c.rs

Lines 472 to 491 in 3e75565

fn parse_expression_with_two_different_precedence_binary_operators() {
let outer_left_operand = 1;
let inner_left_operand = 2;
let inner_right_operand = 3;
let mut tokens = VecDeque::from([
Token::NumericConstant(outer_left_operand),
Token::Plus,
Token::NumericConstant(inner_left_operand),
Token::Asterisk,
Token::NumericConstant(inner_right_operand),
]);
let expected_ast_node = Expression::Binary {
op: BinaryOperator::Add,
left: Box::new(Expression::NumericConstant(outer_left_operand)),
right: Box::new(Expression::Binary {
op: BinaryOperator::Multiply,
left: Box::new(Expression::NumericConstant(2)),
right: Box::new(Expression::NumericConstant(3)),
}),
};

It's best to reuse the bindings and get rid of the hardcoded/magic numbers, to avoid any errors with the hardcoded values going out of sync with the binding values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions