[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 4 | |
[email protected] | 3a88e39 | 2012-10-31 21:32:10 +0000 | [diff] [blame] | 5 | library bidi_utils_test; |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 6 | |
[email protected] | 771dfd7 | 2013-01-13 01:11:07 +0000 | [diff] [blame] | 7 | import 'package:intl/intl.dart'; |
alanknight | 810432e | 2017-06-15 13:40:56 -0700 | [diff] [blame] | 8 | import 'package:test/test.dart'; |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 9 | |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 10 | // ignore_for_file: non_constant_identifier_names |
| 11 | |
alanknight | a110b9c | 2016-01-11 09:54:18 -0800 | [diff] [blame] | 12 | /// Tests the bidi utilities library. |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 13 | void main() { |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 14 | var LRE = '\u202A'; |
| 15 | var RLE = '\u202B'; |
| 16 | var PDF = '\u202C'; |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 17 | |
| 18 | test('isRtlLang', () { |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 19 | expect(Bidi.isRtlLanguage('en'), isFalse); |
| 20 | expect(Bidi.isRtlLanguage('fr'), isFalse); |
| 21 | expect(Bidi.isRtlLanguage('zh-CN'), isFalse); |
| 22 | expect(Bidi.isRtlLanguage('fil'), isFalse); |
| 23 | expect(Bidi.isRtlLanguage('az'), isFalse); |
| 24 | expect(Bidi.isRtlLanguage('iw-Latn'), isFalse); |
| 25 | expect(Bidi.isRtlLanguage('iw-LATN'), isFalse); |
| 26 | expect(Bidi.isRtlLanguage('iw_latn'), isFalse); |
| 27 | expect(Bidi.isRtlLanguage('ar'), isTrue); |
| 28 | expect(Bidi.isRtlLanguage('AR'), isTrue); |
| 29 | expect(Bidi.isRtlLanguage('iw'), isTrue); |
| 30 | expect(Bidi.isRtlLanguage('he'), isTrue); |
| 31 | expect(Bidi.isRtlLanguage('fa'), isTrue); |
| 32 | expect(Bidi.isRtlLanguage('ar-EG'), isTrue); |
| 33 | expect(Bidi.isRtlLanguage('az-Arab'), isTrue); |
| 34 | expect(Bidi.isRtlLanguage('az-ARAB-IR'), isTrue); |
| 35 | expect(Bidi.isRtlLanguage('az_arab_IR'), isTrue); |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 36 | Intl.withLocale('en_US', () { |
| 37 | expect(Bidi.isRtlLanguage(), isFalse); |
| 38 | }); |
| 39 | Intl.withLocale('ar', () { |
| 40 | expect(Bidi.isRtlLanguage(), isTrue); |
| 41 | }); |
| 42 | Intl.withLocale(null, () { |
| 43 | expect(Bidi.isRtlLanguage(), Bidi.isRtlLanguage(Intl.systemLocale)); |
| 44 | }); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 45 | }); |
| 46 | |
| 47 | test('hasAnyLtr', () { |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 48 | expect(Bidi.hasAnyLtr(''), isFalse); |
| 49 | expect(Bidi.hasAnyLtr('\u05e0\u05e1\u05e2'), isFalse); |
| 50 | expect(Bidi.hasAnyLtr('\u05e0\u05e1z\u05e2'), isTrue); |
| 51 | expect(Bidi.hasAnyLtr('123\t... \n'), isFalse); |
| 52 | expect(Bidi.hasAnyLtr('<br>123<', false), isTrue); |
| 53 | expect(Bidi.hasAnyLtr('<br>123<', true), isFalse); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 54 | }); |
| 55 | |
| 56 | test('hasAnyRtl', () { |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 57 | expect(Bidi.hasAnyRtl(''), isFalse); |
| 58 | expect(Bidi.hasAnyRtl('abc'), isFalse); |
| 59 | expect(Bidi.hasAnyRtl('ab\u05e0c'), isTrue); |
| 60 | expect(Bidi.hasAnyRtl('123\t... \n'), isFalse); |
| 61 | expect(Bidi.hasAnyRtl('<input value=\u05e0>123', false), isTrue); |
| 62 | expect(Bidi.hasAnyRtl('<input value=\u05e0>123', true), isFalse); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 63 | }); |
| 64 | |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 65 | test('endsWithLtr', () { |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 66 | expect(Bidi.endsWithLtr('a'), isTrue); |
| 67 | expect(Bidi.endsWithLtr('abc'), isTrue); |
| 68 | expect(Bidi.endsWithLtr('a (!)'), isTrue); |
| 69 | expect(Bidi.endsWithLtr('a.1'), isTrue); |
| 70 | expect(Bidi.endsWithLtr('http://www.google.com '), isTrue); |
| 71 | expect(Bidi.endsWithLtr('\u05e0a'), isTrue); |
| 72 | expect(Bidi.endsWithLtr(' \u05e0\u05e1a\u05e2\u05e3 a (!)'), isTrue); |
| 73 | expect(Bidi.endsWithLtr(''), isFalse); |
| 74 | expect(Bidi.endsWithLtr(' '), isFalse); |
| 75 | expect(Bidi.endsWithLtr('1'), isFalse); |
| 76 | expect(Bidi.endsWithLtr('\u05e0'), isFalse); |
| 77 | expect(Bidi.endsWithLtr('\u05e0 1(!)'), isFalse); |
| 78 | expect(Bidi.endsWithLtr('a\u05e0'), isFalse); |
| 79 | expect(Bidi.endsWithLtr('a abc\u05e0\u05e1def\u05e2. 1'), isFalse); |
| 80 | expect(Bidi.endsWithLtr(' \u05e0\u05e1a\u05e2 <', true), isFalse); |
| 81 | expect(Bidi.endsWithLtr(' \u05e0\u05e1a\u05e2 <', false), isTrue); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 82 | }); |
| 83 | |
| 84 | test('endsWithRtl', () { |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 85 | expect(Bidi.endsWithRtl('\u05e0'), isTrue); |
| 86 | expect(Bidi.endsWithRtl('\u05e0\u05e1\u05e2'), isTrue); |
| 87 | expect(Bidi.endsWithRtl('\u05e0 (!)'), isTrue); |
| 88 | expect(Bidi.endsWithRtl('\u05e0.1'), isTrue); |
| 89 | expect(Bidi.endsWithRtl('http://www.google.com/\u05e0 '), isTrue); |
| 90 | expect(Bidi.endsWithRtl('a\u05e0'), isTrue); |
| 91 | expect(Bidi.endsWithRtl(' a abc\u05e0def\u05e3. 1'), isTrue); |
| 92 | expect(Bidi.endsWithRtl(''), isFalse); |
| 93 | expect(Bidi.endsWithRtl(' '), isFalse); |
| 94 | expect(Bidi.endsWithRtl('1'), isFalse); |
| 95 | expect(Bidi.endsWithRtl('a'), isFalse); |
| 96 | expect(Bidi.endsWithRtl('a 1(!)'), isFalse); |
| 97 | expect(Bidi.endsWithRtl('\u05e0a'), isFalse); |
| 98 | expect(Bidi.endsWithRtl('\u05e0 \u05e0\u05e1ab\u05e2 a (!)'), isFalse); |
| 99 | expect(Bidi.endsWithRtl(' \u05e0\u05e1a\u05e2 <', true), isTrue); |
| 100 | expect(Bidi.endsWithRtl(' \u05e0\u05e1a\u05e2 <', false), isFalse); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 101 | }); |
| 102 | |
| 103 | test('guardBracketInHtml', () { |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 104 | var strWithRtl = 'asc \u05d0 (\u05d0\u05d0\u05d0)'; |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 105 | expect(Bidi.guardBracketInHtml(strWithRtl), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 106 | equals('asc \u05d0 <span dir=rtl>(\u05d0\u05d0\u05d0)</span>')); |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 107 | expect(Bidi.guardBracketInHtml(strWithRtl, true), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 108 | equals('asc \u05d0 <span dir=rtl>(\u05d0\u05d0\u05d0)</span>')); |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 109 | expect(Bidi.guardBracketInHtml(strWithRtl, false), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 110 | equals('asc \u05d0 <span dir=ltr>(\u05d0\u05d0\u05d0)</span>')); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 111 | |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 112 | var strWithRtl2 = '\u05d0 a (asc:))'; |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 113 | expect(Bidi.guardBracketInHtml(strWithRtl2), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 114 | equals('\u05d0 a <span dir=rtl>(asc:))</span>')); |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 115 | expect(Bidi.guardBracketInHtml(strWithRtl2, true), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 116 | equals('\u05d0 a <span dir=rtl>(asc:))</span>')); |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 117 | expect(Bidi.guardBracketInHtml(strWithRtl2, false), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 118 | equals('\u05d0 a <span dir=ltr>(asc:))</span>')); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 119 | |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 120 | var strWithoutRtl = 'a (asc) {{123}}'; |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 121 | expect(Bidi.guardBracketInHtml(strWithoutRtl), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 122 | equals('a <span dir=ltr>(asc)</span> <span dir=ltr>{{123}}</span>')); |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 123 | expect(Bidi.guardBracketInHtml(strWithoutRtl, true), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 124 | equals('a <span dir=rtl>(asc)</span> <span dir=rtl>{{123}}</span>')); |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 125 | expect(Bidi.guardBracketInHtml(strWithoutRtl, false), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 126 | equals('a <span dir=ltr>(asc)</span> <span dir=ltr>{{123}}</span>')); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 127 | }); |
| 128 | |
| 129 | test('guardBracketInText', () { |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 130 | var strWithRtl = 'asc \u05d0 (\u05d0\u05d0\u05d0)'; |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 131 | expect(Bidi.guardBracketInText(strWithRtl), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 132 | equals('asc \u05d0 \u200f(\u05d0\u05d0\u05d0)\u200f')); |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 133 | expect(Bidi.guardBracketInText(strWithRtl, true), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 134 | equals('asc \u05d0 \u200f(\u05d0\u05d0\u05d0)\u200f')); |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 135 | expect(Bidi.guardBracketInText(strWithRtl, false), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 136 | equals('asc \u05d0 \u200e(\u05d0\u05d0\u05d0)\u200e')); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 137 | |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 138 | var strWithRtl2 = '\u05d0 a (asc:))'; |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 139 | expect(Bidi.guardBracketInText(strWithRtl2), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 140 | equals('\u05d0 a \u200f(asc:))\u200f')); |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 141 | expect(Bidi.guardBracketInText(strWithRtl2, true), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 142 | equals('\u05d0 a \u200f(asc:))\u200f')); |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 143 | expect(Bidi.guardBracketInText(strWithRtl2, false), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 144 | equals('\u05d0 a \u200e(asc:))\u200e')); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 145 | |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 146 | var strWithoutRtl = 'a (asc) {{123}}'; |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 147 | expect(Bidi.guardBracketInText(strWithoutRtl), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 148 | equals('a \u200e(asc)\u200e \u200e{{123}}\u200e')); |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 149 | expect(Bidi.guardBracketInText(strWithoutRtl, true), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 150 | equals('a \u200f(asc)\u200f \u200f{{123}}\u200f')); |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 151 | expect(Bidi.guardBracketInText(strWithoutRtl, false), |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 152 | equals('a \u200e(asc)\u200e \u200e{{123}}\u200e')); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 153 | }); |
| 154 | |
| 155 | test('enforceRtlInHtml', () { |
| 156 | var str = '<div> first <br> second </div>'; |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 157 | expect(Bidi.enforceRtlInHtml(str), |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 158 | equals('<div dir=rtl> first <br> second </div>')); |
| 159 | str = 'first second'; |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 160 | expect(Bidi.enforceRtlInHtml(str), |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 161 | equals('\n<span dir=rtl>first second</span>')); |
| 162 | }); |
| 163 | |
| 164 | test('enforceRtlInText', () { |
| 165 | var str = 'first second'; |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 166 | expect(Bidi.enforceRtlInText(str), equals('${RLE}first second$PDF')); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 167 | }); |
| 168 | |
| 169 | test('enforceLtrInHtml', () { |
| 170 | var str = '<div> first <br> second </div>'; |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 171 | expect(Bidi.enforceLtrInHtml(str), |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 172 | equals('<div dir=ltr> first <br> second </div>')); |
| 173 | str = 'first second'; |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 174 | expect(Bidi.enforceLtrInHtml(str), |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 175 | equals('\n<span dir=ltr>first second</span>')); |
| 176 | }); |
| 177 | |
| 178 | test('enforceLtrInText', () { |
| 179 | var str = 'first second'; |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 180 | expect(Bidi.enforceLtrInText(str), equals('${LRE}first second$PDF')); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 181 | }); |
| 182 | |
| 183 | test('normalizeHebrewQuote', () { |
[email protected] | 6345a92 | 2012-10-04 21:15:20 +0000 | [diff] [blame] | 184 | expect(Bidi.normalizeHebrewQuote('\u05d0"'), equals('\u05d0\u05f4')); |
| 185 | expect(Bidi.normalizeHebrewQuote('\u05d0\''), equals('\u05d0\u05f3')); |
| 186 | expect(Bidi.normalizeHebrewQuote('\u05d0"\u05d0\''), |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 187 | equals('\u05d0\u05f4\u05d0\u05f3')); |
| 188 | }); |
| 189 | |
| 190 | test('estimateDirectionOfText', () { |
[email protected] | 5ed533b | 2012-10-18 18:21:38 +0000 | [diff] [blame] | 191 | expect(Bidi.estimateDirectionOfText('', isHtml: false).value, |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 192 | equals(TextDirection.UNKNOWN.value)); |
[email protected] | 5ed533b | 2012-10-18 18:21:38 +0000 | [diff] [blame] | 193 | expect(Bidi.estimateDirectionOfText(' ', isHtml: false).value, |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 194 | equals(TextDirection.UNKNOWN.value)); |
[email protected] | 5ed533b | 2012-10-18 18:21:38 +0000 | [diff] [blame] | 195 | expect(Bidi.estimateDirectionOfText('! (...)', isHtml: false).value, |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 196 | equals(TextDirection.UNKNOWN.value)); |
Kevin Moore | 4f4b8b4 | 2015-04-24 16:34:31 -0700 | [diff] [blame] | 197 | expect( |
| 198 | Bidi.estimateDirectionOfText('All-Ascii content', isHtml: false).value, |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 199 | equals(TextDirection.LTR.value)); |
[email protected] | 5ed533b | 2012-10-18 18:21:38 +0000 | [diff] [blame] | 200 | expect(Bidi.estimateDirectionOfText('-17.0%', isHtml: false).value, |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 201 | equals(TextDirection.LTR.value)); |
[email protected] | 5ed533b | 2012-10-18 18:21:38 +0000 | [diff] [blame] | 202 | expect(Bidi.estimateDirectionOfText('http://foo/bar/', isHtml: false).value, |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 203 | equals(TextDirection.LTR.value)); |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 204 | expect( |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 205 | Bidi.estimateDirectionOfText( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 206 | 'http://foo/bar/?s=\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0' |
| 207 | '\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0' |
| 208 | '\u05d0\u05d0\u05d0\u05d0\u05d0') |
| 209 | .value, |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 210 | equals(TextDirection.LTR.value)); |
[email protected] | 5ed533b | 2012-10-18 18:21:38 +0000 | [diff] [blame] | 211 | expect(Bidi.estimateDirectionOfText('\u05d0', isHtml: false).value, |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 212 | equals(TextDirection.RTL.value)); |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 213 | expect( |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 214 | Bidi.estimateDirectionOfText('9 \u05d0 -> 17.5, 23, 45, 19', |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 215 | isHtml: false) |
| 216 | .value, |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 217 | equals(TextDirection.RTL.value)); |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 218 | expect( |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 219 | Bidi.estimateDirectionOfText( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 220 | 'http://foo/bar/ \u05d0 http://foo2/bar2/ http://foo3/bar3/') |
| 221 | .value, |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 222 | equals(TextDirection.RTL.value)); |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 223 | expect( |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 224 | Bidi.estimateDirectionOfText( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 225 | '\u05d0\u05d9\u05df \u05de\u05de\u05e9 \u05de\u05d4 \u05dc\u05e8\u05d0' |
| 226 | '\u05d5\u05ea: \u05dc\u05d0 \u05e6\u05d9\u05dc\u05de\u05ea\u05d9 \u05d4' |
| 227 | '\u05e8\u05d1\u05d4 \u05d5\u05d2\u05dd \u05d0\u05dd \u05d4\u05d9\u05d9' |
| 228 | '\u05ea\u05d9 \u05de\u05e6\u05dc\u05dd, \u05d4\u05d9\u05d4 \u05e9' |
| 229 | '\u05dd') |
| 230 | .value, |
| 231 | equals(TextDirection.RTL.value)); |
| 232 | expect( |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 233 | Bidi.estimateDirectionOfText( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 234 | '\u05db\u05d0 - http://geek.co.il/gallery/v/2007-06 - \u05d0\u05d9' |
| 235 | '\u05df \u05de\u05de\u05e9 \u05de\u05d4 \u05dc\u05e8\u05d0\u05d5\u05ea:' |
| 236 | ' \u05dc\u05d0 \u05e6\u05d9\u05dc\u05de\u05ea\u05d9 \u05d4\u05e8\u05d1 ' |
| 237 | '\u05d5\u05d2\u05dd \u05d0\u05dd \u05d4\u05d9\u05d9\u05d9 \u05de\u05e6' |
| 238 | '\u05dc\u05dd, \u05d4\u05d9\u05d4 \u05e9\u05dd \u05d1\u05e2\u05d9\u05e7' |
| 239 | ' \u05d4\u05e8\u05d1\u05d4 \u05d0\u05e0\u05e9\u05d9\u05dd. \u05de\u05d4' |
| 240 | ' \u05e9\u05db\u05df - \u05d0\u05e4\u05e9\u05e8 \u05dc\u05e0\u05e6' |
| 241 | '\u05dc \u05d0\u05ea \u05d4\u05d4 \u05d3\u05d6\u05de\u05e0\u05d5 ' |
| 242 | '\u05dc\u05d4\u05e1\u05ea\u05db\u05dc \u05e2\u05dc \u05db\u05de\u05d4 ' |
| 243 | '\u05ea\u05de\u05d5\u05e0\u05d5\u05ea \u05de\u05e9\u05e9\u05e2\u05d5' |
| 244 | '\u05ea \u05d9\u05e9\u05e0\u05d5 \u05d9\u05d5\u05ea\u05e8 \u05e9\u05d9' |
| 245 | '\u05e9 \u05dc\u05d9 \u05d1\u05d0\u05ea\u05e8', |
| 246 | isHtml: false) |
| 247 | .value, |
| 248 | equals(TextDirection.RTL.value)); |
| 249 | expect( |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 250 | Bidi.estimateDirectionOfText( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 251 | 'CAPTCHA \u05de\u05e9\u05d5\u05db\u05dc\u05dc ' |
| 252 | '\u05de\u05d3\u05d9?') |
| 253 | .value, |
| 254 | equals(TextDirection.RTL.value)); |
| 255 | expect( |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 256 | Bidi.estimateDirectionOfText( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 257 | 'Yes Prime Minister \u05e2\u05d3\u05db\u05d5\u05df. \u05e9\u05d0\u05dc' |
| 258 | '\u05d5 \u05d0\u05d5\u05ea\u05d9 \u05de\u05d4 \u05d0\u05e0\u05d9 ' |
| 259 | '\u05e8\u05d5\u05e6\u05d4 \u05de\u05ea\u05e0\u05d4 \u05dc\u05d7' |
| 260 | '\u05d2') |
| 261 | .value, |
| 262 | equals(TextDirection.RTL.value)); |
| 263 | expect( |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 264 | Bidi.estimateDirectionOfText( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 265 | '17.4.02 \u05e9\u05e2\u05d4:13-20 .15-00 .\u05dc\u05d0 \u05d4\u05d9' |
| 266 | '\u05d9\u05ea\u05d9 \u05db\u05d0\u05df.') |
| 267 | .value, |
| 268 | equals(TextDirection.RTL.value)); |
| 269 | expect( |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 270 | Bidi.estimateDirectionOfText( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 271 | '5710 5720 5730. \u05d4\u05d3\u05dc\u05ea. \u05d4\u05e0\u05e9\u05d9' |
| 272 | '\u05e7\u05d4', |
| 273 | isHtml: false) |
| 274 | .value, |
| 275 | equals(TextDirection.RTL.value)); |
| 276 | expect( |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 277 | Bidi.estimateDirectionOfText( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 278 | '\u05d4\u05d3\u05dc\u05ea http://www.google.com ' |
| 279 | 'http://www.gmail.com') |
| 280 | .value, |
| 281 | equals(TextDirection.RTL.value)); |
| 282 | expect( |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 283 | Bidi.estimateDirectionOfText( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 284 | '\u05d4\u05d3\u05dc <some quite nasty html mark up>') |
| 285 | .value, |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 286 | equals(TextDirection.LTR.value)); |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 287 | expect( |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 288 | Bidi.estimateDirectionOfText( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 289 | '\u05d4\u05d3\u05dc <some quite nasty html mark up>') |
| 290 | .value, |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 291 | equals(TextDirection.LTR.value)); |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 292 | expect( |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 293 | Bidi.estimateDirectionOfText('\u05d4\u05d3\u05dc\u05ea & < >') |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 294 | .value, |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 295 | equals(TextDirection.LTR.value)); |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 296 | expect( |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 297 | Bidi.estimateDirectionOfText('\u05d4\u05d3\u05dc\u05ea & < >', |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 298 | isHtml: true) |
| 299 | .value, |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 300 | equals(TextDirection.RTL.value)); |
| 301 | }); |
| 302 | |
| 303 | test('detectRtlDirectionality', () { |
| 304 | var bidiText = []; |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 305 | var item = SampleItem('Pure Ascii content'); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 306 | bidiText.add(item); |
| 307 | |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 308 | item = SampleItem( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 309 | '\u05d0\u05d9\u05df \u05de\u05de\u05e9 \u05de\u05d4' |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 310 | ' \u05dc\u05e8\u05d0\u05d5\u05ea: \u05dc\u05d0 \u05e6\u05d9\u05dc' |
| 311 | '\u05de\u05ea\u05d9 \u05d4\u05e8\u05d1\u05d4 \u05d5\u05d2\u05dd ' |
| 312 | '\u05d0\u05dd \u05d4\u05d9\u05d9\u05ea\u05d9 \u05de\u05e6\u05dc\u05dd, ' |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 313 | '\u05d4\u05d9\u05d4 \u05e9\u05dd', |
| 314 | true); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 315 | bidiText.add(item); |
| 316 | |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 317 | item = SampleItem( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 318 | '\u05db\u05d0\u05df - http://geek.co.il/gallery/v/' |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 319 | '2007-06 - \u05d0\u05d9\u05df \u05de\u05de\u05e9 \u05de\u05d4 \u05dc' |
| 320 | '\u05e8\u05d0\u05d5\u05ea: \u05dc\u05d0 \u05e6\u05d9\u05dc\u05de\u05ea' |
| 321 | '\u05d9 \u05d4\u05e8\u05d1\u05d4 \u05d5\u05d2\u05dd \u05d0\u05dd \u05d4' |
| 322 | '\u05d9\u05d9\u05ea\u05d9 \u05de\u05e6\u05dc\u05dd, \u05d4\u05d9\u05d4 ' |
| 323 | '\u05e9\u05dd \u05d1\u05e2\u05d9\u05e7\u05e8 \u05d4\u05e8\u05d1\u05d4 ' |
| 324 | '\u05d0\u05e0\u05e9\u05d9\u05dd. \u05de\u05d4 \u05e9\u05db\u05df - ' |
| 325 | '\u05d0\u05e4\u05e9\u05e8 \u05dc\u05e0\u05e6\u05dc \u05d0\u05ea \u05d4' |
| 326 | '\u05d4\u05d3\u05d6\u05de\u05e0\u05d5\u05ea \u05dc\u05d4\u05e1\u05ea' |
| 327 | '\u05db\u05dc \u05e2\u05dc \u05db\u05de\u05d4 \u05ea\u05de\u05d5\u05e0' |
| 328 | '\u05d5\u05ea \u05de\u05e9\u05e2\u05e9\u05e2\u05d5\u05ea \u05d9\u05e9' |
| 329 | '\u05e0\u05d5\u05ea \u05d9\u05d5\u05ea\u05e8 \u05e9\u05d9\u05e9 \u05dc' |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 330 | '\u05d9 \u05d1\u05d0\u05ea\u05e8', |
| 331 | true); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 332 | bidiText.add(item); |
| 333 | |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 334 | item = SampleItem( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 335 | 'CAPTCHA \u05de\u05e9\u05d5\u05db\u05dc\u05dc ' |
| 336 | '\u05de\u05d3\u05d9?', |
| 337 | true); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 338 | bidiText.add(item); |
| 339 | |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 340 | item = SampleItem( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 341 | 'Yes Prime Minister \u05e2\u05d3\u05db\u05d5\u05df. ' |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 342 | '\u05e9\u05d0\u05dc\u05d5 \u05d0\u05d5\u05ea\u05d9 \u05de\u05d4 \u05d0' |
| 343 | '\u05e0\u05d9 \u05e8\u05d5\u05e6\u05d4 \u05de\u05ea\u05e0\u05d4 ' |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 344 | '\u05dc\u05d7\u05d2', |
| 345 | true); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 346 | bidiText.add(item); |
| 347 | |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 348 | item = SampleItem( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 349 | '17.4.02 \u05e9\u05e2\u05d4:13-20 .15-00 .\u05dc' |
| 350 | '\u05d0 \u05d4\u05d9\u05d9\u05ea\u05d9 \u05db\u05d0\u05df.', |
| 351 | true); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 352 | bidiText.add(item); |
| 353 | |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 354 | item = SampleItem( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 355 | '5710 5720 5730. \u05d4\u05d3\u05dc\u05ea. \u05d4' |
| 356 | '\u05e0\u05e9\u05d9\u05e7\u05d4', |
| 357 | true); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 358 | bidiText.add(item); |
| 359 | |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 360 | item = SampleItem( |
alanknight | eb20e1b | 2017-02-03 12:57:58 -0800 | [diff] [blame] | 361 | '\u05d4\u05d3\u05dc\u05ea http://www.google.com ' |
| 362 | 'http://www.gmail.com', |
| 363 | true); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 364 | bidiText.add(item); |
| 365 | |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 366 | item = SampleItem('>\u05d4<', true, true); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 367 | bidiText.add(item); |
| 368 | |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 369 | item = SampleItem('>\u05d4<', false); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 370 | bidiText.add(item); |
| 371 | |
| 372 | for (var i = 0; i < bidiText.length; i++) { |
Kevin Moore | 4f4b8b4 | 2015-04-24 16:34:31 -0700 | [diff] [blame] | 373 | var isRtlDir = Bidi.detectRtlDirectionality(bidiText[i].text, |
| 374 | isHtml: bidiText[i].isHtml); |
alanknight | 5f9d4d0 | 2015-12-16 15:55:46 -0800 | [diff] [blame] | 375 | |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 376 | if (isRtlDir != bidiText[i].isRtl) { |
| 377 | var str = '"${bidiText[i].text} " should be ' |
Kevin Moore | 4f4b8b4 | 2015-04-24 16:34:31 -0700 | [diff] [blame] | 378 | '${bidiText[i].isRtl ? "rtl" : "ltr"} but detected as ' |
| 379 | '${isRtlDir ? "rtl" : "ltr"}'; |
alanknight | 5f9d4d0 | 2015-12-16 15:55:46 -0800 | [diff] [blame] | 380 | fail(str); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 381 | } |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 382 | } |
| 383 | }); |
| 384 | } |
| 385 | |
| 386 | class SampleItem { |
| 387 | String text; |
| 388 | bool isRtl; |
| 389 | bool isHtml; |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 390 | SampleItem([this.text = '', this.isRtl = false, this.isHtml = false]); |
[email protected] | 0ba76c3 | 2012-08-21 21:32:12 +0000 | [diff] [blame] | 391 | } |