Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
41826fa8
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1598
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看板
提交
41826fa8
编写于
11月 29, 2023
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 修改条件编译屏蔽web端不支持的测试例
上级
0c4c6829
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
306 addition
and
290 deletion
+306
-290
.editorconfig
.editorconfig
+12
-0
uni_modules/uts-tests/utssdk/KeyWord.uts
uni_modules/uts-tests/utssdk/KeyWord.uts
+129
-124
uni_modules/uts-tests/utssdk/Number.uts
uni_modules/uts-tests/utssdk/Number.uts
+165
-166
未找到文件。
.editorconfig
0 → 100644
浏览文件 @
41826fa8
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
\ No newline at end of file
uni_modules/uts-tests/utssdk/KeyWord.uts
浏览文件 @
41826fa8
import { describe, test, expect, Result } from './tests.uts'
import { describe, test, expect, Result } from './tests.uts'
class User{
class User
{
name:
string = "";
name :
string = "";
age:
number = 0
age :
number = 0
}
}
const passcode = "secret passcode";
const passcode = "secret passcode";
class Parent {
class Parent {
private _name
: string = ""; // private是私有的,外部不能访问
private _name
: string = ""; // private是私有的,外部不能访问
get name()
: string { // 读取name会触发此拦截器
get name()
: string { // 读取name会触发此拦截器
console.log("start to get parent.name");
console.log("start to get parent.name");
return this._name;
return this._name;
}
}
set name(newName
: string) { // 给name赋值会触发此拦截器
set name(newName
: string) { // 给name赋值会触发此拦截器
console.log("start to set parent.name");
console.log("start to set parent.name");
if (passcode == "secret passcode") { // 校验是否有权修改name的值,这里的条件可以修改以方便测试
if (passcode == "secret passcode") { // 校验是否有权修改name的值,这里的条件可以修改以方便测试
this._name = newName;
this._name = newName;
} else {
} else {
console.log("Error: set parent.name fail");
console.log("Error: set parent.name fail");
}
}
}
}
// 静态属性和方法
// 静态属性和方法
static age
: number = 30
static age
: number = 30
static run()
: string {
static run()
: string {
console.log("this is a static method")
console.log("this is a static method")
return "static method"
return "static method"
}
}
// readonly
// readonly
readonly address
: string = ""
readonly address
: string = ""
weight
: number = 80
weight
: number = 80
// constructor
// constructor
constructor(weight
: number) {
constructor(weight
: number) {
console.log("开始实例化")
console.log("开始实例化")
this.weight = weight
this.weight = weight
}
}
// 实例方法
// 实例方法
eat()
: string {
eat()
: string {
console.log("this is parent")
console.log("this is parent")
return "parent instance method"
return "parent instance method"
}
}
}
}
class ChildrenTest extends Parent {
class ChildrenTest extends Parent {
// override constructor(weight: number) {
// override constructor(weight: number) {
// super(weight)
// super(weight)
// }
// }
override eat()
: string {
override eat()
: string {
super.eat()
super.eat()
return "children instance method"
return "children instance method"
}
}
// swift 中不能重写父类的存储属性,只能重写父类的计算的属性(本质上是重写计算属性的get set方法)
// swift 中不能重写父类的存储属性,只能重写父类的计算的属性(本质上是重写计算属性的get set方法)
// #ifndef APP-IOS
// #ifndef APP-IOS
override weight = 8
override weight = 8
// #endif
// #endif
}
}
export function testKeyWord(): Result {
export function testKeyWord() : Result {
return describe("KeyWord", () => {
return describe("KeyWord", () => {
test('new', () => {
test('new', () => {
let new1 = new User()
let new1 = new User()
// expect(JSON.stringify(new1)).toEqual('{"age":0,"name":""}')
// expect(JSON.stringify(new1)).toEqual('{"age":0,"name":""}')
console.log(JSON.stringify(new1))
console.log(JSON.stringify(new1))
new1.age = 10
new1.age = 10
new1.name = "job"
new1.name = "job"
console.log(JSON.stringify(new1))
console.log(JSON.stringify(new1))
// expect(JSON.stringify(new1)).toEqual('{"age":10,"name":"job"}')
// expect(JSON.stringify(new1)).toEqual('{"age":10,"name":"job"}')
})
test('typeof', () => {
let new1 = new User()
expect(typeof(new1)).toEqual('object')
expect(typeof(123456.789)).toEqual('Double')
//expect(typeof(789778979798797987979)).toEqual('number')
expect(typeof(0.0)).toEqual('Double')
expect(typeof("hello world")).toEqual('string')
expect(typeof([1,2,3])).toEqual('object')
expect(typeof(new Array<any>())).toEqual('object')
expect(typeof(new Set<any>())).toEqual('object')
// expect(typeof(new Map<any,any>())).toEqual('object')
expect(typeof(new Date())).toEqual('object')
expect(typeof("hello world")).toEqual('string')
// 原生对象
// #ifndef APP-IOS
expect(typeof(UTSAndroid.getUniActivity())).toEqual('object')
// #endif
})
test('instanceof', () => {
let user1:any = new User()
let instanceRet1 = user1 instanceof User
expect(instanceRet1).toEqual(true)
let instanceRet2 = (typeof user1) == "string"
expect(instanceRet2).toEqual(false)
let num1:any = 3.1415926
let instanceRet3 = (typeof num1) == "string"
expect(instanceRet3).toEqual(false)
let instanceRet4 = (typeof num1) == "number"
expect(instanceRet4).toEqual(false)
})
test('isArray', () => {
let user1:any = new User()
expect(Array.isArray(user1)).toEqual(false)
expect(Array.isArray([1,2,3])).toEqual(true)
})
test('class', () => {
let p = new Parent(20)
p.name = "tom" // 会打印"start to set person.name"
console.log(p.name); // 先打印"start to get person.name",然后打印"tom"
expect(Parent.age).toEqual(30)
expect(Parent.run()).toEqual("static method")
expect(p.eat()).toEqual("parent instance method")
// let c = new ChildrenTest(0)
// expect(c.eat()).toEqual("children instance method")
})
})
})
}
test('typeof', () => {
let new1 = new User()
expect(typeof (new1)).toEqual('object')
// #ifdef APP-ANDROID || APP-IOS
expect(typeof (123456.789)).toEqual('Double')
//expect(typeof(789778979798797987979)).toEqual('number')
expect(typeof (0.0)).toEqual('Double')
// #endif
expect(typeof ("hello world")).toEqual('string')
expect(typeof ([1, 2, 3])).toEqual('object')
expect(typeof (new Array<any>())).toEqual('object')
expect(typeof (new Set<any>())).toEqual('object')
// expect(typeof(new Map<any,any>())).toEqual('object')
expect(typeof (new Date())).toEqual('object')
expect(typeof ("hello world")).toEqual('string')
// 原生对象
// #ifdef APP-ANDROID
expect(typeof (UTSAndroid.getUniActivity())).toEqual('object')
// #endif
})
test('instanceof', () => {
let user1 : any = new User()
let instanceRet1 = user1 instanceof User
expect(instanceRet1).toEqual(true)
let instanceRet2 = (typeof user1) == "string"
expect(instanceRet2).toEqual(false)
let num1 : any = 3.1415926
let instanceRet3 = (typeof num1) == "string"
expect(instanceRet3).toEqual(false)
// #ifdef APP-ANDROID
let instanceRet4 = (typeof num1) == "number"
expect(instanceRet4).toEqual(false)
// #endif
})
test('isArray', () => {
let user1 : any = new User()
expect(Array.isArray(user1)).toEqual(false)
expect(Array.isArray([1, 2, 3])).toEqual(true)
})
test('class', () => {
let p = new Parent(20)
p.name = "tom" // 会打印"start to set person.name"
console.log(p.name); // 先打印"start to get person.name",然后打印"tom"
expect(Parent.age).toEqual(30)
expect(Parent.run()).toEqual("static method")
expect(p.eat()).toEqual("parent instance method")
// let c = new ChildrenTest(0)
// expect(c.eat()).toEqual("children instance method")
})
})
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/Number.uts
浏览文件 @
41826fa8
import { describe, test, expect, Result } from './tests.uts'
import { describe, test, expect, Result } from './tests.uts'
export function testNumber(): Result {
export function testNumber() : Result {
return describe("Number", () => {
return describe("Number", () => {
test('toFixed', () => {
test('toFixed', () => {
function financial(x: Number): String {
function financial(x : Number) : String {
return x.toFixed(2);
return x.toFixed(2);
}
}
expect(financial(123.456)).toEqual('123.46');
expect(financial(123.456)).toEqual('123.46');
expect(financial(0.004)).toEqual("0.00");
expect(financial(0.004)).toEqual("0.00");
expect(financial(0)).toEqual("0.00");
expect(financial(0)).toEqual("0.00");
expect(financial(1)).toEqual("1.00");
expect(financial(1)).toEqual("1.00");
let num1: number = -1.1 / 0.1
let num1 : number = -1.1 / 0.1
let num2: number = -1.1 / 0.1
let num2 : number = -1.1 / 0.1
let num3: number = -1.1 / -0.1
let num3 : number = -1.1 / -0.1
console.warn(num1)
console.warn(num1)
console.warn(num2)
console.warn(num2)
console.warn(num3)
console.warn(num3)
let obj = {"id":"3be2c600-894c-4231-aa56-82fd989cc961","result":{"result":[num1, num2, num3]}}
let obj = { "id": "3be2c600-894c-4231-aa56-82fd989cc961", "result": { "result": [num1, num2, num3] } }
console.log(JSON.stringify(obj))
console.log(JSON.stringify(obj))
// #ifndef APP-IOS
expect(123456.789.toFixed(2)).toEqual("123456.79");
// android 专有数据类型
expect(12345600123.789123.toFixed(2)).toEqual("12345600123.79");
expect(123456.789.toFixed(2)).toEqual("123456.79");
expect((-123456.789).toFixed(5)).toEqual("-123456.78900");
expect(12345600123.789123.toFixed(2)).toEqual("12345600123.79");
expect(parseFloat("16688995566.369").toFixed(3)).toEqual("16688995566.369");
expect((-123456.789).toFixed(5)).toEqual("-123456.78900");
// #ifndef APP-ANDROID
expect(parseFloat("16688995566.369").toFixed(3)).toEqual("16688995566.369");
// android 专有数据类型
let a1 = 56
let a1 = 56
let a2 = -122
let a2 = -122
expect(a1.toByte().toFixed(2)).toEqual("56.00");
expect(a1.toByte().toFixed(2)).toEqual("56.00");
expect(a2.toByte().toFixed(2)).toEqual("-122.00");
expect(a2.toByte().toFixed(2)).toEqual("-122.00");
expect(a1.toShort().toFixed(5)).toEqual("56.00000");
expect(a1.toShort().toFixed(5)).toEqual("56.00000");
expect(a2.toShort().toFixed(5)).toEqual("-122.00000");
expect(a2.toShort().toFixed(5)).toEqual("-122.00000");
// #endif
// #endif
/**
/**
* add since 2023-11-21
* add since 2023-11-21
* 发现部分场景在android 6 以下与web有差异,新增以下示例
* 发现部分场景在android 6 以下与web有差异,新增以下示例
*/
*/
let r = 2.449999999999999999;
let r = 2.449999999999999999;
let t1 = r.toFixed(1);
let t1 = r.toFixed(1);
expect(t1).toEqual("2.5");
expect(t1).toEqual("2.5");
let r2 = 2.4499999999999999;
let r2 = 2.4499999999999999;
let t2 = r2.toFixed(1);
let t2 = r2.toFixed(1);
expect(t2).toEqual("2.4");
expect(t2).toEqual("2.4");
let r3 = -9007199254740991;
let r3 = -9007199254740991;
let t3 = r3.toFixed(15);
let t3 = r3.toFixed(15);
expect(t3).toEqual("-9007199254740991.000000000000000");
expect(t3).toEqual("-9007199254740991.000000000000000");
})
})
test('isFinite', () => {
test('isFinite', () => {
expect(isFinite(1000 / 1)).toEqual(true);
expect(isFinite(1000 / 1)).toEqual(true);
expect(isFinite(910)).toEqual(true);
expect(isFinite(910)).toEqual(true);
expect(isFinite(0)).toEqual(true);
expect(isFinite(0)).toEqual(true);
})
})
test('isInteger', () => {
test('isInteger', () => {
expect(Number.isInteger(12)).toEqual(true);
expect(Number.isInteger(12)).toEqual(true);
expect(Number.isInteger(12.01)).toEqual(false);
expect(Number.isInteger(12.01)).toEqual(false);
expect(Number.isInteger(-213123112.01)).toEqual(false);
expect(Number.isInteger(-213123112.01)).toEqual(false);
expect(Number.isInteger(-213123112)).toEqual(true);
expect(Number.isInteger(-213123112)).toEqual(true);
})
})
test('isNaN', () => {
test('isNaN', () => {
expect(isNaN(0)).toEqual(false);
expect(isNaN(0)).toEqual(false);
})
})
test('toPrecision', () => {
test('toPrecision', () => {
expect(123.456.toPrecision(4)).toEqual("123.5");
expect(123.456.toPrecision(4)).toEqual("123.5");
expect(0.004.toPrecision(4)).toEqual("0.004000");
expect(0.004.toPrecision(4)).toEqual("0.004000");
// expect(1.23e5.toPrecision(4)).toEqual("1.230e+5");
// expect(1.23e5.toPrecision(4)).toEqual("1.230e+5");
})
})
test('toString', () => {
test('toString', () => {
expect((10).toString()).toEqual("10");
expect((10).toString()).toEqual("10");
expect((17).toString()).toEqual("17");
expect((17).toString()).toEqual("17");
expect((17.2).toString()).toEqual("17.2");
expect((17.2).toString()).toEqual("17.2");
expect((6).toString(2)).toEqual("110");
expect((6).toString(2)).toEqual("110");
expect((254).toString(16)).toEqual("fe");
expect((254).toString(16)).toEqual("fe");
expect((-10).toString(2)).toEqual("-1010");
expect((-10).toString(2)).toEqual("-1010");
expect((-0xff).toString(2)).toEqual("-11111111");
expect((-0xff).toString(2)).toEqual("-11111111");
})
})
test('valueOf', () => {
test('valueOf', () => {
expect((10).valueOf()).toEqual(10);
expect((10).valueOf()).toEqual(10);
expect((-10.2).valueOf()).toEqual(-10.2);
expect((-10.2).valueOf()).toEqual(-10.2);
expect((0xf).valueOf()).toEqual(15);
expect((0xf).valueOf()).toEqual(15);
})
// 数据转换操作示例
test('toX', () => {
let num = 10.123
expect(num.toInt()).toEqual(10);
expect(num.toDouble()).toEqual(10.123);
})
test('numberEquals', () => {
let a1 = 10.123
let b1 = 10.12300
let c1 = 10.12300002
expect(a1 == b1).toEqual(true);
expect(a1 === b1).toEqual(true);
expect(a1 !== 10.123001).toEqual(true);
expect(a1 != c1).toEqual(true);
let a2 = 0
let b2 = 0.0
expect(a2 == b2).toEqual(true);
expect(a2 === b2).toEqual(true);
let a3 = -1000
let b3 = -1000.0
expect(a3 == b3).toEqual(true);
expect(a3 === b3).toEqual(true);
let a4 = 123456789123456
let b4 = 123456789123456.0
expect(a4 == b4).toEqual(true);
expect(a4 === b4 * 1.0).toEqual(true);
let a5 = -123456789123456
let b5 = -123456789123456.01
expect(a5 != b5).toEqual(true);
expect(a5 !== b5).toEqual(true);
let a6 = 246.0 / 123 * 1.0
let b6 = 2
let c6 = 2.0
expect(a6 == b6).toEqual(true);
expect(b6 === c6).toEqual(true);
expect(b6 !== c6 * 1.001).toEqual(true);
expect(b6 != c6 * 1.001).toEqual(true);
let a7 = -10 * 123.2
let b7 = - 1232
expect(a7 == b7).toEqual(true);
expect(a7 != b7 * -1).toEqual(true);
let a8 = -101 * 123.201
expect(a8 == -12443.301).toEqual(true);
expect(a8 === -12443.301).toEqual(true);
expect(a8 !== -12443.301 * 0.999).toEqual(true);
expect(a8 != -12443.301 * 0.999999).toEqual(true);
let a9 = -0.02 * -123456
expect(a9 == 2469.12).toEqual(true);
expect(a9 === 2469.12).toEqual(true);
expect(a9 != 2469.1201).toEqual(true);
let a10 = 123456789123456.123456789123456
let b10 = 123456789123456.123456789123456000000
expect(a10 == b10).toEqual(true);
expect(a10 === b10).toEqual(true);
})
})
})
}
// 数据转换操作示例
test('toX', () => {
let num = 10.123
expect(num.toInt()).toEqual(10);
expect(num.toDouble()).toEqual(10.123);
})
test('numberEquals', () => {
let a1 = 10.123
let b1 = 10.12300
let c1 = 10.12300002
expect(a1 == b1).toEqual(true);
expect(a1 === b1).toEqual(true);
expect(a1 !== 10.123001).toEqual(true);
expect(a1 != c1).toEqual(true);
let a2 = 0
let b2 = 0.0
expect(a2 == b2).toEqual(true);
expect(a2 === b2).toEqual(true);
let a3 = -1000
let b3 = -1000.0
expect(a3 == b3).toEqual(true);
expect(a3 === b3).toEqual(true);
let a4 = 123456789123456
let b4 = 123456789123456.0
expect(a4 == b4).toEqual(true);
expect(a4 === b4 * 1.0).toEqual(true);
let a5 = -123456789123456
let b5 = -123456789123456.01
expect(a5 != b5).toEqual(true);
expect(a5 !== b5).toEqual(true);
let a6 = 246.0 / 123 * 1.0
let b6 = 2
let c6 = 2.0
expect(a6 == b6).toEqual(true);
expect(b6 === c6).toEqual(true);
expect(b6 !== c6 * 1.001).toEqual(true);
expect(b6 != c6 * 1.001).toEqual(true);
let a7 = -10 * 123.2
let b7 = - 1232
expect(a7 == b7).toEqual(true);
expect(a7 != b7 * -1).toEqual(true);
let a8 = -101 * 123.201
expect(a8 == -12443.301).toEqual(true);
expect(a8 === -12443.301).toEqual(true);
expect(a8 !== -12443.301 * 0.999).toEqual(true);
expect(a8 != -12443.301 * 0.999999).toEqual(true);
let a9 = -0.02 * -123456
expect(a9 == 2469.12).toEqual(true);
expect(a9 === 2469.12).toEqual(true);
expect(a9 != 2469.1201).toEqual(true);
let a10 = 123456789123456.123456789123456
let b10 = 123456789123456.123456789123456000000
expect(a10 == b10).toEqual(true);
expect(a10 === b10).toEqual(true);
})
})
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录