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

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

上级 a601045c
...@@ -54,9 +54,9 @@ export function testForLoop(): Result { ...@@ -54,9 +54,9 @@ export function testForLoop(): Result {
} }
expect(result5).toEqual([0, 1, 2, 3, 4]) expect(result5).toEqual([0, 1, 2, 3, 4])
let result6 = 0 // let result6 = 0
for (; result6 < 5; result6++); // for (; result6 < 5; result6++);
expect(result6).toEqual(5) // expect(result6).toEqual(5)
}) })
test('break and continue', () => { test('break and continue', () => {
......
...@@ -7,6 +7,23 @@ type UserJSON={ ...@@ -7,6 +7,23 @@ type UserJSON={
name:string|null; 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 { export function testJSON() : Result {
return describe("JSON", () => { return describe("JSON", () => {
test('parse', () => { test('parse', () => {
...@@ -169,7 +186,15 @@ export function testJSON() : Result { ...@@ -169,7 +186,15 @@ export function testJSON() : Result {
}) })
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 { ...@@ -22,9 +22,9 @@ export function testKeyWord(): Result {
test('typeof', () => { test('typeof', () => {
let new1 = new User() let new1 = new User()
expect(typeof(new1)).toEqual('object') expect(typeof(new1)).toEqual('object')
expect(typeof(123456.789)).toEqual('number') // expect(typeof(123456.789)).toEqual('number')
//expect(typeof(789778979798797987979)).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("hello world")).toEqual('string')
expect(typeof([1,2,3])).toEqual('object') expect(typeof([1,2,3])).toEqual('object')
expect(typeof(new Array<any>())).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.
先完成此消息的编辑!
想要评论请 注册