forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodePointAt.js
More file actions
105 lines (89 loc) · 3.88 KB
/
codePointAt.js
File metadata and controls
105 lines (89 loc) · 3.88 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
Object.defineProperty(Object.getPrototypeOf({}), "echo", { value: function () { WScript.Echo(this); } });
function AssertEqual(actual, expected, msg) { ((actual === expected ? "Passed! " : "Failed (actual: " + actual + ", expected: " + expected + "). Message: ") + msg).echo(); };
Object.defineProperty(Object.getPrototypeOf({}), "equalTo", { value: function (other, msg) { AssertEqual(this.constructor(this), other, msg); } });
try {
String.prototype.codePointAt.call();
} catch (e) {
e.echo();
}
try {
String.prototype.codePointAt.call(null);
} catch (e) {
e.echo();
}
try {
String.prototype.codePointAt.call(undefined);
} catch (e) {
e.echo();
}
try {
new String.prototype.codePointAt();
} catch (e) {
e.echo();
}
try {
String.fromCodePoint.call();
} catch (e) {
"Fail!".echo();
}
try {
String.fromCodePoint.call(null);
} catch (e) {
"Fail!".echo();
}
try {
String.fromCodePoint.call(undefined);
} catch (e) {
"Fail!".echo();
}
try {
new String.fromCodePoint();
} catch (e) {
e.echo();
}
try {
String.fromCodePoint(1.1);
} catch (ex) {
ex.echo();
}
try {
String.fromCodePoint(100000000);
} catch (ex) {
ex.echo();
}
try {
String.fromCodePoint(-0.0001);
} catch (ex) {
ex.echo();
}
try {
String.fromCodePoint(Infinity);
} catch (ex) {
ex.echo();
}
AssertEqual("".codePointAt(0), undefined, "Size = 0, index 0 test.");
AssertEqual("a".codePointAt(-1), undefined, "Size = 1, index -1 test.");
String.fromCodePoint(97).codePointAt(0).equalTo(97, "Simple character test.");
String.fromCodePoint(65536).codePointAt(0).equalTo(65536, "Surrogate pair treated as a single code point.");
String.fromCodePoint(65536).codePointAt(1).equalTo(56320, "Index pointing to a second surrogate code unit returns the value of that code unit.");
String.fromCodePoint(55296).codePointAt(0).equalTo(55296, "Partial surrogate code unit.");
String.fromCodePoint(55295, 56320).codePointAt(0).equalTo(55295, "First surrogate code unit not in range [D800-DBFF].");
String.fromCodePoint(56320, 56320).codePointAt(0).equalTo(56320, "First surrogate code unit not in range [D800-DBFF].");
String.fromCodePoint(65536).codePointAt(0).equalTo(65536, "First surrogate code unit min value.");
String.fromCodePoint(55296, 56320).codePointAt(0).equalTo(65536, "First surrogate code unit min value.");
String.fromCodePoint(1113088).codePointAt(0).equalTo(1113088, "First surrogate code unit max value.");
String.fromCodePoint(56319, 56320).codePointAt(0).equalTo(1113088, "First surrogate code unit max value.");
String.fromCodePoint(55296, 56319).codePointAt(0).equalTo(55296, "Second surrogate code unit not in range [DC00-DFFF].");
String.fromCodePoint(55296, 57344).codePointAt(0).equalTo(55296, "Second surrogate code unit not in range [DC00-DFFF].");
String.fromCodePoint(65536).codePointAt(0).equalTo(65536, "Second surrogate code unit min value.");
String.fromCodePoint(55296, 56320).codePointAt(0).equalTo(65536, "Second surrogate code unit min value.");
String.fromCodePoint(66559).codePointAt(0).equalTo(66559, "Second surrogate code unit max value.");
String.fromCodePoint(55296, 57343).codePointAt(0).equalTo(66559, "Second surrogate code unit max value.");
String.prototype.codePointAt.call(5, 0).equalTo(53, "Calling on a number object instead of string object.");
if(String.fromCodePoint.length !== 1) {
WScript.Echo("String.fromCodePoint length should be 1, actual: " + String.fromCodePoint.length);
}