@@ -6,17 +6,42 @@ module.exports = require('./common').runTest(test);
6
6
7
7
function test ( binding ) {
8
8
const testData = [
9
- [ 'int8' , Int8Array , 1 ] ,
10
- [ 'uint8' , Uint8Array , 1 ] ,
11
- [ 'uint8_clamped' , Uint8ClampedArray , 1 ] ,
12
- [ 'int16' , Int16Array , 2 ] ,
13
- [ 'uint16' , Uint16Array , 2 ] ,
14
- [ 'int32' , Int32Array , 4 ] ,
15
- [ 'uint32' , Uint32Array , 4 ] ,
16
- [ 'float32' , Float32Array , 4 ] ,
17
- [ 'float64' , Float64Array , 8 ]
9
+ [ 'int8' , Int8Array , 1 , new Int8Array ( [ 0 , 124 , 24 , 44 ] ) ] ,
10
+ [ 'uint8' , Uint8Array , 1 , new Uint8Array ( [ 0 , 255 , 2 , 14 ] ) ] ,
11
+ [ 'uint8_clamped' , Uint8ClampedArray , 1 , new Uint8ClampedArray ( [ 0 , 256 , 0 , 255 ] ) ] ,
12
+ [ 'int16' , Int16Array , 2 , new Int16Array ( [ - 32768 , 32767 , 1234 , 42 ] ) ] ,
13
+ [ 'uint16' , Uint16Array , 2 , new Uint16Array ( [ 0 , 65535 , 4 , 12 ] ) ] ,
14
+ [ 'int32' , Int32Array , 4 , new Int32Array ( [ Math . pow ( 2 , 31 ) , Math . pow ( - 2 , 31 ) , 255 , 4 ] ) ] ,
15
+ [ 'uint32' , Uint32Array , 4 , new Uint32Array ( [ 0 , Math . pow ( 2 , 32 ) , 24 , 125 ] ) ] ,
16
+ [ 'float32' , Float32Array , 4 , new Float32Array ( [ 0 , 21 , 34 , 45 ] ) ] ,
17
+ [ 'float64' , Float64Array , 8 , new Float64Array ( [ 0 , 4124 , 45 , 90 ] ) ]
18
18
] ;
19
19
20
+ const bigIntTests = [
21
+ [ 'bigint64' , BigInt64Array , 8 , new BigInt64Array ( [ 9007199254740991n , 9007199254740991n , 24n , 125n ] ) ] ,
22
+ [ 'biguint64' , BigUint64Array , 8 , new BigUint64Array ( [ 9007199254740991n , 9007199254740991n , 2345n , 345n ] ) ]
23
+ ] ;
24
+
25
+ bigIntTests . forEach ( data => {
26
+ const length = 4 ;
27
+ const t = binding . typedarray . createTypedArray ( data [ 0 ] , length ) ;
28
+ assert . ok ( t instanceof data [ 1 ] ) ;
29
+ assert . strictEqual ( binding . typedarray . getTypedArrayType ( t ) , data [ 0 ] ) ;
30
+ assert . strictEqual ( binding . typedarray . getTypedArrayLength ( t ) , length ) ;
31
+ assert . strictEqual ( binding . typedarray . getTypedArraySize ( t ) , data [ 2 ] ) ;
32
+ assert . strictEqual ( binding . typedarray . getTypedArrayByteOffset ( t ) , 0 ) ;
33
+ assert . strictEqual ( binding . typedarray . getTypedArrayByteLength ( t ) , data [ 2 ] * length ) ;
34
+
35
+ t [ 3 ] = 11n ;
36
+ assert . strictEqual ( binding . typedarray . getTypedArrayElement ( t , 3 ) , 11n ) ;
37
+ binding . typedarray . setTypedArrayElement ( t , 3 , 22n ) ;
38
+ assert . strictEqual ( binding . typedarray . getTypedArrayElement ( t , 3 ) , 22n ) ;
39
+ assert . strictEqual ( t [ 3 ] , 22n ) ;
40
+
41
+ const nonEmptyTypedArray = binding . typedarray . createTypedArray ( data [ 0 ] , length , data [ 3 ] . buffer ) ;
42
+ binding . typedarray . checkBufferContent ( nonEmptyTypedArray , data [ 3 ] ) ;
43
+ } ) ;
44
+
20
45
testData . forEach ( data => {
21
46
try {
22
47
const length = 4 ;
@@ -63,6 +88,9 @@ function test (binding) {
63
88
assert . strictEqual ( t [ 3 ] , 22 ) ;
64
89
65
90
assert . strictEqual ( binding . typedarray . getTypedArrayBuffer ( t ) , b ) ;
91
+
92
+ const nonEmptyTypedArray = binding . typedarray . createTypedArray ( data [ 0 ] , length , data [ 3 ] . buffer ) ;
93
+ assert . strictEqual ( binding . typedarray . checkBufferContent ( nonEmptyTypedArray , data [ 3 ] ) , true ) ;
66
94
} catch ( e ) {
67
95
console . log ( data ) ;
68
96
throw e ;
0 commit comments