Hi all !
I’m trying for find a solution to shorten my test suite, even slightly
I’ve this function
def check_inst(insts, data)
data.each do |k, v|
assert_equal v[:opcode], insts[k].opcode
v[:operands].each_with_index do |operand, index|
case operand[:klass]
when NumberLiteral
puts "here"
# assert_equal operand[:value], insts[k].operands[index].value.value
when Ident
puts "yo"
when IR::Register
puts "reg"
else
puts operand[:klass]
end
end
end
end
That I call this way
exp = {
0 => {
opcode: IR::OpCode::MUL,
operands: {
{klass: IR::Register},
{klass: NumberLiteral, value: 2},
{klass: NumberLiteral, value: 8},
},
},
1 => {
opcode: IR::OpCode::MOV,
operands: {
{klass: IR::Register},
{klass: Ident, name: "b", indiced_by: !nil},
},
},
}
check_inst(get_insts(opcodes), exp)
The case/when always ends in the else block
When I print out the content of operand[:klass] it appears to be ok, so why the right case is not executed ?
Basically I’m comparing a class names with class names