summaryrefslogtreecommitdiffstats
path: root/vendor/js-sys/tests/wasm/ArrayBuffer.rs
blob: 1bf099aef14b37d2d8ff319507a9879cfbab7d24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use js_sys::*;
use wasm_bindgen::JsCast;
use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;

#[wasm_bindgen_test]
fn new() {
    let x = ArrayBuffer::new(42);
    let y: JsValue = x.into();
    assert!(y.is_object());
}

#[wasm_bindgen_test]
fn byte_length() {
    let buf = ArrayBuffer::new(42);
    assert_eq!(buf.byte_length(), 42);
}

#[wasm_bindgen_test]
fn is_view() {
    let x = Uint8Array::new(&JsValue::from(42));
    assert!(ArrayBuffer::is_view(&JsValue::from(x)));
}

#[wasm_bindgen_test]
fn slice() {
    let buf = ArrayBuffer::new(4);
    let slice = buf.slice(2);
    assert!(JsValue::from(slice).is_object());
}

#[wasm_bindgen_test]
fn slice_with_end() {
    let buf = ArrayBuffer::new(4);
    let slice = buf.slice_with_end(1, 2);
    assert!(JsValue::from(slice).is_object());
}

#[wasm_bindgen_test]
fn arraybuffer_inheritance() {
    let buf = ArrayBuffer::new(4);
    assert!(buf.is_instance_of::<ArrayBuffer>());
    assert!(buf.is_instance_of::<Object>());
    let _: &Object = buf.as_ref();
}