1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "BidiUtils.h"
18
19 #include <gtest/gtest.h>
20
21 #include "minikin/Range.h"
22
23 #include "UnicodeUtils.h"
24
25 namespace minikin {
26
27 const char LTR_1[] = "Hello, World";
28 const char RTL_1[] = "\u0627\u0644\u0633\u0644\u0627\u0645\u0020\u0639\u0644\u064A\u0643\u0645";
29 const char LTR_2[] = "Hello, Android";
30 const char RTL_2[] = "\u0639\u0644\u064A\u0643\u0645\u0020\u0627\u0644\u0633\u0644\u0627\u0645";
31
TEST(BidiUtilsTest,AllLTRCharText)32 TEST(BidiUtilsTest, AllLTRCharText) {
33 auto text = utf8ToUtf16(LTR_1);
34 uint32_t ltrLength = text.size();
35 {
36 BidiText bidiText(text, Range(0, ltrLength), Bidi::LTR);
37 auto it = bidiText.begin();
38 EXPECT_NE(bidiText.end(), it);
39 EXPECT_EQ(Range(0, ltrLength), (*it).range);
40 EXPECT_FALSE((*it).isRtl);
41 ++it;
42 EXPECT_EQ(bidiText.end(), it);
43 }
44 {
45 BidiText bidiText(text, Range(0, ltrLength), Bidi::RTL);
46 auto it = bidiText.begin();
47 EXPECT_NE(bidiText.end(), it);
48 EXPECT_EQ(Range(0, ltrLength), (*it).range);
49 EXPECT_FALSE((*it).isRtl);
50 ++it;
51 EXPECT_EQ(bidiText.end(), it);
52 }
53 {
54 BidiText bidiText(text, Range(0, ltrLength), Bidi::DEFAULT_LTR);
55 auto it = bidiText.begin();
56 EXPECT_NE(bidiText.end(), it);
57 EXPECT_EQ(Range(0, ltrLength), (*it).range);
58 EXPECT_FALSE((*it).isRtl);
59 ++it;
60 EXPECT_EQ(bidiText.end(), it);
61 }
62 {
63 BidiText bidiText(text, Range(0, ltrLength), Bidi::DEFAULT_RTL);
64 auto it = bidiText.begin();
65 EXPECT_NE(bidiText.end(), it);
66 EXPECT_EQ(Range(0, ltrLength), (*it).range);
67 EXPECT_FALSE((*it).isRtl);
68 ++it;
69 EXPECT_EQ(bidiText.end(), it);
70 }
71 {
72 BidiText bidiText(text, Range(0, ltrLength), Bidi::FORCE_LTR);
73 auto it = bidiText.begin();
74 EXPECT_NE(bidiText.end(), it);
75 EXPECT_EQ(Range(0, ltrLength), (*it).range);
76 EXPECT_FALSE((*it).isRtl);
77 ++it;
78 EXPECT_EQ(bidiText.end(), it);
79 }
80 {
81 BidiText bidiText(text, Range(0, ltrLength), Bidi::FORCE_RTL);
82 auto it = bidiText.begin();
83 EXPECT_NE(bidiText.end(), it);
84 EXPECT_EQ(Range(0, ltrLength), (*it).range);
85 EXPECT_TRUE((*it).isRtl);
86 ++it;
87 EXPECT_EQ(bidiText.end(), it);
88 }
89 }
90
TEST(BidiUtilsTest,AllRTLCharText)91 TEST(BidiUtilsTest, AllRTLCharText) {
92 auto text = utf8ToUtf16(RTL_1);
93 uint32_t rtlLength = text.size();
94 {
95 BidiText bidiText(text, Range(0, rtlLength), Bidi::LTR);
96 auto it = bidiText.begin();
97 EXPECT_NE(bidiText.end(), it);
98 EXPECT_EQ(Range(0, rtlLength), (*it).range);
99 EXPECT_TRUE((*it).isRtl);
100 ++it;
101 EXPECT_EQ(bidiText.end(), it);
102 }
103 {
104 BidiText bidiText(text, Range(0, rtlLength), Bidi::RTL);
105 auto it = bidiText.begin();
106 EXPECT_NE(bidiText.end(), it);
107 EXPECT_EQ(Range(0, rtlLength), (*it).range);
108 EXPECT_TRUE((*it).isRtl);
109 ++it;
110 EXPECT_EQ(bidiText.end(), it);
111 }
112 {
113 BidiText bidiText(text, Range(0, rtlLength), Bidi::DEFAULT_LTR);
114 auto it = bidiText.begin();
115 EXPECT_NE(bidiText.end(), it);
116 EXPECT_EQ(Range(0, rtlLength), (*it).range);
117 EXPECT_TRUE((*it).isRtl);
118 ++it;
119 EXPECT_EQ(bidiText.end(), it);
120 }
121 {
122 BidiText bidiText(text, Range(0, rtlLength), Bidi::DEFAULT_RTL);
123 auto it = bidiText.begin();
124 EXPECT_NE(bidiText.end(), it);
125 EXPECT_EQ(Range(0, rtlLength), (*it).range);
126 EXPECT_TRUE((*it).isRtl);
127 ++it;
128 EXPECT_EQ(bidiText.end(), it);
129 }
130 {
131 BidiText bidiText(text, Range(0, rtlLength), Bidi::FORCE_LTR);
132 auto it = bidiText.begin();
133 EXPECT_NE(bidiText.end(), it);
134 EXPECT_EQ(Range(0, rtlLength), (*it).range);
135 EXPECT_FALSE((*it).isRtl);
136 ++it;
137 EXPECT_EQ(bidiText.end(), it);
138 }
139 {
140 BidiText bidiText(text, Range(0, rtlLength), Bidi::FORCE_RTL);
141 auto it = bidiText.begin();
142 EXPECT_NE(bidiText.end(), it);
143 EXPECT_EQ(Range(0, rtlLength), (*it).range);
144 EXPECT_TRUE((*it).isRtl);
145 ++it;
146 EXPECT_EQ(bidiText.end(), it);
147 }
148 }
149
TEST(BidiUtilsTest,LTR_RTL_CharText)150 TEST(BidiUtilsTest, LTR_RTL_CharText) {
151 auto text = utf8ToUtf16(std::string(LTR_1) + RTL_1);
152 uint32_t ltrLength = utf8ToUtf16(LTR_1).size();
153 uint32_t rtlLength = utf8ToUtf16(RTL_1).size();
154 {
155 // Logical Run: L1 L2 R1 R2
156 // Visual Run : L1 L2 R2 R1
157 BidiText bidiText(text, Range(0, text.size()), Bidi::LTR);
158 auto it = bidiText.begin();
159 EXPECT_NE(bidiText.end(), it);
160 EXPECT_EQ(Range(0, ltrLength), (*it).range);
161 EXPECT_FALSE((*it).isRtl);
162 ++it;
163 EXPECT_NE(bidiText.end(), it);
164 EXPECT_EQ(Range(ltrLength, ltrLength + rtlLength), (*it).range);
165 EXPECT_TRUE((*it).isRtl);
166 ++it;
167 EXPECT_EQ(bidiText.end(), it);
168 }
169 {
170 // Logical Run: L1 L2 R1 R2
171 // Visual Run : R2 R1 L1 L2
172 BidiText bidiText(text, Range(0, text.size()), Bidi::RTL);
173 auto it = bidiText.begin();
174 EXPECT_NE(bidiText.end(), it);
175 EXPECT_EQ(Range(ltrLength, ltrLength + rtlLength), (*it).range);
176 EXPECT_TRUE((*it).isRtl);
177 ++it;
178 EXPECT_NE(bidiText.end(), it);
179 EXPECT_EQ(Range(0, ltrLength), (*it).range);
180 EXPECT_FALSE((*it).isRtl);
181 ++it;
182 EXPECT_EQ(bidiText.end(), it);
183 }
184 {
185 // Logical Run: L1 L2 R1 R2
186 // Visual Run : L1 L2 R2 R1
187 BidiText bidiText(text, Range(0, text.size()), Bidi::DEFAULT_LTR);
188 auto it = bidiText.begin();
189 EXPECT_NE(bidiText.end(), it);
190 EXPECT_EQ(Range(0, ltrLength), (*it).range);
191 EXPECT_FALSE((*it).isRtl);
192 ++it;
193 EXPECT_NE(bidiText.end(), it);
194 EXPECT_EQ(Range(ltrLength, ltrLength + rtlLength), (*it).range);
195 EXPECT_TRUE((*it).isRtl);
196 ++it;
197 EXPECT_EQ(bidiText.end(), it);
198 }
199 {
200 // Logical Run: L1 L2 R1 R2
201 // Visual Run : L1 L2 R2 R1
202 BidiText bidiText(text, Range(0, text.size()), Bidi::DEFAULT_RTL);
203 auto it = bidiText.begin();
204 EXPECT_NE(bidiText.end(), it);
205 EXPECT_EQ(Range(0, ltrLength), (*it).range);
206 EXPECT_FALSE((*it).isRtl);
207 ++it;
208 EXPECT_NE(bidiText.end(), it);
209 EXPECT_EQ(Range(ltrLength, ltrLength + rtlLength), (*it).range);
210 EXPECT_TRUE((*it).isRtl);
211 ++it;
212 EXPECT_EQ(bidiText.end(), it);
213 }
214 {
215 // Logical Run: L1 L2 R1 R2
216 // Visual Run : L1 L2 R1 R2
217 BidiText bidiText(text, Range(0, text.size()), Bidi::FORCE_LTR);
218 auto it = bidiText.begin();
219 EXPECT_NE(bidiText.end(), it);
220 EXPECT_EQ(Range(0, ltrLength + rtlLength), (*it).range);
221 EXPECT_FALSE((*it).isRtl);
222 ++it;
223 EXPECT_EQ(bidiText.end(), it);
224 }
225 {
226 // Logical Run: L1 L2 R1 R2
227 // Visual Run : R2 R1 L2 L1
228 BidiText bidiText(text, Range(0, text.size()), Bidi::FORCE_RTL);
229 auto it = bidiText.begin();
230 EXPECT_NE(bidiText.end(), it);
231 EXPECT_EQ(Range(0, ltrLength + rtlLength), (*it).range);
232 EXPECT_TRUE((*it).isRtl);
233 ++it;
234 EXPECT_EQ(bidiText.end(), it);
235 }
236 }
237
TEST(BidiUtilsTest,RTL_LTR_CharText)238 TEST(BidiUtilsTest, RTL_LTR_CharText) {
239 auto text = utf8ToUtf16(std::string(RTL_1) + LTR_1);
240 uint32_t ltrLength = utf8ToUtf16(LTR_1).size();
241 uint32_t rtlLength = utf8ToUtf16(RTL_1).size();
242 {
243 // Logical Run: R1 R2 L1 L2
244 // Visual Run : R2 R1 L1 L2
245 BidiText bidiText(text, Range(0, text.size()), Bidi::LTR);
246 auto it = bidiText.begin();
247 EXPECT_NE(bidiText.end(), it);
248 EXPECT_EQ(Range(0, rtlLength), (*it).range);
249 EXPECT_TRUE((*it).isRtl);
250 ++it;
251 EXPECT_NE(bidiText.end(), it);
252 EXPECT_EQ(Range(rtlLength, ltrLength + rtlLength), (*it).range);
253 EXPECT_FALSE((*it).isRtl);
254 ++it;
255 EXPECT_EQ(bidiText.end(), it);
256 }
257 {
258 // Logical Run: R1 R2 L1 L2
259 // Visual Run : L1 L2 R2 R1
260 BidiText bidiText(text, Range(0, text.size()), Bidi::RTL);
261 auto it = bidiText.begin();
262 EXPECT_NE(bidiText.end(), it);
263 EXPECT_EQ(Range(rtlLength, ltrLength + rtlLength), (*it).range);
264 EXPECT_FALSE((*it).isRtl);
265 ++it;
266 EXPECT_NE(bidiText.end(), it);
267 EXPECT_EQ(Range(0, rtlLength), (*it).range);
268 EXPECT_TRUE((*it).isRtl);
269 ++it;
270 EXPECT_EQ(bidiText.end(), it);
271 }
272 {
273 // Logical Run: R1 R2 L1 L2
274 // Visual Run : L1 L2 R2 R1
275 BidiText bidiText(text, Range(0, text.size()), Bidi::DEFAULT_LTR);
276 auto it = bidiText.begin();
277 EXPECT_NE(bidiText.end(), it);
278 EXPECT_EQ(Range(rtlLength, ltrLength + rtlLength), (*it).range);
279 EXPECT_FALSE((*it).isRtl);
280 ++it;
281 EXPECT_NE(bidiText.end(), it);
282 EXPECT_EQ(Range(0, rtlLength), (*it).range);
283 EXPECT_TRUE((*it).isRtl);
284 ++it;
285 EXPECT_EQ(bidiText.end(), it);
286 }
287 {
288 // Logical Run: R1 R2 L1 L2
289 // Visual Run : L1 L2 R2 R1
290 BidiText bidiText(text, Range(0, text.size()), Bidi::DEFAULT_RTL);
291 auto it = bidiText.begin();
292 EXPECT_NE(bidiText.end(), it);
293 EXPECT_EQ(Range(rtlLength, ltrLength + rtlLength), (*it).range);
294 EXPECT_FALSE((*it).isRtl);
295 ++it;
296 EXPECT_NE(bidiText.end(), it);
297 EXPECT_EQ(Range(0, rtlLength), (*it).range);
298 EXPECT_TRUE((*it).isRtl);
299 ++it;
300 EXPECT_EQ(bidiText.end(), it);
301 }
302 {
303 // Logical Run: R1 R2 L1 L2
304 // Visual Run : R1 R2 L1 L2
305 BidiText bidiText(text, Range(0, text.size()), Bidi::FORCE_LTR);
306 auto it = bidiText.begin();
307 EXPECT_NE(bidiText.end(), it);
308 EXPECT_EQ(Range(0, ltrLength + rtlLength), (*it).range);
309 EXPECT_FALSE((*it).isRtl);
310 ++it;
311 EXPECT_EQ(bidiText.end(), it);
312 }
313 {
314 // Logical Run: R1 R2 L1 L2
315 // Visual Run : L2 L1 R2 R1
316 BidiText bidiText(text, Range(0, text.size()), Bidi::FORCE_RTL);
317 auto it = bidiText.begin();
318 EXPECT_NE(bidiText.end(), it);
319 EXPECT_EQ(Range(0, ltrLength + rtlLength), (*it).range);
320 EXPECT_TRUE((*it).isRtl);
321 ++it;
322 EXPECT_EQ(bidiText.end(), it);
323 }
324 }
325
TEST(BidiUtilsTest,LTR_RTL_LTR_CharText)326 TEST(BidiUtilsTest, LTR_RTL_LTR_CharText) {
327 auto text = utf8ToUtf16(std::string(LTR_1) + RTL_1 + LTR_2);
328 uint32_t ltr1Length = utf8ToUtf16(LTR_1).size();
329 uint32_t ltr2Length = utf8ToUtf16(LTR_2).size();
330 uint32_t rtlLength = utf8ToUtf16(RTL_1).size();
331 {
332 // Logical Run: L1 L2 R1 R2 L3 L4
333 // Visual Run : L1 L2 R2 R1 L3 L4
334 BidiText bidiText(text, Range(0, text.size()), Bidi::LTR);
335 auto it = bidiText.begin();
336 EXPECT_NE(bidiText.end(), it);
337 EXPECT_EQ(Range(0, ltr1Length), (*it).range);
338 EXPECT_FALSE((*it).isRtl);
339 ++it;
340 EXPECT_NE(bidiText.end(), it);
341 EXPECT_EQ(Range(ltr1Length, ltr1Length + rtlLength), (*it).range);
342 EXPECT_TRUE((*it).isRtl);
343 ++it;
344 EXPECT_NE(bidiText.end(), it);
345 EXPECT_EQ(Range(ltr1Length + rtlLength, ltr1Length + rtlLength + ltr2Length), (*it).range);
346 EXPECT_FALSE((*it).isRtl);
347 ++it;
348 EXPECT_EQ(bidiText.end(), it);
349 }
350 {
351 // Logical Run: L1 L2 R1 R2 L3 L4
352 // Visual Run : L3 L4 R2 R1 L1 2L
353 BidiText bidiText(text, Range(0, text.size()), Bidi::RTL);
354 auto it = bidiText.begin();
355 EXPECT_NE(bidiText.end(), it);
356 EXPECT_EQ(Range(ltr1Length + rtlLength, text.size()), (*it).range);
357 EXPECT_FALSE((*it).isRtl);
358 ++it;
359 EXPECT_NE(bidiText.end(), it);
360 EXPECT_EQ(Range(ltr1Length, ltr1Length + rtlLength), (*it).range);
361 EXPECT_TRUE((*it).isRtl);
362 ++it;
363 EXPECT_NE(bidiText.end(), it);
364 EXPECT_EQ(Range(0, ltr1Length), (*it).range);
365 EXPECT_FALSE((*it).isRtl);
366 ++it;
367 EXPECT_EQ(bidiText.end(), it);
368 }
369 {
370 // Logical Run: L1 L2 R1 R2 L3 L4
371 // Visual Run : L1 L2 R2 R1 L3 L4
372 BidiText bidiText(text, Range(0, text.size()), Bidi::DEFAULT_LTR);
373 auto it = bidiText.begin();
374 EXPECT_NE(bidiText.end(), it);
375 EXPECT_EQ(Range(0, ltr1Length), (*it).range);
376 EXPECT_FALSE((*it).isRtl);
377 ++it;
378 EXPECT_NE(bidiText.end(), it);
379 EXPECT_EQ(Range(ltr1Length, ltr1Length + rtlLength), (*it).range);
380 EXPECT_TRUE((*it).isRtl);
381 ++it;
382 EXPECT_NE(bidiText.end(), it);
383 EXPECT_EQ(Range(ltr1Length + rtlLength, ltr1Length + rtlLength + ltr2Length), (*it).range);
384 EXPECT_FALSE((*it).isRtl);
385 ++it;
386 EXPECT_EQ(bidiText.end(), it);
387 }
388 {
389 // Logical Run: L1 L2 R1 R2 L3 L4
390 // Visual Run : L1 L2 R2 R1 L3 L4
391 BidiText bidiText(text, Range(0, text.size()), Bidi::DEFAULT_RTL);
392 auto it = bidiText.begin();
393 EXPECT_NE(bidiText.end(), it);
394 EXPECT_EQ(Range(0, ltr1Length), (*it).range);
395 EXPECT_FALSE((*it).isRtl);
396 ++it;
397 EXPECT_NE(bidiText.end(), it);
398 EXPECT_EQ(Range(ltr1Length, ltr1Length + rtlLength), (*it).range);
399 EXPECT_TRUE((*it).isRtl);
400 ++it;
401 EXPECT_NE(bidiText.end(), it);
402 EXPECT_EQ(Range(ltr1Length + rtlLength, ltr1Length + rtlLength + ltr2Length), (*it).range);
403 EXPECT_FALSE((*it).isRtl);
404 ++it;
405 EXPECT_EQ(bidiText.end(), it);
406 }
407 {
408 // Logical Run: L1 L2 R1 R2 L3 L4
409 // Visual Run : L1 L2 R2 R1 L3 L4
410 BidiText bidiText(text, Range(0, text.size()), Bidi::FORCE_LTR);
411 auto it = bidiText.begin();
412 EXPECT_NE(bidiText.end(), it);
413 EXPECT_EQ(Range(0, ltr1Length + rtlLength + ltr2Length), (*it).range);
414 EXPECT_FALSE((*it).isRtl);
415 ++it;
416 EXPECT_EQ(bidiText.end(), it);
417 }
418 {
419 // Logical Run: L1 L2 R1 R2 L3 L4
420 // Visual Run : L1 L2 R2 R1 L3 L4
421 BidiText bidiText(text, Range(0, text.size()), Bidi::FORCE_RTL);
422 auto it = bidiText.begin();
423 EXPECT_NE(bidiText.end(), it);
424 EXPECT_EQ(Range(0, ltr1Length + rtlLength + ltr2Length), (*it).range);
425 EXPECT_TRUE((*it).isRtl);
426 ++it;
427 EXPECT_EQ(bidiText.end(), it);
428 }
429 }
430
TEST(BidiUtilsTest,RTL_LTR_RTL_CharText)431 TEST(BidiUtilsTest, RTL_LTR_RTL_CharText) {
432 auto text = utf8ToUtf16(std::string(RTL_1) + LTR_1 + RTL_2);
433 uint32_t ltrLength = utf8ToUtf16(LTR_1).size();
434 uint32_t rtl1Length = utf8ToUtf16(RTL_1).size();
435 uint32_t rtl2Length = utf8ToUtf16(RTL_2).size();
436 {
437 // Logical Run: R1 R2 L1 L2 R3 R4
438 // Visual Run : R2 R1 L1 L2 R4 R3
439 BidiText bidiText(text, Range(0, text.size()), Bidi::LTR);
440 auto it = bidiText.begin();
441 EXPECT_NE(bidiText.end(), it);
442 EXPECT_EQ(Range(0, rtl1Length), (*it).range);
443 EXPECT_TRUE((*it).isRtl);
444 ++it;
445 EXPECT_NE(bidiText.end(), it);
446 EXPECT_EQ(Range(rtl1Length, ltrLength + rtl1Length), (*it).range);
447 EXPECT_FALSE((*it).isRtl);
448 ++it;
449 EXPECT_NE(bidiText.end(), it);
450 EXPECT_EQ(Range(rtl1Length + ltrLength, text.size()), (*it).range);
451 EXPECT_TRUE((*it).isRtl);
452 ++it;
453 EXPECT_EQ(bidiText.end(), it);
454 }
455 {
456 // Logical Run: R1 R2 L1 L2 R3 R4
457 // Visual Run : R4 R3 L1 L2 R2 R1
458 BidiText bidiText(text, Range(0, text.size()), Bidi::RTL);
459 auto it = bidiText.begin();
460 EXPECT_NE(bidiText.end(), it);
461 EXPECT_EQ(Range(rtl1Length + ltrLength, text.size()), (*it).range);
462 EXPECT_TRUE((*it).isRtl);
463 ++it;
464 EXPECT_NE(bidiText.end(), it);
465 EXPECT_EQ(Range(rtl1Length, ltrLength + rtl1Length), (*it).range);
466 EXPECT_FALSE((*it).isRtl);
467 ++it;
468 EXPECT_NE(bidiText.end(), it);
469 EXPECT_EQ(Range(0, rtl1Length), (*it).range);
470 EXPECT_TRUE((*it).isRtl);
471 ++it;
472 EXPECT_EQ(bidiText.end(), it);
473 }
474 {
475 // Logical Run: R1 R2 L1 L2 R3 R4
476 // Visual Run : R4 R3 L1 L2 R2 R1
477 BidiText bidiText(text, Range(0, text.size()), Bidi::DEFAULT_LTR);
478 auto it = bidiText.begin();
479 EXPECT_NE(bidiText.end(), it);
480 EXPECT_EQ(Range(rtl1Length + ltrLength, text.size()), (*it).range);
481 EXPECT_TRUE((*it).isRtl);
482 ++it;
483 EXPECT_NE(bidiText.end(), it);
484 EXPECT_EQ(Range(rtl1Length, ltrLength + rtl1Length), (*it).range);
485 EXPECT_FALSE((*it).isRtl);
486 ++it;
487 EXPECT_NE(bidiText.end(), it);
488 EXPECT_EQ(Range(0, rtl1Length), (*it).range);
489 EXPECT_TRUE((*it).isRtl);
490 ++it;
491 EXPECT_EQ(bidiText.end(), it);
492 }
493 {
494 // Logical Run: R1 R2 L1 L2 R3 R4
495 // Visual Run : R4 R3 L1 L2 R2 R1
496 BidiText bidiText(text, Range(0, text.size()), Bidi::DEFAULT_RTL);
497 auto it = bidiText.begin();
498 EXPECT_NE(bidiText.end(), it);
499 EXPECT_EQ(Range(rtl1Length + ltrLength, text.size()), (*it).range);
500 EXPECT_TRUE((*it).isRtl);
501 ++it;
502 EXPECT_NE(bidiText.end(), it);
503 EXPECT_EQ(Range(rtl1Length, ltrLength + rtl1Length), (*it).range);
504 EXPECT_FALSE((*it).isRtl);
505 ++it;
506 EXPECT_NE(bidiText.end(), it);
507 EXPECT_EQ(Range(0, rtl1Length), (*it).range);
508 EXPECT_TRUE((*it).isRtl);
509 ++it;
510 EXPECT_EQ(bidiText.end(), it);
511 }
512 {
513 // Logical Run: R1 R2 L1 L2 R3 R4
514 // Visual Run : R1 R2 L1 L2 R3 R4
515 BidiText bidiText(text, Range(0, text.size()), Bidi::FORCE_LTR);
516 auto it = bidiText.begin();
517 EXPECT_NE(bidiText.end(), it);
518 EXPECT_EQ(Range(0, rtl1Length + ltrLength + rtl2Length), (*it).range);
519 EXPECT_FALSE((*it).isRtl);
520 ++it;
521 EXPECT_EQ(bidiText.end(), it);
522 }
523 {
524 // Logical Run: R1 R2 L1 L2 R3 R4
525 // Visual Run : R4 R3 L2 L1 R2 R1
526 BidiText bidiText(text, Range(0, text.size()), Bidi::FORCE_RTL);
527 auto it = bidiText.begin();
528 EXPECT_NE(bidiText.end(), it);
529 EXPECT_EQ(Range(0, rtl1Length + ltrLength + rtl2Length), (*it).range);
530 EXPECT_TRUE((*it).isRtl);
531 ++it;
532 EXPECT_EQ(bidiText.end(), it);
533 }
534 }
535
536 } // namespace minikin
537