提交 238829ab 编写于 作者: 雪洛's avatar 雪洛

test: 增加{}.toMap用法测试,格式化代码

上级 328f6668
import { describe, test, expect,expectNumber, Result } from './tests.uts'
import { describe, test, expect, expectNumber, Result } from './tests.uts'
type UserJSON={
id:string;
name:string|null;
type UserJSON = {
id : string;
name : string | null;
}
type PersonJSON = {
/**
* @JSON_FIELD "a+b"
*/
a_b: string;
a_b : string;
/**
* @JSON_FIELD "a-b"
*/
a_b_: number;
a_b_ : number;
/**
* @JSON_FIELD "class"
*/
_class: boolean;
_class : boolean;
}
......@@ -112,7 +112,7 @@ export function testJSON() : Result {
expect(obj4?.getNumber('data[1].a')).toEqual(2)
expect(obj4?.getBoolean('data[2][0].b')).toEqual(true)
expect(obj4?.getAny('data[1].a')).toEqual(2)
expect(obj4?.getJSON('data[2][1]')).toEqual({"b":"test"})
expect(obj4?.getJSON('data[2][1]')).toEqual({ "b": "test" })
expect(obj4?.getArray('data[3]')).toEqual([1, 2, 3])
})
......@@ -145,11 +145,11 @@ export function testJSON() : Result {
test('parseArray', () => {
const json1 = `[1,2,3]`;
const array1 = JSON.parseArray(json1);
expect(array1).toEqual([1,2,3]);
expect(array1).toEqual([1, 2, 3]);
const json2 = `[1,"hello world",3]`;
const array2 = JSON.parseArray(json2);
expect(array2).toEqual([1,"hello world",3]);
expect(array2).toEqual([1, "hello world", 3]);
const json3 = `[{"name":"John","id":"30"},{"name":"jack","id":"21"}]`;
......@@ -178,10 +178,10 @@ export function testJSON() : Result {
// const obj4 = { name: 'John', age: 30 };
// const json4 = JSON.stringify(obj4, null, 4);
// expect(json4).toEqual(`{
// "name": "John",
// "age": 30
// }`);
// expect(json4).toEqual(`{
// "name": "John",
// "age": 30
// }`);
// expect(JSON.stringify({ x: 5, y: 6 })).toEqual(`{"x":5,"y":6}`);
expect(JSON.stringify([3, 'false', false])).toEqual(`[3,"false",false]`);
expect(JSON.stringify({})).toEqual('{}');
......@@ -221,9 +221,9 @@ export function testJSON() : Result {
// expect(ret).toEqual('{"$db":[{"$method":"collection","$param":["type"]},{"$method":"add","$param":[[{"num":2,"tag":"default-tag"},{"num":3,"tag":"default-tag"}]]}]}')
type Msg = {
id: string,
method: string,
params: any
id : string,
method : string,
params : any
}
// type CallUniMethodParams = {
// method : string
......@@ -241,9 +241,9 @@ export function testJSON() : Result {
class Stage {
$m: string
$p: Array<any>
constructor(){
$m : string
$p : Array<any>
constructor() {
this.$m = 'test'
this.$p = ['type']
}
......@@ -257,7 +257,7 @@ export function testJSON() : Result {
// expect(JSON.stringify(obj22)).toEqual('{"data":[{}]}')
type A = {
inserted: number
inserted : number
}
const str = '{"inserted": 2}'
const obj33 = JSON.parse<A>(str)!
......@@ -282,19 +282,21 @@ export function testJSON() : Result {
test('UTSJSONOject', () => {
let t1 = "1"
const a = {
test(){
test() {
t1 = "2"
console.log("test")
}
};
//console.log(a['test']);
(a['test'] as ()=>void)()
(a['test'] as () => void)()
//console.log(t1);
expect(t1).toEqual("2")
//console.log(JSON.stringify(a));
const map = {
a: 1
}.toMap()
expect(map.get('a')).toEqual(1)
})
})
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册