UTSJSONObject.uts 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
import { describe, test, expect, expectNumber, Result } from './tests.uts'



export function testUTSJSONObject() : Result {
  return describe("utsjsonobject", () => {
    test('keys', () => {
      // #ifdef APP-ANDROID
        let obj = {
          name:"zhangsan",
          age:11
        }
        expect(UTSJSONObject.keys(obj).size).toEqual(2);
        console.log(UTSJSONObject.keys(obj))
      // #endif
    })
    
    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);
        console.log(returnedTarget)
      // #endif
    })
    
29
    test('setvalue-after-get', () => {
lizhongyi_'s avatar
lizhongyi_ 已提交
30
      // #ifdef APP-ANDROID
31 32 33 34 35 36 37 38
        let obj = {
          "cars":[
            {
              name:"car1",
              value:100
            }
          ]
        }
lizhongyi_'s avatar
lizhongyi_ 已提交
39
            
40 41 42 43
        let cars = obj.getArray<UTSJSONObject>("cars")
        cars![0].set("value",20)
        let firstCar = obj.getJSON("cars[0]")
        expect(firstCar!['value']).toEqual(20);
lizhongyi_'s avatar
lizhongyi_ 已提交
44
        // #endif
45 46
    })
    
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    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<User>(target, source);
        
        expect(returnedTarget!.a).toEqual(1);
        console.log(returnedTarget)
      // #endif
    })
  })
}