• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// LATIN SMALL LIGATURES
16// LATIN SMALL LIGATURE FF
17assert ("\ufb00".toLowerCase() == "\ufb00");
18assert ("\ufb00".toUpperCase() == "\u0046\u0046");
19// LATIN SMALL LIGATURE FI
20assert ("\ufb01".toLowerCase() == "\ufb01");
21assert ("\ufb01".toUpperCase() == "\u0046\u0049");
22// LATIN SMALL LIGATURE FL
23assert ("\ufb02".toLowerCase() == "\ufb02");
24assert ("\ufb02".toUpperCase() == "\u0046\u004c");
25// LATIN SMALL LIGATURE FFI
26assert ("\ufb03".toLowerCase() == "\ufb03");
27assert ("\ufb03".toUpperCase() == "\u0046\u0046\u0049");
28// LATIN SMALL LIGATURE FFL
29assert ("\ufb04".toLowerCase() == "\ufb04");
30assert ("\ufb04".toUpperCase() == "\u0046\u0046\u004c");
31// LATIN SMALL LIGATURE LONG S T
32assert ("\ufb05".toLowerCase() == "\ufb05");
33assert ("\ufb05".toUpperCase() == "\u0053\u0054");
34// LATIN SMALL LIGATURE ST
35assert ("\ufb06".toLowerCase() == "\ufb06");
36assert ("\ufb06".toUpperCase() == "\u0053\u0054");
37
38// LATIN CAPITAL LETTER I WITH DOT ABOVE
39assert ("\u0130".toLowerCase() == "\u0069\u0307");
40assert ("\u0130".toUpperCase() == "\u0130");
41
42// LATIN SMALL LETTER SHARP S
43assert ("\u00df".toLowerCase() == "\u00df");
44assert ("\u00df".toUpperCase() == "\u0053\u0053");
45
46// LATIN CAPITAL LETTER I WITH BREVE
47assert ("\u012c".toLowerCase() == "\u012d");
48assert ("\u012c".toUpperCase() == "\u012c");
49// LATIN SMALL LETTER I WITH BREVE
50assert ("\u012d".toLowerCase() == "\u012d")
51assert ("\u012d".toUpperCase() == "\u012c");
52
53// Check randomly selected characters from conversion tables
54
55// lower-case conversions
56assert ("\u01c5\u01c8\u01cb\u212b".toLowerCase() == "\u01c6\u01c9\u01cc\u00e5");
57assert ("\u0130".toLowerCase() == "\u0069\u0307");
58
59// upper-case conversions
60assert ("\u00b5\u017f".toUpperCase() == "\u039c\u0053");
61assert ("\ufb17\u00df\u1fbc".toUpperCase() == "\u0544\u053D\u0053\u0053\u0391\u0399");
62assert ("\ufb03\ufb04".toUpperCase() == "\u0046\u0046\u0049\u0046\u0046\u004c");
63
64// character case ranges
65assert ("\u0100\u0101\u0139\u03fa\ua7b4".toLowerCase() == "\u0101\u0101\u013a\u03fb\ua7b5");
66assert ("\u0101\u0100\u013a\u03fb\ua7b5".toUpperCase() == "\u0100\u0100\u0139\u03fa\ua7b4");
67
68// character pairs
69assert ("\u0178\ua7b1\u0287\ua7b3".toLowerCase() == "\u00ff\u0287\u0287\uab53");
70assert ("\u00ff\u0287\ua7b1\uab53".toUpperCase() == "\u0178\ua7b1\ua7b1\ua7b3");
71
72// character case ranges
73assert ("\u00e0\u00c0\u00c1\u00c2\uff21".toLowerCase() == "\u00e0\u00e0\u00e1\u00e2\uff41");
74assert ("\u00e0\u00c0\u00e1\u00e2\uff41".toUpperCase() == "\u00c0\u00c0\u00c1\u00c2\uff21");
75
76// lower-case ranges
77assert ("\u1f88\u1f98\u1fa8\u1f8b\u1faf".toLowerCase() == "\u1f80\u1f90\u1fa0\u1f83\u1fa7");
78
79// upper-case special ranges
80assert ("\u1f80\u1f81\u1fa7".toUpperCase() == "\u1f08\u0399\u1f09\u0399\u1f6f\u0399");
81
82assert ("0123456789abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQRSTUVWXYZ".toLowerCase()
83        == "0123456789abcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxyz");
84assert ("0123456789abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQRSTUVWXYZ".toUpperCase()
85        == "0123456789ABCDEFGHIJKLMNOPQRSTUVWXZYABCDEFGHIJKLMNOPQRSTUVWXYZ");
86
87// Although codepoint 0x10400 and 0x10428 are an upper-lowercase pair,
88// we must not do their conversion in JavaScript. We must also ignore
89// stray surrogates.
90
91assert ("\ud801\ud801\udc00\udc00".toLowerCase() == "\ud801\ud801\udc00\udc00");
92assert ("\ud801\ud801\udc28\udc28".toUpperCase() == "\ud801\ud801\udc28\udc28");
93
94// Conversion of non-string objects.
95
96assert (String.prototype.toUpperCase.call(true) == "TRUE");
97assert (String.prototype.toLowerCase.call(-23) == "-23");
98
99var object = { toString : function() { return "<sTr>"; } };
100assert (String.prototype.toUpperCase.call(object) == "<STR>");
101assert (String.prototype.toLowerCase.call(object) == "<str>");
102
103try
104{
105  String.prototype.toUpperCase.call(null);
106  assert(false);
107}
108catch (e)
109{
110  assert (e instanceof TypeError);
111}
112