From ba58c1331c7fd79bfe288be89f389d597818f7c0 Mon Sep 17 00:00:00 2001 From: mahaifeng Date: Mon, 29 Jul 2024 15:08:13 +0800 Subject: [PATCH] =?UTF-8?q?[arraybuffer]=E4=BF=AE=E6=94=B91.0=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uts-tests/utssdk/ArrayBuffer.uts | 3 +- uni_modules/uts-tests/utssdk/TDataView.uts | 2 +- .../uts-tests/utssdk/TFloat32Array.uts | 8 ++--- .../uts-tests/utssdk/TFloat64Array.uts | 8 ++--- uni_modules/uts-tests/utssdk/TInt16Array.uts | 33 ++++++++++--------- uni_modules/uts-tests/utssdk/TInt32Array.uts | 10 +++--- uni_modules/uts-tests/utssdk/TInt8Array.uts | 6 ++-- uni_modules/uts-tests/utssdk/TUInt8Array.uts | 10 +++--- .../uts-tests/utssdk/TUInt8ClampedArray.uts | 8 +++-- uni_modules/uts-tests/utssdk/TUint16Array.uts | 9 +++-- uni_modules/uts-tests/utssdk/TUint32Array.uts | 9 ++--- uni_modules/uts-tests/utssdk/index.uts | 5 +++ 12 files changed, 62 insertions(+), 49 deletions(-) diff --git a/uni_modules/uts-tests/utssdk/ArrayBuffer.uts b/uni_modules/uts-tests/utssdk/ArrayBuffer.uts index bde78d3..de05cab 100644 --- a/uni_modules/uts-tests/utssdk/ArrayBuffer.uts +++ b/uni_modules/uts-tests/utssdk/ArrayBuffer.uts @@ -23,8 +23,7 @@ const int16 = new TInt16Array() export function testArrayBuffer() : Result { return describe("ArrayBuffer", () => { - // #ifndef APP-IOS - + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB //dataview start test('dataview_constructor', () => { tDataView.setConstructor() diff --git a/uni_modules/uts-tests/utssdk/TDataView.uts b/uni_modules/uts-tests/utssdk/TDataView.uts index a109f40..3d44e0d 100644 --- a/uni_modules/uts-tests/utssdk/TDataView.uts +++ b/uni_modules/uts-tests/utssdk/TDataView.uts @@ -18,7 +18,7 @@ export class TDataView { // this.setUint8(); // this.testMix(); } - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB setConstructor() { let buffer = new ArrayBuffer(16); let dataview = new DataView(buffer); diff --git a/uni_modules/uts-tests/utssdk/TFloat32Array.uts b/uni_modules/uts-tests/utssdk/TFloat32Array.uts index caa6f98..e80d75e 100644 --- a/uni_modules/uts-tests/utssdk/TFloat32Array.uts +++ b/uni_modules/uts-tests/utssdk/TFloat32Array.uts @@ -7,7 +7,7 @@ import { export class TFloat32Array { test() { - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB this.testfloat32(); this.testConstructor(); this.testSet(); @@ -34,7 +34,7 @@ export class TFloat32Array { this.arrayBufferSlice(); // #endif } - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB from() { var float32Array = Float32Array.from([1, 2, 3], (v : number, _ : number) : number => v + v); expect(float32Array.toString()).toEqual('2,4,6'); @@ -76,12 +76,12 @@ export class TFloat32Array { var array = [1, 2, 3] float32.set(array, 1); expect(float32.toString()).toEqual("0,1,2,3,0,0,0,0"); - + let src = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]; let typed_dest = new Float32Array(16); typed_dest.set(src); expect(typed_dest.toString()).toEqual("1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4"); - + let typed_src = new Float32Array(src); typed_dest = new Float32Array(16); typed_dest.set(typed_src); diff --git a/uni_modules/uts-tests/utssdk/TFloat64Array.uts b/uni_modules/uts-tests/utssdk/TFloat64Array.uts index 08f6078..74468de 100644 --- a/uni_modules/uts-tests/utssdk/TFloat64Array.uts +++ b/uni_modules/uts-tests/utssdk/TFloat64Array.uts @@ -7,7 +7,7 @@ import { export class TFloat64Array { test() { - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB this.testfloat64(); this.testConstructor(); this.testSet(); @@ -34,7 +34,7 @@ export class TFloat64Array { this.arrayBufferSlice(); // #endif } - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB testfloat64() { let float64 = new Float64Array(2); float64[0] = 42; @@ -315,8 +315,8 @@ export class TFloat64Array { for (let i = 0; i < size; ++i) { initialFloat64Array[i] = Math.random(); } - let arr = new Float64Array(initialFloat64Array); - let new_arr = arr.subarray(1, size - 1); + let arr = new Float64Array(initialFloat64Array); + let new_arr = arr.subarray(1, size - 1); for (let i = 1; i < size - 1; ++i) { if (arr[i] !== new_arr[i - 1]) { expect(true).toEqual(false); diff --git a/uni_modules/uts-tests/utssdk/TInt16Array.uts b/uni_modules/uts-tests/utssdk/TInt16Array.uts index 830d217..ca08a41 100644 --- a/uni_modules/uts-tests/utssdk/TInt16Array.uts +++ b/uni_modules/uts-tests/utssdk/TInt16Array.uts @@ -7,7 +7,7 @@ import { export class TInt16Array { test() { - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB this.testConstructor(); this.testSet(); this.testCopyWith(); @@ -34,7 +34,8 @@ export class TInt16Array { // #endif } - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB + testConstructor() { let buffer = new ArrayBuffer(16); let int16 = new Int16Array(buffer); @@ -62,7 +63,7 @@ export class TInt16Array { testEvery() { // #TEST Int16Array.every - let result = new Int16Array([12, 5, 8, 130, 44]).every((value, _, _a:Int16Array):boolean => value < 40); + let result = new Int16Array([12, 5, 8, 130, 44]).every((value, _, _a : Int16Array) : boolean => value < 40); expect(result).toEqual(false); // #END } @@ -88,7 +89,7 @@ export class TInt16Array { testFilter() { // #TEST Int16Array.filter - let int16 = new Int16Array([12, 5, 8, 44]).filter((value, _, _a:Int16Array):boolean => value >= 10); + let int16 = new Int16Array([12, 5, 8, 44]).filter((value, _, _a : Int16Array) : boolean => value >= 10); expect(int16.toString()).toEqual("12,44"); // #END } @@ -96,7 +97,7 @@ export class TInt16Array { find() { // #TEST Int16Array.find let int16 = new Int16Array([4, 5, 8, 12]); - let res = int16.find((value, _, _a:Int16Array):boolean => value > 5); + let res = int16.find((value, _, _a : Int16Array) : boolean => value > 5); expect(res).toEqual(8); // #END } @@ -104,18 +105,18 @@ export class TInt16Array { findIndex() { // #TEST Int16Array.findIndex let int16 = new Int16Array([4, 6, 8, 12]); - let res = int16.findIndex((value, _, _a:Int16Array):boolean => value > 100); + let res = int16.findIndex((value, _, _a : Int16Array) : boolean => value > 100); expect(res).toEqual(-1); int16 = new Int16Array([4, 6, 7, 120]); - res = int16.findIndex((value, _, _a:Int16Array):boolean => value > 100); + res = int16.findIndex((value, _, _a : Int16Array) : boolean => value > 100); expect(res).toEqual(3); // #END } foreach() { // #TEST Int16Array.forEach - new Int16Array([0, 1, 2, 3]).forEach((value, index, _:Int16Array) => { + new Int16Array([0, 1, 2, 3]).forEach((value, index, _ : Int16Array) => { console.log(`a[${index}] = ${value}`); }); // #END @@ -192,7 +193,7 @@ export class TInt16Array { map() { // #TEST Int16Array.map let numbers = new Int16Array([1, 4, 9]); - let doubles = numbers.map((value, _, _a:Int16Array):number => value * 2); + let doubles = numbers.map((value, _, _a : Int16Array) : number => value * 2); expect(numbers.toString()).toEqual("1,4,9"); expect(doubles.toString()).toEqual("2,8,18"); // #END @@ -201,11 +202,11 @@ export class TInt16Array { reduce() { // #TEST Int16Array.reduce let total = new Int16Array([0, 1, 2, 3]); - let res = total.reduce((accumulator, currentValue, _, _a:Int16Array):number => accumulator + currentValue); + let res = total.reduce((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue); expect(res).toEqual(6); total = new Int16Array([0, 1, 2, 3]); - res = total.reduce((accumulator, currentValue, _, _a:Int16Array):number => accumulator + currentValue, 8); + res = total.reduce((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue, 8); expect(res).toEqual(14); // #END } @@ -213,11 +214,11 @@ export class TInt16Array { reduceRight() { // #TEST Int16Array.reduceRight let total = new Int16Array([0, 1, 2, 3]); - let res = total.reduceRight((accumulator, currentValue, _, _a:Int16Array):number => accumulator + currentValue); + let res = total.reduceRight((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue); expect(res).toEqual(6); total = new Int16Array([0, 1, 2, 3]); - res = total.reduceRight((accumulator, currentValue, _, _a:Int16Array):number => accumulator + currentValue, 8); + res = total.reduceRight((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue, 8); expect(res).toEqual(14); // #END } @@ -253,7 +254,7 @@ export class TInt16Array { numbers.sort(); expect(numbers.toString()).toEqual("1,5,40"); - numbers.sort((a, b):number => a - b); + numbers.sort((a, b) : number => a - b); expect(numbers.toString()).toEqual("1,5,40"); // #END } @@ -279,7 +280,7 @@ export class TInt16Array { } arrayBufferSlice() { - + // #TEST ArrayBuffer.slice with Int16Array let buffer = new ArrayBuffer(16); let int16 = new Int16Array(buffer); @@ -290,7 +291,7 @@ export class TInt16Array { let sliced = new Int16Array(res); expect(sliced[0]).toEqual(42); // #END - + } testSome() { // #TEST Int16Array.some diff --git a/uni_modules/uts-tests/utssdk/TInt32Array.uts b/uni_modules/uts-tests/utssdk/TInt32Array.uts index 23f71ad..de7e297 100644 --- a/uni_modules/uts-tests/utssdk/TInt32Array.uts +++ b/uni_modules/uts-tests/utssdk/TInt32Array.uts @@ -7,7 +7,8 @@ import { export class TInt32Array { test() { - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB + this.testInt32Array(); this.testConstructor(); this.testSet(); @@ -35,7 +36,8 @@ export class TInt32Array { // #endif } - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB + testInt32Array() { let int32 = new Int32Array(2); int32[0] = 42; @@ -298,7 +300,7 @@ export class TInt32Array { } arrayBufferSlice() { - + // #TEST ArrayBuffer.slice let buffer = new ArrayBuffer(16); let int32 = new Int32Array(buffer); @@ -309,7 +311,7 @@ export class TInt32Array { let sliced = new Int32Array(res); expect(sliced[1]).toEqual(42); // #END - + } testSome() { // #TEST Int32Array.some diff --git a/uni_modules/uts-tests/utssdk/TInt8Array.uts b/uni_modules/uts-tests/utssdk/TInt8Array.uts index 0efd20c..ea72d52 100644 --- a/uni_modules/uts-tests/utssdk/TInt8Array.uts +++ b/uni_modules/uts-tests/utssdk/TInt8Array.uts @@ -8,7 +8,8 @@ import { export class TInt8Array { test() { - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB + this.testConstructor(); this.testSet(); this.testCopyWith(); @@ -35,7 +36,8 @@ export class TInt8Array { //#endif } - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB + testConstructor() { let buffer = new ArrayBuffer(16); let int8View = new Int8Array(buffer); diff --git a/uni_modules/uts-tests/utssdk/TUInt8Array.uts b/uni_modules/uts-tests/utssdk/TUInt8Array.uts index f93f855..8297d89 100644 --- a/uni_modules/uts-tests/utssdk/TUInt8Array.uts +++ b/uni_modules/uts-tests/utssdk/TUInt8Array.uts @@ -7,7 +7,8 @@ import { export class TUint8Array { test() { - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB + this.testMAX(); this.testConstructor(); this.testSet(); @@ -34,7 +35,8 @@ export class TUint8Array { this.arrayBufferSlice(); // #endif } - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB + from() { var s = new Set([1, 2, 3]); var unit8 = Uint8Array.from(s); @@ -314,11 +316,11 @@ export class TUint8Array { element < 10 ) expect(res).toEqual(true); - console.log('uint8',res) + console.log('uint8', res) res = positives.some((element : number, index : number, array : Uint8Array) : boolean => element < 0 ) - console.log('uint8',res) + console.log('uint8', res) expect(res).toEqual(false); // #END } diff --git a/uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts b/uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts index 4dfdaee..1f89f79 100644 --- a/uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts +++ b/uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts @@ -7,7 +7,8 @@ import { export class TUint8ClampedArray { test() { - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB + this.testMAX(); this.testConstructor(); this.testSet(); @@ -35,7 +36,8 @@ export class TUint8ClampedArray { // #endif } - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB + testMAX() { let uint8Clamped = new Uint8ClampedArray(16); uint8Clamped[0] = 255; @@ -291,7 +293,7 @@ export class TUint8ClampedArray { } arrayBufferSlice() { - + // #TEST ArrayBuffer.slice let buffer = new ArrayBuffer(16); let uint8Clamped = new Uint8ClampedArray(buffer); diff --git a/uni_modules/uts-tests/utssdk/TUint16Array.uts b/uni_modules/uts-tests/utssdk/TUint16Array.uts index 73f87a5..0711706 100644 --- a/uni_modules/uts-tests/utssdk/TUint16Array.uts +++ b/uni_modules/uts-tests/utssdk/TUint16Array.uts @@ -7,7 +7,7 @@ import { export class TUint16Array { test() { - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB this.testuint16(); this.testConstructor(); this.testSet(); @@ -35,7 +35,7 @@ export class TUint16Array { // #endif } - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB testuint16() { let uint16 = new Uint16Array(2); uint16[0] = 42; @@ -305,7 +305,7 @@ export class TUint16Array { } arrayBufferSlice() { - + // #TEST Uint16Array.arrayBufferSlice let buffer = new ArrayBuffer(16); let uint16 = new Uint16Array(buffer); @@ -316,7 +316,7 @@ export class TUint16Array { let sliced = new Uint16Array(res); expect(sliced[0]).toEqual(42); // #END - + } testSome() { // #TEST Uint16Array.some @@ -334,5 +334,4 @@ export class TUint16Array { // #END } // #endif - } \ No newline at end of file diff --git a/uni_modules/uts-tests/utssdk/TUint32Array.uts b/uni_modules/uts-tests/utssdk/TUint32Array.uts index 096e95a..7185744 100644 --- a/uni_modules/uts-tests/utssdk/TUint32Array.uts +++ b/uni_modules/uts-tests/utssdk/TUint32Array.uts @@ -7,7 +7,8 @@ import { export class TUint32Array { test() { - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB + this.testuint32(); this.testConstructor(); this.testSet(); @@ -35,7 +36,7 @@ export class TUint32Array { // #endif } - // #ifndef APP-IOS + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB testuint32() { let uint32 = new Uint32Array(2); uint32[0] = 42; @@ -299,7 +300,7 @@ export class TUint32Array { } arrayBufferSlice() { - + // #TEST ArrayBuffer.slice let buffer = new ArrayBuffer(16); let uint32 = new Uint32Array(buffer); @@ -310,7 +311,7 @@ export class TUint32Array { let sliced = new Uint32Array(res); expect(sliced[1]).toEqual(42); // #END - + } testSome() { // #TEST Uint32Array.some diff --git a/uni_modules/uts-tests/utssdk/index.uts b/uni_modules/uts-tests/utssdk/index.uts index d87f3b2..023231e 100644 --- a/uni_modules/uts-tests/utssdk/index.uts +++ b/uni_modules/uts-tests/utssdk/index.uts @@ -41,7 +41,10 @@ export function runTests() : UTSJSONObject { const JSONLargeRes = testJSONLarge(); const consoleRes = testConsole(); const UTSJSONObjectRes = testUTSJSONObject(); + + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB const ArrayBufferRes = testArrayBuffer(); + // #endif const NativeCodeRes = testNativeCode(); return { Array: ArrayRes, @@ -62,7 +65,9 @@ export function runTests() : UTSJSONObject { Type: TypeRes, console:consoleRes, UTSJSONObject:UTSJSONObjectRes, + // #ifdef (UNI-APP-X && APP-ANDROID) || WEB ArrayBuffer:ArrayBufferRes, + // #endif NativeCode:NativeCodeRes } } \ No newline at end of file -- GitLab