mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-24 02:01:35 +00:00
Move the js
module to a js_sys
crate (#512)
* Move the `js` module to a `js_sys` crate * Update js-sys tests to pass again * Update binding_to_unimplemented_apis_doesnt_break_everything Remove its dependency on the `js` module * Update metadata for js-sys * Fix the `closures` example
This commit is contained in:
56
crates/js-sys/tests/all/DataView.rs
Normal file
56
crates/js-sys/tests/all/DataView.rs
Normal file
@ -0,0 +1,56 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use super::project;
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
project()
|
||||
.file("src/lib.rs", r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate js_sys;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use js_sys::{ArrayBuffer, DataView};
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test_data_view(buffer: &ArrayBuffer, offset: usize, len: usize) {
|
||||
let v = DataView::new(buffer, offset, len);
|
||||
assert_eq!(v.byte_offset(), offset);
|
||||
assert_eq!(v.byte_length(), len);
|
||||
assert_eq!(v.get_int8(0), 2);
|
||||
assert_eq!(v.get_uint8(0), 2);
|
||||
|
||||
v.set_int8(0, 42);
|
||||
assert_eq!(v.get_int8(0), 42);
|
||||
v.set_uint8(0, 255);
|
||||
assert_eq!(v.get_uint8(0), 255);
|
||||
v.set_int16(0, 32767);
|
||||
assert_eq!(v.get_int16(0), 32767);
|
||||
v.set_uint16(0, 65535);
|
||||
assert_eq!(v.get_uint16(0), 65535);
|
||||
v.set_int32(0, 123456789);
|
||||
assert_eq!(v.get_int32(0), 123456789);
|
||||
v.set_uint32(0, 3_123_456_789);
|
||||
assert_eq!(v.get_uint32(0), 3_123_456_789);
|
||||
v.set_float32(0, 100.123);
|
||||
assert_eq!(v.get_float32(0), 100.123);
|
||||
v.set_float64(0, 123456789.123456);
|
||||
assert_eq!(v.get_float64(0), 123456789.123456);
|
||||
|
||||
v.set_int8(0, 42);
|
||||
}
|
||||
"#)
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
const bytes = new Int8Array(10);
|
||||
bytes[2] = 2;
|
||||
wasm.test_data_view(bytes.buffer, 2, 8);
|
||||
assert.equal(bytes[2], 42);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
Reference in New Issue
Block a user