Debian Codegraph @

closure-library/closure/goog/i18n/uchar_test.js

raw
1 // Copyright 2009 The Closure Library Authors. All Rights Reserved.
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 goog.provide('goog.i18n.uCharTest');
16 goog.setTestOnly('goog.i18n.uCharTest');
17
18 goog.require('goog.i18n.uChar');
19 goog.require('goog.testing.jsunit');
20
21 function testToHexString() {
22 var result = goog.i18n.uChar.toHexString('\uD869\uDED6');
23 assertEquals('U+2A6D6', result);
24 }
25
26 function testPadString() {
27 var result = goog.i18n.uChar.padString_('abc', 4, '0');
28 assertEquals('0abc', result);
29 }
30
31 function testToCharCode() {
32 var result = goog.i18n.uChar.toCharCode('\uD869\uDED6');
33 assertEquals(0x2A6D6, result);
34 }
35
36 function testcodePointAt() {
37 // Basic cases.
38 assertEquals(0x006C, goog.i18n.uChar.getCodePointAround('Hello!', 2));
39 assertEquals(
40 0x2708 /* Airplane symbol (non-ASCII) */,
41 goog.i18n.uChar.getCodePointAround('Hello\u2708', 5));
42
43 // Supplementary characters.
44 assertEquals(0x2A6D6, goog.i18n.uChar.getCodePointAround('\uD869\uDED6', 0));
45 assertEquals(-0x2A6D6, goog.i18n.uChar.getCodePointAround('\uD869\uDED6', 1));
46 assertEquals(
47 0xD869, goog.i18n.uChar.getCodePointAround(
48 '\uD869' +
49 'w',
50 0));
51 assertEquals(
52 0xDED6, goog.i18n.uChar.getCodePointAround(
53 '\uD869' +
54 'w' +
55 '\uDED6',
56 2));
57 }
58
59 function testBuildSupplementaryCodePoint() {
60 var result = goog.i18n.uChar.buildSupplementaryCodePoint(0xD869, 0xDED6);
61 assertEquals(0x2A6D6, result);
62 assertNull(goog.i18n.uChar.buildSupplementaryCodePoint(0xDED6, 0xD869));
63 assertNull(goog.i18n.uChar.buildSupplementaryCodePoint(0xD869, 0xAC00));
64 }
65
66 function testCharCount() {
67 assertEquals(2, goog.i18n.uChar.charCount(0x2A6D6));
68 assertEquals(1, goog.i18n.uChar.charCount(0xAC00));
69 }
70
71 function testIsSupplementaryCodePoint() {
72 assertTrue(goog.i18n.uChar.isSupplementaryCodePoint(0x2A6D6));
73 assertFalse(goog.i18n.uChar.isSupplementaryCodePoint(0xAC00));
74 }
75
76 function testIsLeadSurrogateCodepoint() {
77 assertTrue(goog.i18n.uChar.isLeadSurrogateCodePoint(0xD869));
78 assertFalse(goog.i18n.uChar.isLeadSurrogateCodePoint(0xDED6));
79 assertFalse(goog.i18n.uChar.isLeadSurrogateCodePoint(0xAC00));
80 }
81
82 function testIsTrailSurrogateCodePoint() {
83 assertTrue(goog.i18n.uChar.isTrailSurrogateCodePoint(0xDED6));
84 assertFalse(goog.i18n.uChar.isTrailSurrogateCodePoint(0xD869));
85 assertFalse(goog.i18n.uChar.isTrailSurrogateCodePoint(0xAC00));
86 }
87
88 function testFromCharCode() {
89 var result = goog.i18n.uChar.fromCharCode(0x2A6D6);
90 assertEquals('\uD869\uDED6', result);
91 }
92
93 function testFromCharCode_invalidValues() {
94 var result = goog.i18n.uChar.fromCharCode(-1);
95 assertEquals(null, result);
96
97 result =
98 goog.i18n.uChar.fromCharCode(goog.i18n.uChar.CODE_POINT_MAX_VALUE_ + 1);
99 assertEquals(null, result);
100
101 result = goog.i18n.uChar.fromCharCode(null);
102 assertEquals(null, result);
103
104 result = goog.i18n.uChar.fromCharCode(undefined);
105 assertEquals(null, result);
106
107 result = goog.i18n.uChar.fromCharCode(NaN);
108 assertEquals(null, result);
109 }