-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c74758
commit 83b2bb8
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use wasm_bindgen_test::wasm_bindgen_test; | ||
use web_sys::js_sys::{Int32Array, SharedArrayBuffer, Uint8Array}; | ||
|
||
use crate::{write_command_with_payload, InputCommand, OutputCommand}; | ||
|
||
#[wasm_bindgen_test] | ||
fn test_command_conversion() { | ||
assert_eq!(InputCommand::DbRequest as i32, 2); | ||
assert_eq!(OutputCommand::DbResponse as i32, 2); | ||
assert!(InputCommand::try_from(20 as i32).is_ok()); | ||
assert!(OutputCommand::try_from(20 as i32).is_ok()); | ||
} | ||
|
||
#[wasm_bindgen_test] | ||
// #[test] | ||
fn test_command_write() { | ||
let arr_buf = SharedArrayBuffer::new(100); | ||
let i32arr = Int32Array::new(&arr_buf); | ||
let u8arr = Uint8Array::new(&arr_buf); | ||
write_command_with_payload( | ||
InputCommand::DbRequest as i32, | ||
vec![1, 2, 3, 4], | ||
&i32arr, | ||
&u8arr, | ||
) | ||
.unwrap(); | ||
assert_eq!(i32arr.get_index(0), InputCommand::DbRequest as i32); | ||
let mut buf = vec![0u8; 100]; | ||
u8arr.copy_to(&mut buf); | ||
let result = | ||
bincode::deserialize::<Vec<i32>>(&buf[8..i32arr.get_index(1) as usize + 8]).unwrap(); | ||
assert_eq!(result, vec![1, 2, 3, 4]); | ||
} |