Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
77ecebe3
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1595
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
77ecebe3
编写于
8月 22, 2023
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加JSON parseObject测试示例
上级
e4aa0b50
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
111 addition
and
6 deletion
+111
-6
uni_modules/uts-advance/utssdk/app-android/index.uts
uni_modules/uts-advance/utssdk/app-android/index.uts
+1
-1
uni_modules/uts-tests/utssdk/Extapi.uts
uni_modules/uts-tests/utssdk/Extapi.uts
+70
-0
uni_modules/uts-tests/utssdk/JSON.uts
uni_modules/uts-tests/utssdk/JSON.uts
+34
-3
uni_modules/uts-tests/utssdk/index.uts
uni_modules/uts-tests/utssdk/index.uts
+6
-2
未找到文件。
uni_modules/uts-advance/utssdk/app-android/index.uts
浏览文件 @
77ecebe3
...
...
@@ -484,7 +484,7 @@ export function logDateCombineTest(){
*
*/
export function quitApp(){
UTSAndroid.
quitApp
()
UTSAndroid.
exit
()
}
export class User {
...
...
uni_modules/uts-tests/utssdk/Extapi.uts
0 → 100644
浏览文件 @
77ecebe3
import { describe, test, expect, Result } from './tests.uts'
export function testExtapi() : Result {
return describe("Storage", () => {
test('setStorage', () => {
uni.setStorage({
key: "dddddd",
data: 1,
complete: (res) => {
let ret = uni.getStorageSync("dddddd")
expect(ret).toEqual(1)
uni.setStorageSync("dddddd",3.14159265358)
ret = uni.getStorageSync("dddddd")
expect(ret).toEqual(3.14159265358)
}
})
uni.setStorage({
key: "dddddd",
data: true,
complete: (res) => {
console.log(res)
let ret = uni.getStorageSync("dddddd")
expect(ret).toEqual(true)
uni.setStorageSync("dddddd",false)
ret = uni.getStorageSync("dddddd")
expect(ret).toEqual(false)
}
})
uni.setStorage({
key: "dddddd",
data: "海上生明月,天涯共此时,情人怨遥夜,竟夕起相思。",
complete: (res) => {
console.log(res)
let ret = uni.getStorageSync("dddddd")
expect(ret).toEqual("海上生明月,天涯共此时,情人怨遥夜,竟夕起相思。")
uni.setStorageSync("dddddd","床前明月光,疑似地上霜")
ret = uni.getStorageSync("dddddd")
expect(ret).toEqual("床前明月光,疑似地上霜")
}
})
// IOS 打印对象乱序,暂时注释
// uni.setStorage({
// key: "dddddd",
// data: {
// "a": 1,
// "b": "2",
// "c": {
// "x": "1",
// "y": true
// }
// },
// complete: (res) => {
// let ret = uni.getStorageSync("dddddd")
// console.log(ret)
// expect(JSON.stringify(ret)).toEqual('{"a":1,"b":"2","c":{"x":"1","y":true}}')
// }
// })
})
})
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/JSON.uts
浏览文件 @
77ecebe3
...
...
@@ -2,9 +2,9 @@ import { describe, test, expect, Result } from './tests.uts'
class User
{
name:string = ""
;
age:number = 12
;
type UserJSON=
{
id:string
;
name:string|null
;
}
export function testJSON() : Result {
...
...
@@ -73,6 +73,32 @@ export function testJSON() : Result {
// expect(JSON.parse('"foo"')!).toEqual("foo");
// expect(JSON.parse('null')!).toEqual(null);
})
test('parseObject', () => {
const json = `{"result":true, "count":42}`;
const obj = JSON.parseObject(json);
expect(obj!["count"]).toEqual(42);
expect(obj!["result"] as boolean).toEqual(true);
expect(JSON.parseObject('{}')!).toEqual({});
const json1 = `{
"name": "John",
"id": "30"
}`;
let obj2 = JSON.parseObject<UserJSON>(json1);
expect(obj2!!.id).toEqual("30");
const json2 = `{
"id": "30"
}`;
let obj3 = JSON.parseObject<UserJSON>(json2);
expect(obj3!!.id).toEqual("30");
const json3 = `{
"name": "John"
}`;
let obj4 = JSON.parseObject<UserJSON>(json3);
expect(obj4).toEqual(null);
})
test('stringify', () => {
const obj = { name: 'John', age: 30 };
const json = JSON.stringify(obj);
...
...
@@ -111,5 +137,10 @@ export function testJSON() : Result {
expect(JSON.stringify(Math.PI)).toEqual('3.141592653589793');
expect(JSON.stringify(Math.E)).toEqual('2.718281828459045');
})
})
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/index.uts
浏览文件 @
77ecebe3
...
...
@@ -3,6 +3,7 @@ import { testDate } from './Date.uts'
import { testString } from './String.uts'
import { testError } from './Error.uts'
import { testKeyWord } from './KeyWord.uts'
import { testExtapi } from './Extapi.uts'
import { testJSON } from './JSON.uts'
import { testNumber } from './Number.uts'
import { testMap } from './Map.uts'
...
...
@@ -29,7 +30,9 @@ export function runTests() : UTSJSONObject {
const OperatorsRes = testOperators();
const MathRes = testMath();
const RegExpRes = testRegExp();
const KeyWordRes = testKeyWord();
const KeyWordRes = testKeyWord();
const extapiRes = testExtapi();
// #ifdef APP-ANDROID
// const ReactiveArrayRes = testReactiveArray();
// const ReactiveMapRes = testReactiveMap();
...
...
@@ -53,6 +56,7 @@ export function runTests() : UTSJSONObject {
Operators: OperatorsRes,
Math: MathRes,
RegExp: RegExpRes,
KeyWord:KeyWordRes
KeyWord:KeyWordRes,
extapi:extapiRes
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录