提交 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={ type UserJSON = {
id:string; id : string;
name:string|null; name : string | null;
} }
type PersonJSON = { type PersonJSON = {
/** /**
* @JSON_FIELD "a+b" * @JSON_FIELD "a+b"
*/ */
a_b: string; a_b : string;
/** /**
* @JSON_FIELD "a-b" * @JSON_FIELD "a-b"
*/ */
a_b_: number; a_b_ : number;
/** /**
* @JSON_FIELD "class" * @JSON_FIELD "class"
*/ */
_class: boolean; _class : boolean;
} }
...@@ -112,7 +112,7 @@ export function testJSON() : Result { ...@@ -112,7 +112,7 @@ export function testJSON() : Result {
expect(obj4?.getNumber('data[1].a')).toEqual(2) expect(obj4?.getNumber('data[1].a')).toEqual(2)
expect(obj4?.getBoolean('data[2][0].b')).toEqual(true) expect(obj4?.getBoolean('data[2][0].b')).toEqual(true)
expect(obj4?.getAny('data[1].a')).toEqual(2) 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]) expect(obj4?.getArray('data[3]')).toEqual([1, 2, 3])
}) })
...@@ -145,11 +145,11 @@ export function testJSON() : Result { ...@@ -145,11 +145,11 @@ export function testJSON() : Result {
test('parseArray', () => { test('parseArray', () => {
const json1 = `[1,2,3]`; const json1 = `[1,2,3]`;
const array1 = JSON.parseArray(json1); const array1 = JSON.parseArray(json1);
expect(array1).toEqual([1,2,3]); expect(array1).toEqual([1, 2, 3]);
const json2 = `[1,"hello world",3]`; const json2 = `[1,"hello world",3]`;
const array2 = JSON.parseArray(json2); 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"}]`; const json3 = `[{"name":"John","id":"30"},{"name":"jack","id":"21"}]`;
...@@ -178,10 +178,10 @@ export function testJSON() : Result { ...@@ -178,10 +178,10 @@ export function testJSON() : Result {
// const obj4 = { name: 'John', age: 30 }; // const obj4 = { name: 'John', age: 30 };
// const json4 = JSON.stringify(obj4, null, 4); // const json4 = JSON.stringify(obj4, null, 4);
// expect(json4).toEqual(`{ // expect(json4).toEqual(`{
// "name": "John", // "name": "John",
// "age": 30 // "age": 30
// }`); // }`);
// expect(JSON.stringify({ x: 5, y: 6 })).toEqual(`{"x":5,"y":6}`); // 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([3, 'false', false])).toEqual(`[3,"false",false]`);
expect(JSON.stringify({})).toEqual('{}'); expect(JSON.stringify({})).toEqual('{}');
...@@ -221,9 +221,9 @@ export function testJSON() : Result { ...@@ -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"}]]}]}') // expect(ret).toEqual('{"$db":[{"$method":"collection","$param":["type"]},{"$method":"add","$param":[[{"num":2,"tag":"default-tag"},{"num":3,"tag":"default-tag"}]]}]}')
type Msg = { type Msg = {
id: string, id : string,
method: string, method : string,
params: any params : any
} }
// type CallUniMethodParams = { // type CallUniMethodParams = {
// method : string // method : string
...@@ -241,9 +241,9 @@ export function testJSON() : Result { ...@@ -241,9 +241,9 @@ export function testJSON() : Result {
class Stage { class Stage {
$m: string $m : string
$p: Array<any> $p : Array<any>
constructor(){ constructor() {
this.$m = 'test' this.$m = 'test'
this.$p = ['type'] this.$p = ['type']
} }
...@@ -257,7 +257,7 @@ export function testJSON() : Result { ...@@ -257,7 +257,7 @@ export function testJSON() : Result {
// expect(JSON.stringify(obj22)).toEqual('{"data":[{}]}') // expect(JSON.stringify(obj22)).toEqual('{"data":[{}]}')
type A = { type A = {
inserted: number inserted : number
} }
const str = '{"inserted": 2}' const str = '{"inserted": 2}'
const obj33 = JSON.parse<A>(str)! const obj33 = JSON.parse<A>(str)!
...@@ -282,19 +282,21 @@ export function testJSON() : Result { ...@@ -282,19 +282,21 @@ export function testJSON() : Result {
test('UTSJSONOject', () => { test('UTSJSONOject', () => {
let t1 = "1" let t1 = "1"
const a = { const a = {
test(){ test() {
t1 = "2" t1 = "2"
console.log("test") console.log("test")
} }
}; };
//console.log(a['test']); //console.log(a['test']);
(a['test'] as ()=>void)() (a['test'] as () => void)()
//console.log(t1); //console.log(t1);
expect(t1).toEqual("2") expect(t1).toEqual("2")
//console.log(JSON.stringify(a)); //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.
先完成此消息的编辑!
想要评论请 注册