Debian Codegraph @

.cargo/vendor/js-sys/tests/wasm/ArrayBuffer.rs

raw
1 use js_sys::*;
2 use wasm_bindgen::JsCast;
3 use wasm_bindgen::JsValue;
4 use wasm_bindgen_test::*;
5
6 #[wasm_bindgen_test]
7 fn new() {
8 let x = ArrayBuffer::new(42);
9 let y: JsValue = x.into();
10 assert!(y.is_object());
11 }
12
13 #[wasm_bindgen_test]
14 fn byte_length() {
15 let buf = ArrayBuffer::new(42);
16 assert_eq!(buf.byte_length(), 42);
17 }
18
19 #[wasm_bindgen_test]
20 fn is_view() {
21 let x = Uint8Array::new(&JsValue::from(42));
22 assert!(ArrayBuffer::is_view(&JsValue::from(x)));
23 }
24
25 #[wasm_bindgen_test]
26 fn slice() {
27 let buf = ArrayBuffer::new(4);
28 let slice = buf.slice(2);
29 assert!(JsValue::from(slice).is_object());
30 }
31
32 #[wasm_bindgen_test]
33 fn slice_with_end() {
34 let buf = ArrayBuffer::new(4);
35 let slice = buf.slice_with_end(1, 2);
36 assert!(JsValue::from(slice).is_object());
37 }
38
39 #[wasm_bindgen_test]
40 fn arraybuffer_inheritance() {
41 let buf = ArrayBuffer::new(4);
42 assert!(buf.is_instance_of::<ArrayBuffer>());
43 assert!(buf.is_instance_of::<Object>());
44 let _: &Object = buf.as_ref();
45 }