Skip to content

Commit 0f2c1ff

Browse files
committed
Added Test for Float32Array
1 parent 2b5a0a0 commit 0f2c1ff

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

mozjs/tests/typedarray.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use mozjs::jsval::UndefinedValue;
99
use mozjs::rooted;
1010
use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS};
1111
use mozjs::typedarray;
12-
use mozjs::typedarray::{CreateWith, Uint32Array};
12+
use mozjs::typedarray::{CreateWith, Float32Array, Uint32Array};
1313

1414
#[test]
1515
fn typedarray() {
@@ -42,7 +42,7 @@ fn typedarray() {
4242
assert!(rval.is_object());
4343

4444
typedarray!(in(context) let array: Uint8Array = rval.to_object());
45-
assert_eq!(array.unwrap().as_slice(), &[0, 2, 4][..]);
45+
assert_eq!(array.unwrap().as_slice(), &[0, 2, 4]);
4646

4747
typedarray!(in(context) let array: Uint8Array = rval.to_object());
4848
assert_eq!(array.unwrap().len(), 3);
@@ -62,11 +62,11 @@ fn typedarray() {
6262
);
6363

6464
typedarray!(in(context) let array: Uint32Array = rval.get());
65-
assert_eq!(array.unwrap().as_slice(), &[1, 3, 5][..]);
65+
assert_eq!(array.unwrap().as_slice(), &[1, 3, 5]);
6666

6767
typedarray!(in(context) let mut array: Uint32Array = rval.get());
6868
array.as_mut().unwrap().update(&[2, 4, 6]);
69-
assert_eq!(array.unwrap().as_slice(), &[2, 4, 6][..]);
69+
assert_eq!(array.unwrap().as_slice(), &[2, 4, 6]);
7070

7171
rooted!(in(context) let rval = ptr::null_mut::<JSObject>());
7272
typedarray!(in(context) let array: Uint8Array = rval.get());
@@ -87,5 +87,15 @@ fn typedarray() {
8787

8888
typedarray!(in(context) let view: ArrayBufferView = rval.get());
8989
assert_eq!(view.unwrap().is_shared(), false);
90+
91+
rooted!(in(context) let mut rval = ptr::null_mut::<JSObject>());
92+
assert!(Float32Array::create(context, CreateWith::Slice(&[0.25, 0.5, 1.0, 2.0, 4.0]), rval.handle_mut()).is_ok());
93+
94+
typedarray!(in(context) let array: Float32Array = rval.get());
95+
assert_eq!(array.unwrap().as_slice(), &[0.25, 0.5, 1.0, 2.0, 4.0]);
96+
97+
typedarray!(in(context) let mut array: Float32Array = rval.get());
98+
array.as_mut().unwrap().update(&[0.5, 1.0, 2.0]);
99+
assert_eq!(array.unwrap().as_slice(), &[0.5, 1.0, 2.0, 2.0, 4.0]);
90100
}
91101
}

0 commit comments

Comments
 (0)