Global.uts 3.8 KB
Newer Older
lizhongyi_'s avatar
lizhongyi_ 已提交
1 2 3 4 5 6 7 8 9 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
import { describe, test, expect, Result } from './tests.uts'

export function testGlobal(): Result {
    return describe("Global", () => {
		
		test('parseInt', () => {
			expect(parseInt("123.456")).toEqual(123);
			expect(parseInt("123")).toEqual(123);
			expect(parseInt("123", 10)).toEqual(123);
			expect(parseInt("   123", 10)).toEqual(123);
			expect(parseInt("077")).toEqual(77);
			expect(parseInt("1.9")).toEqual(1);
			expect(parseInt("ff", 16)).toEqual(255);
			expect(parseInt("0xFF", 0)).toEqual(255);
			expect(parseInt("0xFF", 16)).toEqual(255);
			expect(parseInt("0xFF")).toEqual(255);
			expect(parseInt("0xFF", 10)).toEqual(0);
			expect(parseInt("0xF", 16)).toEqual(15);
			expect(parseInt("F", 16)).toEqual(15);
			expect(parseInt("021", 8)).toEqual(17);
			expect(parseInt("015", 10)).toEqual(15);
			expect(parseInt("15,123", 10)).toEqual(15);
			expect(parseInt("FXX123.99", 16)).toEqual(15);
			expect(parseInt("1111", 2)).toEqual(15);
			expect(parseInt("15 * 3", 10)).toEqual(15);
			expect(parseInt("15e2", 10)).toEqual(15);
			expect(parseInt("15px", 10)).toEqual(15);
			expect(parseInt("12", 13)).toEqual(15);
			expect(parseInt("17", 8)).toEqual(15);
			expect(isNaN(parseInt("a"))).toEqual(true)
			expect(parseInt("a", 16)).toEqual(10)
			expect(isNaN(parseInt("345", 2))).toEqual(true)
			expect(isNaN(parseInt("hello"))).toEqual(true)
			expect(parseInt("6.022e23")).toEqual(6)
			expect(parseInt("9223372036854775807")).toEqual(9.223372036854778e+18)
			expect(parseInt("9223372036854775807000")).toEqual(9.223372036854777e+21)
			expect(parseInt("922337203685477580700099999999999999999999999999999999999999999999999999999999999999999")).toEqual(9.223372036854776e+86)
38 39 40
			expect(parseInt("50") / 100).toEqualNumber(0.5);
			expect(parseInt("500") / 100).toEqualNumber(5);
			
杜庆泉's avatar
杜庆泉 已提交
41
			
lizhongyi_'s avatar
lizhongyi_ 已提交
42 43 44 45 46 47 48 49 50
		})
		
		test('parseFloat', () => {
			expect(parseFloat("11.20")).toEqual(11.2);
			expect(parseFloat("3.14")).toEqual(3.14);
			expect(parseFloat("  3.14  ")).toEqual(3.14);
			expect(parseFloat("314e-2")).toEqual(3.14);
			expect(parseFloat("0.0314E+2")).toEqual(3.14);
			expect(parseFloat("3.14some non-digit characters")).toEqual(3.14);
51
			expect(parseFloat("100") / 50).toEqualNumber(2);
杜庆泉's avatar
杜庆泉 已提交
52
			expect(parseFloat("105") / 50).toEqual(2.1);
lizhongyi_'s avatar
lizhongyi_ 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
		})
		
		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')
		})     
		
    })
}