KeyWord.uts 3.5 KB
Newer Older
杜庆泉's avatar
杜庆泉 已提交
1 2 3 4 5 6 7 8
import { describe, test, expect, Result } from './tests.uts'

class User{
	name:string = "";
	age:number = 0
}

export function testKeyWord(): Result {
lizhongyi_'s avatar
lizhongyi_ 已提交
9
    return describe("KeyWord", () => {
杜庆泉's avatar
杜庆泉 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
		
		test('encodeURI', () => {
		   expect(encodeURI("你好")).toEqual('%E4%BD%A0%E5%A5%BD')
		   expect(encodeURI("你好+22")).toEqual('%E4%BD%A0%E5%A5%BD+22')
		   expect(encodeURI("你;/=好+22")).toEqual('%E4%BD%A0;/=%E5%A5%BD+22')
		   expect(encodeURI("https://demo.dcloud.net.cn/mock/最新/12")).toEqual('https://demo.dcloud.net.cn/mock/%E6%9C%80%E6%96%B0/12')
		})
		
		test('decodeURI', () => {
		   expect(decodeURI('%E4%BD%A0%E5%A5%BD')).toEqual('你好')
		   expect(decodeURI("%E4%BD%A0%E5%A5%BD+22")).toEqual('你好+22')
		   expect(decodeURI("%E4%BD%A0;/=%E5%A5%BD+22")).toEqual('你;/=好+22')
		   expect(decodeURI("https://demo.dcloud.net.cn/mock/%E6%9C%80%E6%96%B0/12")).toEqual('https://demo.dcloud.net.cn/mock/最新/12')
		})
		
		test('encodeURIComponent', () => {
		   expect(encodeURIComponent("你好")).toEqual('%E4%BD%A0%E5%A5%BD')
		   expect(encodeURIComponent("你好+22")).toEqual('%E4%BD%A0%E5%A5%BD%2B22')
		   expect(encodeURIComponent("你;/=好+22")).toEqual('%E4%BD%A0%3B%2F%3D%E5%A5%BD%2B22')
		   expect(encodeURIComponent("https://demo.dcloud.net.cn/mock/最新/12")).toEqual('https%3A%2F%2Fdemo.dcloud.net.cn%2Fmock%2F%E6%9C%80%E6%96%B0%2F12')
		})
		
		test('decodeURIComponent', () => {
		   expect(decodeURIComponent('%E4%BD%A0%E5%A5%BD')).toEqual('你好')
		   expect(decodeURIComponent('%E4%BD%A0%E5%A5%BD%2B22')).toEqual('你好+22')
		   expect(decodeURIComponent('%E4%BD%A0%3B%2F%3D%E5%A5%BD%2B22')).toEqual('你;/=好+22')
		   expect(decodeURIComponent("https://demo.dcloud.net.cn/mock/%E6%9C%80%E6%96%B0/12")).toEqual('https://demo.dcloud.net.cn/mock/最新/12')
		})
		
		
杜庆泉's avatar
杜庆泉 已提交
40 41
        test('new', () => {
           let new1 = new User()
lizhongyi_'s avatar
lizhongyi_ 已提交
42 43 44
		   // expect(JSON.stringify(new1)).toEqual('{"age":0,"name":""}')
		   console.log(JSON.stringify(new1))
		   
杜庆泉's avatar
杜庆泉 已提交
45 46
		   new1.age = 10
		   new1.name = "job"
lizhongyi_'s avatar
lizhongyi_ 已提交
47 48 49
		   console.log(JSON.stringify(new1))
		   // expect(JSON.stringify(new1)).toEqual('{"age":10,"name":"job"}')
		   
杜庆泉's avatar
杜庆泉 已提交
50 51 52
        })
		
		test('typeof', () => {
杜庆泉's avatar
杜庆泉 已提交
53 54
			let new1 = new User()
			expect(typeof(new1)).toEqual('object')
55
			expect(typeof(123456.789)).toEqual('Double')
杜庆泉's avatar
杜庆泉 已提交
56
			//expect(typeof(789778979798797987979)).toEqual('number')
57 58
			expect(typeof(0.0)).toEqual('Double')

杜庆泉's avatar
杜庆泉 已提交
59 60 61 62
			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')
lizhongyi_'s avatar
lizhongyi_ 已提交
63
			// expect(typeof(new Map<any,any>())).toEqual('object')
杜庆泉's avatar
杜庆泉 已提交
64 65
			expect(typeof(new Date())).toEqual('object')
			expect(typeof("hello world")).toEqual('string')
lizhongyi_'s avatar
lizhongyi_ 已提交
66 67
			// 原生对象  
			// #ifndef APP-IOS
杜庆泉's avatar
杜庆泉 已提交
68
			expect(typeof(UTSAndroid.getUniActivity())).toEqual('object')
lizhongyi_'s avatar
lizhongyi_ 已提交
69 70
			// #endif
			   
杜庆泉's avatar
杜庆泉 已提交
71
		   
杜庆泉's avatar
杜庆泉 已提交
72 73 74 75
		})
        
		
		test('instanceof', () => {
杜庆泉's avatar
杜庆泉 已提交
76
			let user1:any = new User()
杜庆泉's avatar
杜庆泉 已提交
77 78
			let instanceRet1 = user1 instanceof User
			expect(instanceRet1).toEqual(true)
79
			let instanceRet2 = (typeof user1) == "string"
杜庆泉's avatar
杜庆泉 已提交
80
			expect(instanceRet2).toEqual(false)
杜庆泉's avatar
杜庆泉 已提交
81
			let num1:any = 3.1415926 
82
			let instanceRet3 = (typeof num1) == "string" 
杜庆泉's avatar
杜庆泉 已提交
83
			expect(instanceRet3).toEqual(false)
84
			let instanceRet4 = (typeof num1) == "number"
lizhongyi_'s avatar
lizhongyi_ 已提交
85
			expect(instanceRet4).toEqual(false)
杜庆泉's avatar
杜庆泉 已提交
86 87
		})
		
杜庆泉's avatar
杜庆泉 已提交
88 89 90 91 92 93
		test('isArray', () => {
			let user1:any = new User()
			expect(Array.isArray(user1)).toEqual(false)
			expect(Array.isArray([1,2,3])).toEqual(true)
		})
		
杜庆泉's avatar
杜庆泉 已提交
94 95 96
		
    })
}