mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-04-11 15:06:02 +00:00
more complex test
This commit is contained in:
parent
7504381419
commit
f5890c2c7b
78
src/graph.rs
78
src/graph.rs
@ -759,27 +759,83 @@ mod tests {
|
|||||||
|
|
||||||
extern crate wabt;
|
extern crate wabt;
|
||||||
|
|
||||||
|
use parity_wasm::elements;
|
||||||
|
|
||||||
|
fn load_sample(wat: &'static str) -> super::Module {
|
||||||
|
super::parse(&wabt::wat2wasm(wat).expect("faled to parse wat!")[..])
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn smoky() {
|
fn smoky() {
|
||||||
let wasm = wabt::wat2wasm(r#"
|
let sample = load_sample(r#"
|
||||||
(module
|
(module
|
||||||
(type (func))
|
(type (func))
|
||||||
(func (type 0))
|
(func (type 0))
|
||||||
(memory 0 1)
|
(memory 0 1)
|
||||||
(export "simple" (func 0))
|
(export "simple" (func 0))
|
||||||
|
)
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(sample.types.len(), 1);
|
||||||
|
assert_eq!(sample.funcs.len(), 1);
|
||||||
|
assert_eq!(sample.tables.len(), 0);
|
||||||
|
assert_eq!(sample.memory.len(), 1);
|
||||||
|
assert_eq!(sample.exports.len(), 1);
|
||||||
|
|
||||||
|
assert_eq!(sample.types.get_ref(0).link_count(), 1);
|
||||||
|
assert_eq!(sample.funcs.get_ref(0).link_count(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn table() {
|
||||||
|
let mut sample = load_sample(r#"
|
||||||
|
(module
|
||||||
|
(import "env" "foo" (func $foo))
|
||||||
|
(func (param i32)
|
||||||
|
get_local 0
|
||||||
|
i32.const 0
|
||||||
|
call $i32.add
|
||||||
|
drop
|
||||||
)
|
)
|
||||||
"#).expect("Failed to read fixture");
|
(func $i32.add (export "i32.add") (param i32 i32) (result i32)
|
||||||
|
get_local 0
|
||||||
|
get_local 1
|
||||||
|
i32.add
|
||||||
|
)
|
||||||
|
(table 10 anyfunc)
|
||||||
|
|
||||||
let f = super::parse(&wasm[..]);
|
;; Refer all types of functions: imported, defined not exported and defined exported.
|
||||||
|
(elem (i32.const 0) 0 1 2)
|
||||||
|
)"#
|
||||||
|
);
|
||||||
|
|
||||||
assert_eq!(f.types.len(), 1);
|
{
|
||||||
assert_eq!(f.funcs.len(), 1);
|
let element_func = &sample.elements[0].value[1];
|
||||||
assert_eq!(f.tables.len(), 0);
|
let rfunc = element_func.read();
|
||||||
assert_eq!(f.memory.len(), 1);
|
let rtype = &**rfunc.type_ref.read();
|
||||||
assert_eq!(f.exports.len(), 1);
|
let elements::Type::Function(ref ftype) = rtype;
|
||||||
|
|
||||||
|
// it's func#1 in the function space
|
||||||
|
assert_eq!(rfunc.order(), Some(1));
|
||||||
|
// it's type#1
|
||||||
|
assert_eq!(ftype.params().len(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
sample.funcs.begin_delete().push(0).done();
|
||||||
|
|
||||||
|
{
|
||||||
|
let element_func = &sample.elements[0].value[1];
|
||||||
|
let rfunc = element_func.read();
|
||||||
|
let rtype = &**rfunc.type_ref.read();
|
||||||
|
let elements::Type::Function(ref ftype) = rtype;
|
||||||
|
|
||||||
|
/// import deleted so now it's func #0
|
||||||
|
assert_eq!(rfunc.order(), Some(0));
|
||||||
|
/// type should be the same, #1
|
||||||
|
assert_eq!(ftype.params().len(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
assert_eq!(f.types.get_ref(0).link_count(), 1);
|
|
||||||
assert_eq!(f.funcs.get_ref(0).link_count(), 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user