Skip to content

Commit

Permalink
test: multiply test
Browse files Browse the repository at this point in the history
  • Loading branch information
nerodesu017 committed Jun 25, 2024
1 parent 116c83e commit 6b0c0bd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/arithmetic/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod multiply;
24 changes: 24 additions & 0 deletions tests/arithmetic/multiply.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// A simple function to multiply by 2 a i32 value and return the result
#[test_log::test]
pub fn multiply() {
use wasm::{validate, RuntimeInstance};

let wat = r#"
(module
(func (export "multiply") (param $x i32) (result i32)
local.get $x
i32.const 2
i32.mul)
)
"#;

let wasm_bytes = wat::parse_str(wat).unwrap();

let validation_info = validate(&wasm_bytes).expect("validation failed");

let mut instance = RuntimeInstance::new(&validation_info).expect("instantiation failed");

assert_eq!(22, instance.invoke_func(0, 11));
assert_eq!(0, instance.invoke_func(0, 0));
assert_eq!(-20, instance.invoke_func(0, -10));
}
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod arithmetic;

0 comments on commit 6b0c0bd

Please sign in to comment.