提交 26920330 编写于 作者: 雪洛's avatar 雪洛

feat: 修改条件编译屏蔽web端不支持的测试例

上级 49ecc180
# 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
import { describe, test, expect, Result } from './tests.uts'
class User{
name:string = "";
age:number = 0
class User {
name : string = "";
age : number = 0
}
const passcode = "secret passcode";
class Parent {
private _name: string = ""; // private是私有的,外部不能访问
get name(): string { // 读取name会触发此拦截器
private _name : string = ""; // private是私有的,外部不能访问
get name() : string { // 读取name会触发此拦截器
console.log("start to get parent.name");
return this._name;
}
set name(newName: string) { // 给name赋值会触发此拦截器
set name(newName : string) { // 给name赋值会触发此拦截器
console.log("start to set parent.name");
if (passcode == "secret passcode") { // 校验是否有权修改name的值,这里的条件可以修改以方便测试
this._name = newName;
......@@ -22,25 +22,25 @@ class Parent {
}
// 静态属性和方法
static age: number = 30
static run(): string {
static age : number = 30
static run() : string {
console.log("this is a static method")
return "static method"
}
// readonly
readonly address: string = ""
readonly address : string = ""
weight: number = 80
weight : number = 80
// constructor
constructor(weight: number) {
constructor(weight : number) {
console.log("开始实例化")
this.weight = weight
}
// 实例方法
eat(): string {
eat() : string {
console.log("this is parent")
return "parent instance method"
}
......@@ -53,7 +53,7 @@ class ChildrenTest extends Parent {
// super(weight)
// }
override eat(): string {
override eat() : string {
super.eat()
return "children instance method"
}
......@@ -64,7 +64,7 @@ class ChildrenTest extends Parent {
// #endif
}
export function testKeyWord(): Result {
export function testKeyWord() : Result {
return describe("KeyWord", () => {
test('new', () => {
......@@ -81,21 +81,24 @@ export function testKeyWord(): Result {
test('typeof', () => {
let new1 = new User()
expect(typeof(new1)).toEqual('object')
expect(typeof(123456.789)).toEqual('Double')
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')
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 ("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')
expect(typeof (new Date())).toEqual('object')
expect(typeof ("hello world")).toEqual('string')
// 原生对象
// #ifndef APP-IOS
expect(typeof(UTSAndroid.getUniActivity())).toEqual('object')
// #ifdef APP-ANDROID
expect(typeof (UTSAndroid.getUniActivity())).toEqual('object')
// #endif
......@@ -103,22 +106,24 @@ export function testKeyWord(): Result {
test('instanceof', () => {
let user1:any = new User()
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 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()
let user1 : any = new User()
expect(Array.isArray(user1)).toEqual(false)
expect(Array.isArray([1,2,3])).toEqual(true)
expect(Array.isArray([1, 2, 3])).toEqual(true)
})
test('class', () => {
......
import { describe, test, expect, Result } from './tests.uts'
export function testNumber(): Result {
export function testNumber() : Result {
return describe("Number", () => {
test('toFixed', () => {
function financial(x: Number): String {
function financial(x : Number) : String {
return x.toFixed(2);
}
expect(financial(123.456)).toEqual('123.46');
......@@ -12,23 +12,23 @@ export function testNumber(): Result {
expect(financial(0)).toEqual("0.00");
expect(financial(1)).toEqual("1.00");
let num1: number = -1.1 / 0.1
let num2: number = -1.1 / 0.1
let num3: number = -1.1 / -0.1
let num1 : number = -1.1 / 0.1
let num2 : number = -1.1 / 0.1
let num3 : number = -1.1 / -0.1
console.warn(num1)
console.warn(num2)
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))
// #ifndef APP-IOS
// android 专有数据类型
expect(123456.789.toFixed(2)).toEqual("123456.79");
expect(12345600123.789123.toFixed(2)).toEqual("12345600123.79");
expect((-123456.789).toFixed(5)).toEqual("-123456.78900");
expect(parseFloat("16688995566.369").toFixed(3)).toEqual("16688995566.369");
// #ifndef APP-ANDROID
let a1 = 56
let a2 = -122
expect(a1.toByte().toFixed(2)).toEqual("56.00");
......@@ -36,7 +36,6 @@ export function testNumber(): Result {
expect(a1.toShort().toFixed(5)).toEqual("56.00000");
expect(a2.toShort().toFixed(5)).toEqual("-122.00000");
// #endif
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册