const test cases

This commit is contained in:
NikVolf
2017-04-20 17:56:15 +03:00
parent 31c1588a2f
commit 9b401659e9
4 changed files with 30 additions and 2 deletions

BIN
res/cases/v1/const.wasm Normal file

Binary file not shown.

12
res/cases/v1/const.wast Normal file
View File

@ -0,0 +1,12 @@
(module
(type (;0;) (func (result i32)))
(func (;0;) (type 0) (result i32)
i32.const 1024
i32.const 2048
i32.const 4096
i32.const 8192
i32.const 16384
i32.const 32767
return
)
)

View File

@ -238,4 +238,20 @@ mod integration_tests {
"There should be equal amount of function bodies before and after serialization" "There should be equal amount of function bodies before and after serialization"
); );
} }
#[test]
fn const_() {
use super::super::Opcode::*;
let module = deserialize_file("./res/cases/v1/const.wasm").expect("Should be deserialized");
let func = &module.code_section().expect("Code section to exist").bodies()[0];
assert_eq!(func.code().elements().len(), 8);
assert_eq!(I32Const(1024), func.code().elements()[0]);
assert_eq!(I32Const(2048), func.code().elements()[1]);
assert_eq!(I32Const(4096), func.code().elements()[2]);
assert_eq!(I32Const(8192), func.code().elements()[3]);
assert_eq!(I32Const(16384), func.code().elements()[4]);
assert_eq!(I32Const(32767), func.code().elements()[5]);
}
} }

View File

@ -6,7 +6,7 @@ use super::{
}; };
/// Collection of opcodes (usually inside a block section). /// Collection of opcodes (usually inside a block section).
#[derive(Debug)] #[derive(Debug, PartialEq)]
pub struct Opcodes(Vec<Opcode>); pub struct Opcodes(Vec<Opcode>);
impl Opcodes { impl Opcodes {
@ -88,7 +88,7 @@ impl Deserialize for InitExpr {
} }
/// Opcode /// Opcode
#[derive(Debug)] #[derive(Debug, PartialEq)]
#[allow(missing_docs)] #[allow(missing_docs)]
pub enum Opcode { pub enum Opcode {
Unreachable, Unreachable,