mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-05-28 23:21:35 +00:00
if-else test with block split approach
This commit is contained in:
parent
99930c76bf
commit
870a37fd64
Binary file not shown.
@ -6,9 +6,9 @@
|
||||
set_local 0
|
||||
i32.const 0
|
||||
if i32
|
||||
i32.const 8
|
||||
i32.const 5
|
||||
else
|
||||
i32.const 4
|
||||
i32.const 7
|
||||
end
|
||||
set_local 0
|
||||
get_local 0
|
||||
|
@ -913,3 +913,23 @@ impl Serialize for InitExpr {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ifelse() {
|
||||
// see if-else.wast/if-else.wasm
|
||||
let opcode = super::deserialize_buffer::<Opcode>(vec![0x04, 0x7F, 0x41, 0x05, 0x05, 0x41, 0x07, 0x0B])
|
||||
.expect("valid hex of if instruction");
|
||||
match opcode {
|
||||
Opcode::If(_, ops) => {
|
||||
let before_else = ops.elements().iter()
|
||||
.take_while(|op| match **op { Opcode::Else => false, _ => true }).count();
|
||||
let after_else = ops.elements().iter()
|
||||
.skip_while(|op| match **op { Opcode::Else => false, _ => true })
|
||||
.take_while(|op| match **op { Opcode::End => false, _ => true })
|
||||
.count()
|
||||
- 1; // minus Opcode::Else itself
|
||||
|
||||
assert_eq!(before_else, after_else);
|
||||
},
|
||||
_ => { panic!("Should be deserialized as if opcode"); }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user