import { describe, test, expect, expectNumber, Result } from './tests.uts' export function testUTSJSONObject() : Result { return describe("utsjsonobject", () => { test('keys', () => { let obj = { name:"zhangsan", age:11 } expect(UTSJSONObject.keys(obj).length).toEqual(2); console.log(UTSJSONObject.keys(obj)) }) test('assign-notype', () => { // #ifdef APP-ANDROID const target = { a: 1, b: 2 }; const source = { b: 4, c: 5 }; const returnedTarget = UTSJSONObject.assign(target, source); expect(returnedTarget.toMap().size).toEqual(3); type A = { username:"张三", age:12 } type C = { work:0.001 } let b = UTSJSONObject.assign(new A("张三",12),{b:2},new C(0.002)) expect(b['age']).toEqual(12); expect(b['username']).toEqual("张三"); expect(b['b']).toEqual(2); expect(b['work']).toEqual(0.002); // #endif }) test('setvalue-after-get', () => { // #ifdef APP-ANDROID let obj = { "cars":[ { name:"car1", value:100 } ] } let cars = obj.getArray("cars") cars![0].set("value",20) let firstCar = obj.getJSON("cars[0]") expect(firstCar!['value']).toEqual(20); // #endif }) test('assign-withtype', () => { // #ifdef APP-ANDROID type User = { a:number b:number } const target = { a: 1, b: 2 }; const source = { b: 4, c: 5 }; const returnedTarget = UTSJSONObject.assign(target, source); expect(returnedTarget!.a).toEqual(1); console.log(returnedTarget) // #endif }) }) }