Debian Codegraph @

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

raw
1 // Copyright 2008 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.GraphemeBreakTest');
16 goog.setTestOnly('goog.i18n.GraphemeBreakTest');
17
18 goog.require('goog.i18n.GraphemeBreak');
19 goog.require('goog.i18n.uChar');
20 goog.require('goog.testing.jsunit');
21
22 /** @private @const {function(number):?string} */
23 var fromCharCode_ = goog.i18n.uChar.fromCharCode;
24
25 function testEmptyInput() {
26 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings('a', ''));
27 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings('', 'b'));
28 }
29
30 function testBreakNormalAscii() {
31 assertTrue(
32 goog.i18n.GraphemeBreak.hasGraphemeBreak(
33 'a'.charCodeAt(0), 'b'.charCodeAt(0), true));
34
35 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings('a', 'b', true));
36 }
37
38 function testBreakAsciiWithExtendedChar() {
39 assertFalse(
40 goog.i18n.GraphemeBreak.hasGraphemeBreak(
41 'a'.charCodeAt(0), 0x0300, true));
42
43 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings(
44 'a', fromCharCode_(0x0300), true));
45 }
46
47 function testBreakSurrogates() {
48 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreak(0xDA00, 0xDC00, true));
49 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreak(0xDBFF, 0xDFFF, true));
50
51 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings(
52 fromCharCode_(0xDA00), fromCharCode_(0xDC00), true));
53 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings(
54 fromCharCode_(0xDBFF), fromCharCode_(0xDFFF), true));
55 }
56
57 function testBreakHangLxL() {
58 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreak(0x1100, 0x1100, true));
59 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings(
60 fromCharCode_(0x1100), fromCharCode_(0x1100), true));
61 }
62
63 function testBreakHangL_T() {
64 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreak(0x1100, 0x11A8));
65 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings(
66 fromCharCode_(0x1100), fromCharCode_(0x11A8)));
67 }
68
69 function testBreakHangLVxV() {
70 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreak(0xAC00, 0x1160, true));
71 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings(
72 fromCharCode_(0xAC00), fromCharCode_(0x1160), true));
73 }
74
75 function testBreakHangLV_L() {
76 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreak(0xAC00, 0x1100, true));
77 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings(
78 fromCharCode_(0xAC00), fromCharCode_(0x1100), true));
79 }
80
81 function testBreakHangLVTxT() {
82 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreak(0xAC01, 0x11A8, true));
83 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings(
84 fromCharCode_(0xAC01), fromCharCode_(0x11A8), true));
85 }
86
87 function testBreakThaiPrependLegacy() {
88 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreak(0x0E40, 0x0E01, false));
89 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings(
90 fromCharCode_(0x0E40), fromCharCode_(0x0E01), false));
91 }
92
93 function testBreakThaiPrependExtended() {
94 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreak(0x0E40, 0x0E01, true));
95 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings(
96 fromCharCode_(0x0E40), fromCharCode_(0x0E01), true));
97 }
98
99 function testBreakDevaSpacingMarkLegacy() {
100 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreak(0x0915, 0x093E, false));
101 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings(
102 fromCharCode_(0x0915), fromCharCode_(0x093E), false));
103 }
104
105 function testBreakDevaSpacingMarkExtended() {
106 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreak(0x0915, 0x093E, true));
107 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings(
108 fromCharCode_(0x0915), fromCharCode_(0x093E), true));
109 }
110
111 function testBreakDevaViramaSpace() {
112 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreak(0x094D, 0x0020));
113 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings(
114 fromCharCode_(0x094D), fromCharCode_(0x0020)));
115 }
116
117 function testBreakDevaViramaConsonant() {
118 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreak(0x094D, 0x0915));
119 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings(
120 fromCharCode_(0x094D), fromCharCode_(0x0915)));
121 }
122
123 function testEmojiSequences() {
124 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings('👦', '🏼'));
125 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings('👨\u200D', '🚒'));
126 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings('👨', '\u200D🚒'));
127 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings(
128 '🕵️‍♀️', '👨‍🚒'));
129 }
130
131 function testEmojiFlagSequences() {
132 assertFalse(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings('🇦🇨🇦', '🇨'));
133 assertTrue(goog.i18n.GraphemeBreak.hasGraphemeBreakStrings('🇦🇨', '🇦🇨'));
134 }