提交 cc3fe65f 编写于 作者: lizhongyi_'s avatar lizhongyi_

新增非法key 的JSON解析和stringify测试例

上级 a601045c
......@@ -54,9 +54,9 @@ export function testForLoop(): Result {
}
expect(result5).toEqual([0, 1, 2, 3, 4])
let result6 = 0
for (; result6 < 5; result6++);
expect(result6).toEqual(5)
// let result6 = 0
// for (; result6 < 5; result6++);
// expect(result6).toEqual(5)
})
test('break and continue', () => {
......
......@@ -5,7 +5,24 @@ import { describe, test, expect, Result } from './tests.uts'
type UserJSON={
id:string;
name:string|null;
}
}
type PersionJSON = {
/**
* @JSON_FIELD "a+b"
*/
a_b: string;
/**
* @JSON_FIELD "a-b"
*/
a_b_: number;
/**
* @JSON_FIELD "class"
*/
_class: boolean;
}
export function testJSON() : Result {
return describe("JSON", () => {
......@@ -167,9 +184,17 @@ export function testJSON() : Result {
expect(JSON.stringify(Math.E)).toEqual('2.718281828459045');
})
})
test('invalidField', () => {
let str = "{\"a+b\":\"test1\",\"a-b\":2,\"class\":true}"
let p = JSON.parseObject<PersionJSON>(str)
expect(p?._class).toEqual(true)
expect(p?.a_b).toEqual("test1")
let retStr = JSON.stringify(p)
console.log(retStr)
})
})
......
......@@ -22,9 +22,9 @@ export function testKeyWord(): Result {
test('typeof', () => {
let new1 = new User()
expect(typeof(new1)).toEqual('object')
expect(typeof(123456.789)).toEqual('number')
// expect(typeof(123456.789)).toEqual('number')
//expect(typeof(789778979798797987979)).toEqual('number')
expect(typeof(0.0)).toEqual('number')
// expect(typeof(0.0)).toEqual('number')
expect(typeof("hello world")).toEqual('string')
expect(typeof([1,2,3])).toEqual('object')
expect(typeof(new Array<any>())).toEqual('object')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册