17TEST(fxcrt, BidiCharEmpty) {
19 CFX_BidiChar::Segment info;
21 info = bidi.GetSegmentInfo();
22 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, info.direction);
23 EXPECT_EQ(0, info.start);
24 EXPECT_EQ(0, info.count);
25 EXPECT_FALSE(bidi.EndChar());
30 CFX_BidiChar::Segment info;
32 EXPECT_TRUE(bidi.AppendChar(kLeftChar));
33 info = bidi.GetSegmentInfo();
34 EXPECT_EQ(0, info.start);
35 EXPECT_EQ(0, info.count);
37 EXPECT_FALSE(bidi.AppendChar(kLeftChar));
38 EXPECT_FALSE(bidi.AppendChar(kLeftChar));
40 info = bidi.GetSegmentInfo();
41 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, info.direction);
42 EXPECT_EQ(0, info.start);
43 EXPECT_EQ(0, info.count);
45 EXPECT_TRUE(bidi.EndChar());
46 info = bidi.GetSegmentInfo();
47 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, info.direction);
48 EXPECT_EQ(0, info.start);
49 EXPECT_EQ(3, info.count);
51 EXPECT_FALSE(bidi.EndChar());
54TEST(fxcrt, BidiCharLeftNeutralRight) {
56 CFX_BidiChar::Segment info;
58 EXPECT_TRUE(bidi.AppendChar(kLeftChar));
59 info = bidi.GetSegmentInfo();
60 EXPECT_EQ(0, info.start);
61 EXPECT_EQ(0, info.count);
63 EXPECT_FALSE(bidi.AppendChar(kLeftChar));
64 EXPECT_FALSE(bidi.AppendChar(kLeftChar));
65 EXPECT_TRUE(bidi.AppendChar(kNeutralChar));
66 info = bidi.GetSegmentInfo();
67 EXPECT_EQ(0, info.start);
68 EXPECT_EQ(3, info.count);
70 EXPECT_FALSE(bidi.AppendChar(kNeutralChar));
71 EXPECT_FALSE(bidi.AppendChar(kNeutralChar));
72 EXPECT_FALSE(bidi.AppendChar(kNeutralChar));
73 EXPECT_TRUE(bidi.AppendChar(kRightChar));
74 info = bidi.GetSegmentInfo();
75 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, info.direction);
76 EXPECT_EQ(3, info.start);
77 EXPECT_EQ(4, info.count);
79 EXPECT_TRUE(bidi.EndChar());
80 info = bidi.GetSegmentInfo();
81 EXPECT_EQ(CFX_BidiChar::Direction::kRight, info.direction);
82 EXPECT_EQ(7, info.start);
83 EXPECT_EQ(1, info.count);
85 EXPECT_FALSE(bidi.EndChar());
88TEST(fxcrt, BidiCharLeftLeftWeakRight) {
90 CFX_BidiChar::Segment info;
92 EXPECT_TRUE(bidi.AppendChar(kLeftChar));
93 info = bidi.GetSegmentInfo();
94 EXPECT_EQ(0, info.start);
95 EXPECT_EQ(0, info.count);
97 EXPECT_FALSE(bidi.AppendChar(kLeftChar));
98 EXPECT_FALSE(bidi.AppendChar(kLeftChar));
99 EXPECT_TRUE(bidi.AppendChar(kLeftWeakChar));
100 info = bidi.GetSegmentInfo();
101 EXPECT_EQ(0, info.start);
102 EXPECT_EQ(3, info.count);
104 EXPECT_FALSE(bidi.AppendChar(kLeftWeakChar));
105 EXPECT_FALSE(bidi.AppendChar(kLeftWeakChar));
106 EXPECT_FALSE(bidi.AppendChar(kLeftWeakChar));
107 EXPECT_TRUE(bidi.AppendChar(kRightChar));
108 info = bidi.GetSegmentInfo();
109 EXPECT_EQ(CFX_BidiChar::Direction::kLeftWeak, info.direction);
110 EXPECT_EQ(3, info.start);
111 EXPECT_EQ(4, info.count);
113 EXPECT_TRUE(bidi.EndChar());
114 info = bidi.GetSegmentInfo();
115 EXPECT_EQ(CFX_BidiChar::Direction::kRight, info.direction);
116 EXPECT_EQ(7, info.start);
117 EXPECT_EQ(1, info.count);
119 EXPECT_FALSE(bidi.EndChar());
122TEST(fxcrt, BidiCharLeftRightLeft) {
124 CFX_BidiChar::Segment info;
126 EXPECT_TRUE(bidi.AppendChar(kLeftChar));
127 info = bidi.GetSegmentInfo();
128 EXPECT_EQ(0, info.start);
129 EXPECT_EQ(0, info.count);
131 EXPECT_FALSE(bidi.AppendChar(kLeftChar));
132 EXPECT_FALSE(bidi.AppendChar(kLeftChar));
133 EXPECT_TRUE(bidi.AppendChar(kRightChar));
134 info = bidi.GetSegmentInfo();
135 EXPECT_EQ(0, info.start);
136 EXPECT_EQ(3, info.count);
138 EXPECT_FALSE(bidi.AppendChar(kRightChar));
139 EXPECT_FALSE(bidi.AppendChar(kRightChar));
140 EXPECT_FALSE(bidi.AppendChar(kRightChar));
141 EXPECT_TRUE(bidi.AppendChar(kLeftChar));
142 info = bidi.GetSegmentInfo();
143 EXPECT_EQ(CFX_BidiChar::Direction::kRight, info.direction);
144 EXPECT_EQ(3, info.start);
145 EXPECT_EQ(4, info.count);
147 EXPECT_TRUE(bidi.EndChar());
148 info = bidi.GetSegmentInfo();
149 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, info.direction);
150 EXPECT_EQ(7, info.start);
151 EXPECT_EQ(1, info.count);
153 EXPECT_FALSE(bidi.EndChar());
157 CFX_BidiString bidi(L"");
158 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, bidi.OverallDirection());
159 EXPECT_TRUE(bidi.begin() == bidi.end());
162TEST(fxcrt, BidiStringAllNeutral) {
164 const wchar_t str[] = {kNeutralChar, 0};
165 CFX_BidiString bidi(str);
166 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, bidi.OverallDirection());
168 auto it = bidi.begin();
169 ASSERT_NE(it, bidi.end());
170 EXPECT_EQ(0, it->start);
171 EXPECT_EQ(1, it->count);
172 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, it->direction);
174 EXPECT_EQ(it, bidi.end());
177 const wchar_t str[] = {kNeutralChar, kNeutralChar, kNeutralChar, 0};
178 CFX_BidiString bidi(str);
179 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, bidi.OverallDirection());
181 auto it = bidi.begin();
182 ASSERT_NE(it, bidi.end());
183 EXPECT_EQ(0, it->start);
184 EXPECT_EQ(3, it->count);
185 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, it->direction);
187 EXPECT_EQ(it, bidi.end());
191TEST(fxcrt, BidiStringAllLeft) {
193 const wchar_t str[] = {kLeftChar, 0};
194 CFX_BidiString bidi(str);
195 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, bidi.OverallDirection());
197 auto it = bidi.begin();
198 ASSERT_NE(it, bidi.end());
199 EXPECT_EQ(0, it->start);
200 EXPECT_EQ(0, it->count);
201 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, it->direction);
202 ASSERT_NE(it, bidi.end());
205 EXPECT_EQ(0, it->start);
206 EXPECT_EQ(1, it->count);
207 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, it->direction);
208 ASSERT_NE(it, bidi.end());
211 EXPECT_EQ(it, bidi.end());
214 const wchar_t str[] = {kLeftChar, kLeftChar, kLeftChar, 0};
215 CFX_BidiString bidi(str);
216 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, bidi.OverallDirection());
218 auto it = bidi.begin();
219 ASSERT_NE(it, bidi.end());
220 EXPECT_EQ(0, it->start);
221 EXPECT_EQ(0, it->count);
222 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, it->direction);
223 ASSERT_NE(it, bidi.end());
226 EXPECT_EQ(0, it->start);
227 EXPECT_EQ(3, it->count);
228 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, it->direction);
229 ASSERT_NE(it, bidi.end());
232 EXPECT_EQ(it, bidi.end());
236TEST(fxcrt, BidiStringAllLeftWeak) {
238 const wchar_t str[] = {kLeftWeakChar, 0};
239 CFX_BidiString bidi(str);
240 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, bidi.OverallDirection());
242 auto it = bidi.begin();
243 ASSERT_NE(it, bidi.end());
244 EXPECT_EQ(0, it->start);
245 EXPECT_EQ(0, it->count);
246 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, it->direction);
249 ASSERT_NE(it, bidi.end());
250 EXPECT_EQ(0, it->start);
251 EXPECT_EQ(1, it->count);
252 EXPECT_EQ(CFX_BidiChar::Direction::kLeftWeak, it->direction);
255 EXPECT_EQ(it, bidi.end());
258 const wchar_t str[] = {kLeftWeakChar, kLeftWeakChar, kLeftWeakChar, 0};
259 CFX_BidiString bidi(str);
260 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, bidi.OverallDirection());
262 auto it = bidi.begin();
263 ASSERT_NE(it, bidi.end());
264 EXPECT_EQ(0, it->start);
265 EXPECT_EQ(0, it->count);
266 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, it->direction);
269 ASSERT_NE(it, bidi.end());
270 EXPECT_EQ(0, it->start);
271 EXPECT_EQ(3, it->count);
272 EXPECT_EQ(CFX_BidiChar::Direction::kLeftWeak, it->direction);
275 EXPECT_EQ(it, bidi.end());
279TEST(fxcrt, BidiStringAllRight) {
281 const wchar_t str[] = {kRightChar, 0};
282 CFX_BidiString bidi(str);
283 EXPECT_EQ(CFX_BidiChar::Direction::kRight, bidi.OverallDirection());
285 auto it = bidi.begin();
286 EXPECT_EQ(0, it->start);
287 EXPECT_EQ(1, it->count);
288 EXPECT_EQ(CFX_BidiChar::Direction::kRight, it->direction);
289 ASSERT_NE(it, bidi.end());
292 ASSERT_NE(it, bidi.end());
293 EXPECT_EQ(0, it->start);
294 EXPECT_EQ(0, it->count);
295 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, it->direction);
296 ASSERT_NE(it, bidi.end());
299 EXPECT_EQ(it, bidi.end());
302 const wchar_t str[] = {kRightChar, kRightChar, kRightChar, 0};
303 CFX_BidiString bidi(str);
304 EXPECT_EQ(CFX_BidiChar::Direction::kRight, bidi.OverallDirection());
306 auto it = bidi.begin();
307 EXPECT_EQ(0, it->start);
308 EXPECT_EQ(3, it->count);
309 EXPECT_EQ(CFX_BidiChar::Direction::kRight, it->direction);
310 ASSERT_NE(it, bidi.end());
313 ASSERT_NE(it, bidi.end());
314 EXPECT_EQ(0, it->start);
315 EXPECT_EQ(0, it->count);
316 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, it->direction);
317 ASSERT_NE(it, bidi.end());
320 EXPECT_EQ(it, bidi.end());
324TEST(fxcrt, BidiStringLeftNeutralLeftRight) {
325 const wchar_t str[] = {kLeftChar, kNeutralChar, kLeftChar, kRightChar, 0};
326 CFX_BidiString bidi(str);
327 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, bidi.OverallDirection());
329 auto it = bidi.begin();
330 ASSERT_NE(it, bidi.end());
331 EXPECT_EQ(0, it->start);
332 EXPECT_EQ(0, it->count);
333 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, it->direction);
334 ASSERT_NE(it, bidi.end());
337 EXPECT_EQ(0, it->start);
338 EXPECT_EQ(1, it->count);
339 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, it->direction);
340 ASSERT_NE(it, bidi.end());
343 EXPECT_EQ(1, it->start);
344 EXPECT_EQ(1, it->count);
345 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, it->direction);
346 ASSERT_NE(it, bidi.end());
349 EXPECT_EQ(2, it->start);
350 EXPECT_EQ(1, it->count);
351 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, it->direction);
352 ASSERT_NE(it, bidi.end());
355 EXPECT_EQ(3, it->start);
356 EXPECT_EQ(1, it->count);
357 EXPECT_EQ(CFX_BidiChar::Direction::kRight, it->direction);
358 ASSERT_NE(it, bidi.end());
361 EXPECT_EQ(it, bidi.end());
364TEST(fxcrt, BidiStringRightNeutralLeftRight) {
365 const wchar_t str[] = {kRightChar, kNeutralChar, kLeftChar, kRightChar, 0};
366 CFX_BidiString bidi(str);
367 EXPECT_EQ(CFX_BidiChar::Direction::kRight, bidi.OverallDirection());
369 auto it = bidi.begin();
370 EXPECT_EQ(3, it->start);
371 EXPECT_EQ(1, it->count);
372 EXPECT_EQ(CFX_BidiChar::Direction::kRight, it->direction);
373 ASSERT_NE(it, bidi.end());
376 EXPECT_EQ(2, it->start);
377 EXPECT_EQ(1, it->count);
378 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, it->direction);
379 ASSERT_NE(it, bidi.end());
382 EXPECT_EQ(1, it->start);
383 EXPECT_EQ(1, it->count);
384 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, it->direction);
385 ASSERT_NE(it, bidi.end());
388 EXPECT_EQ(0, it->start);
389 EXPECT_EQ(1, it->count);
390 EXPECT_EQ(CFX_BidiChar::Direction::kRight, it->direction);
391 ASSERT_NE(it, bidi.end());
394 ASSERT_NE(it, bidi.end());
395 EXPECT_EQ(0, it->start);
396 EXPECT_EQ(0, it->count);
397 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, it->direction);
398 ASSERT_NE(it, bidi.end());
401 EXPECT_EQ(it, bidi.end());
404TEST(fxcrt, BidiStringRightLeftWeakLeftRight) {
405 const wchar_t str[] = {kRightChar, kLeftWeakChar, kLeftChar, kRightChar, 0};
406 CFX_BidiString bidi(str);
407 EXPECT_EQ(CFX_BidiChar::Direction::kRight, bidi.OverallDirection());
409 auto it = bidi.begin();
410 ASSERT_NE(it, bidi.end());
411 EXPECT_EQ(3, it->start);
412 EXPECT_EQ(1, it->count);
413 EXPECT_EQ(CFX_BidiChar::Direction::kRight, it->direction);
416 ASSERT_NE(it, bidi.end());
417 EXPECT_EQ(2, it->start);
418 EXPECT_EQ(1, it->count);
419 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, it->direction);
422 ASSERT_NE(it, bidi.end());
423 EXPECT_EQ(1, it->start);
424 EXPECT_EQ(1, it->count);
425 EXPECT_EQ(CFX_BidiChar::Direction::kLeftWeak, it->direction);
428 ASSERT_NE(it, bidi.end());
429 EXPECT_EQ(0, it->start);
430 EXPECT_EQ(1, it->count);
431 EXPECT_EQ(CFX_BidiChar::Direction::kRight, it->direction);
434 ASSERT_NE(it, bidi.end());
435 EXPECT_EQ(0, it->start);
436 EXPECT_EQ(0, it->count);
437 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, it->direction);
440 EXPECT_EQ(it, bidi.end());
443TEST(fxcrt, BidiStringReverse) {
444 const wchar_t str[] = {kLeftChar, kNeutralChar, kRightChar,
445 kLeftWeakChar, kLeftChar, 0};
446 CFX_BidiString bidi(str);
447 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, bidi.OverallDirection());
448 bidi.SetOverallDirectionRight();
450 auto it = bidi.begin();
451 ASSERT_NE(it, bidi.end());
452 EXPECT_EQ(4, it->start);
453 EXPECT_EQ(1, it->count);
454 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, it->direction);
457 ASSERT_NE(it, bidi.end());
458 EXPECT_EQ(3, it->start);
459 EXPECT_EQ(1, it->count);
460 EXPECT_EQ(CFX_BidiChar::Direction::kLeftWeak, it->direction);
463 ASSERT_NE(it, bidi.end());
464 EXPECT_EQ(2, it->start);
465 EXPECT_EQ(1, it->count);
466 EXPECT_EQ(CFX_BidiChar::Direction::kRight, it->direction);
469 ASSERT_NE(it, bidi.end());
470 EXPECT_EQ(1, it->start);
471 EXPECT_EQ(1, it->count);
472 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, it->direction);
475 ASSERT_NE(it, bidi.end());
476 EXPECT_EQ(0, it->start);
477 EXPECT_EQ(1, it->count);
478 EXPECT_EQ(CFX_BidiChar::Direction::kLeft, it->direction);
481 ASSERT_NE(it, bidi.end());
482 EXPECT_EQ(0, it->start);
483 EXPECT_EQ(0, it->count);
484 EXPECT_EQ(CFX_BidiChar::Direction::kNeutral, it->direction);
487 EXPECT_EQ(it, bidi.end());