Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: base/i18n/rtl_unittest.cc

Issue 112063003: Implement eliding/truncating at end in RenderText (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Synced Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/i18n/rtl.cc ('k') | chrome/browser/ui/views/omnibox/omnibox_result_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/i18n/rtl.h" 5 #include "base/i18n/rtl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 28 matching lines...) Expand all
39 class RTLTest : public PlatformTest { 39 class RTLTest : public PlatformTest {
40 }; 40 };
41 41
42 TEST_F(RTLTest, GetFirstStrongCharacterDirection) { 42 TEST_F(RTLTest, GetFirstStrongCharacterDirection) {
43 struct { 43 struct {
44 const wchar_t* text; 44 const wchar_t* text;
45 TextDirection direction; 45 TextDirection direction;
46 } cases[] = { 46 } cases[] = {
47 // Test pure LTR string. 47 // Test pure LTR string.
48 { L"foo bar", LEFT_TO_RIGHT }, 48 { L"foo bar", LEFT_TO_RIGHT },
49 // Test pure RTL string.
50 { L"\x05d0\x05d1\x05d2 \x05d3\x0d4\x05d5", RIGHT_TO_LEFT},
49 // Test bidi string in which the first character with strong directionality 51 // Test bidi string in which the first character with strong directionality
50 // is a character with type L. 52 // is a character with type L.
51 { L"foo \x05d0 bar", LEFT_TO_RIGHT }, 53 { L"foo \x05d0 bar", LEFT_TO_RIGHT },
52 // Test bidi string in which the first character with strong directionality 54 // Test bidi string in which the first character with strong directionality
53 // is a character with type R. 55 // is a character with type R.
54 { L"\x05d0 foo bar", RIGHT_TO_LEFT }, 56 { L"\x05d0 foo bar", RIGHT_TO_LEFT },
55 // Test bidi string which starts with a character with weak directionality 57 // Test bidi string which starts with a character with weak directionality
56 // and in which the first character with strong directionality is a 58 // and in which the first character with strong directionality is a
57 // character with type L. 59 // character with type L.
58 { L"!foo \x05d0 bar", LEFT_TO_RIGHT }, 60 { L"!foo \x05d0 bar", LEFT_TO_RIGHT },
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 #error wchar_t should be either UTF-16 or UTF-32 102 #error wchar_t should be either UTF-16 or UTF-32
101 #endif 103 #endif
102 LEFT_TO_RIGHT }, 104 LEFT_TO_RIGHT },
103 }; 105 };
104 106
105 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) 107 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i)
106 EXPECT_EQ(cases[i].direction, 108 EXPECT_EQ(cases[i].direction,
107 GetFirstStrongCharacterDirection(WideToUTF16(cases[i].text))); 109 GetFirstStrongCharacterDirection(WideToUTF16(cases[i].text)));
108 } 110 }
109 111
112
113 // Note that the cases with LRE, LRO, RLE and RLO are invalid for
114 // GetLastStrongCharacterDirection because they should be followed by PDF
115 // character.
116 TEST_F(RTLTest, GetLastStrongCharacterDirection) {
117 struct {
118 const wchar_t* text;
119 TextDirection direction;
120 } cases[] = {
121 // Test pure LTR string.
122 { L"foo bar", LEFT_TO_RIGHT },
123 // Test pure RTL string.
124 { L"\x05d0\x05d1\x05d2 \x05d3\x0d4\x05d5", RIGHT_TO_LEFT},
125 // Test bidi string in which the last character with strong directionality
126 // is a character with type L.
127 { L"foo \x05d0 bar", LEFT_TO_RIGHT },
128 // Test bidi string in which the last character with strong directionality
129 // is a character with type R.
130 { L"\x05d0 foo bar \x05d3", RIGHT_TO_LEFT },
131 // Test bidi string which ends with a character with weak directionality
132 // and in which the last character with strong directionality is a
133 // character with type L.
134 { L"!foo \x05d0 bar!", LEFT_TO_RIGHT },
135 // Test bidi string which ends with a character with weak directionality
136 // and in which the last character with strong directionality is a
137 // character with type R.
138 { L",\x05d0 foo bar \x05d1,", RIGHT_TO_LEFT },
139 // Test bidi string in which the last character with strong directionality
140 // is a character with type AL.
141 { L"\x0622 foo \x05d0 bar \x0622", RIGHT_TO_LEFT },
142 // Test a string without strong directionality characters.
143 { L",!.{}", LEFT_TO_RIGHT },
144 // Test empty string.
145 { L"", LEFT_TO_RIGHT },
146 // Test characters in non-BMP (e.g. Phoenician letters. Please refer to
147 // http://demo.icu-project.org/icu-bin/ubrowse?scr=151&b=10910 for more
148 // information).
149 {
150 #if defined(WCHAR_T_IS_UTF32)
151 L"abc 123" L" ! \x10910 !",
152 #elif defined(WCHAR_T_IS_UTF16)
153 L"abc 123" L" ! \xd802\xdd10 !",
154 #else
155 #error wchar_t should be either UTF-16 or UTF-32
156 #endif
157 RIGHT_TO_LEFT },
158 {
159 #if defined(WCHAR_T_IS_UTF32)
160 L"abc 123" L" ! \x10401 !",
161 #elif defined(WCHAR_T_IS_UTF16)
162 L"abc 123" L" ! \xd801\xdc01 !",
163 #else
164 #error wchar_t should be either UTF-16 or UTF-32
165 #endif
166 LEFT_TO_RIGHT },
167 };
168
169 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i)
170 EXPECT_EQ(cases[i].direction,
171 GetLastStrongCharacterDirection(WideToUTF16(cases[i].text)));
172 }
173
110 TEST_F(RTLTest, GetStringDirection) { 174 TEST_F(RTLTest, GetStringDirection) {
111 struct { 175 struct {
112 const wchar_t* text; 176 const wchar_t* text;
113 TextDirection direction; 177 TextDirection direction;
114 } cases[] = { 178 } cases[] = {
115 // Test pure LTR string. 179 // Test pure LTR string.
116 { L"foobar", LEFT_TO_RIGHT }, 180 { L"foobar", LEFT_TO_RIGHT },
117 { L".foobar", LEFT_TO_RIGHT }, 181 { L".foobar", LEFT_TO_RIGHT },
118 { L"foo, bar", LEFT_TO_RIGHT }, 182 { L"foo, bar", LEFT_TO_RIGHT },
119 // Test pure LTR with strong directionality characters of type LRE. 183 // Test pure LTR with strong directionality characters of type LRE.
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 EXPECT_EQ(test_case, adjusted_string) << " for test case [" << test_case 440 EXPECT_EQ(test_case, adjusted_string) << " for test case [" << test_case
377 << "] with IsRTL() == " << IsRTL(); 441 << "] with IsRTL() == " << IsRTL();
378 } 442 }
379 } 443 }
380 444
381 EXPECT_EQ(was_rtl, IsRTL()); 445 EXPECT_EQ(was_rtl, IsRTL());
382 } 446 }
383 447
384 } // namespace i18n 448 } // namespace i18n
385 } // namespace base 449 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/rtl.cc ('k') | chrome/browser/ui/views/omnibox/omnibox_result_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698