| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 #library('bidi_utils_test'); | 6 #library('bidi_utils_test'); |
| 7 | 7 |
| 8 #import('../../../lib/i18n/intl.dart'); | 8 #import('../../../lib/i18n/intl.dart'); |
| 9 #import('../../../lib/unittest/unittest.dart'); | 9 #import('../../../lib/unittest/unittest.dart'); |
| 10 | 10 |
| 11 /** | 11 /** |
| 12 * Tests the bidi utilities library. | 12 * Tests the bidi utilities library. |
| 13 */ | 13 */ |
| 14 main() { | 14 main() { |
| 15 var LRE = '\u202A'; | 15 var LRE = '\u202A'; |
| 16 var RLE = '\u202B'; | 16 var RLE = '\u202B'; |
| 17 var PDF = '\u202C'; | 17 var PDF = '\u202C'; |
| 18 var LRM = '\u200E'; | 18 var LRM = '\u200E'; |
| 19 var RLM = '\u200F'; | 19 var RLM = '\u200F'; |
| 20 | 20 |
| 21 test('isRtlLang', () { | 21 test('isRtlLang', () { |
| 22 expect(BidiUtils.isRtlLanguage('en'), isFalse); | 22 expect(isRtlLanguage('en'), isFalse); |
| 23 expect(BidiUtils.isRtlLanguage('fr'), isFalse); | 23 expect(isRtlLanguage('fr'), isFalse); |
| 24 expect(BidiUtils.isRtlLanguage('zh-CN'), isFalse); | 24 expect(isRtlLanguage('zh-CN'), isFalse); |
| 25 expect(BidiUtils.isRtlLanguage('fil'), isFalse); | 25 expect(isRtlLanguage('fil'), isFalse); |
| 26 expect(BidiUtils.isRtlLanguage('az'), isFalse); | 26 expect(isRtlLanguage('az'), isFalse); |
| 27 expect(BidiUtils.isRtlLanguage('iw-Latn'), isFalse); | 27 expect(isRtlLanguage('iw-Latn'), isFalse); |
| 28 expect(BidiUtils.isRtlLanguage('iw-LATN'), isFalse); | 28 expect(isRtlLanguage('iw-LATN'), isFalse); |
| 29 expect(BidiUtils.isRtlLanguage('iw_latn'), isFalse); | 29 expect(isRtlLanguage('iw_latn'), isFalse); |
| 30 expect(BidiUtils.isRtlLanguage('ar'), isTrue); | 30 expect(isRtlLanguage('ar'), isTrue); |
| 31 expect(BidiUtils.isRtlLanguage('AR'), isTrue); | 31 expect(isRtlLanguage('AR'), isTrue); |
| 32 expect(BidiUtils.isRtlLanguage('iw'), isTrue); | 32 expect(isRtlLanguage('iw'), isTrue); |
| 33 expect(BidiUtils.isRtlLanguage('he'), isTrue); | 33 expect(isRtlLanguage('he'), isTrue); |
| 34 expect(BidiUtils.isRtlLanguage('fa'), isTrue); | 34 expect(isRtlLanguage('fa'), isTrue); |
| 35 expect(BidiUtils.isRtlLanguage('ar-EG'), isTrue); | 35 expect(isRtlLanguage('ar-EG'), isTrue); |
| 36 expect(BidiUtils.isRtlLanguage('az-Arab'), isTrue); | 36 expect(isRtlLanguage('az-Arab'), isTrue); |
| 37 expect(BidiUtils.isRtlLanguage('az-ARAB-IR'), isTrue); | 37 expect(isRtlLanguage('az-ARAB-IR'), isTrue); |
| 38 expect(BidiUtils.isRtlLanguage('az_arab_IR'), isTrue); | 38 expect(isRtlLanguage('az_arab_IR'), isTrue); |
| 39 }); | 39 }); |
| 40 | 40 |
| 41 test('hasAnyLtr', () { | 41 test('hasAnyLtr', () { |
| 42 expect(BidiUtils.hasAnyLtr(''), isFalse); | 42 expect(hasAnyLtr(''), isFalse); |
| 43 expect(BidiUtils.hasAnyLtr('\u05e0\u05e1\u05e2'), isFalse); | 43 expect(hasAnyLtr('\u05e0\u05e1\u05e2'), isFalse); |
| 44 expect(BidiUtils.hasAnyLtr('\u05e0\u05e1z\u05e2'), isTrue); | 44 expect(hasAnyLtr('\u05e0\u05e1z\u05e2'), isTrue); |
| 45 expect(BidiUtils.hasAnyLtr('123\t... \n'), isFalse); | 45 expect(hasAnyLtr('123\t... \n'), isFalse); |
| 46 expect(BidiUtils.hasAnyLtr('<br>123<', false), isTrue); | 46 expect(hasAnyLtr('<br>123<', false), isTrue); |
| 47 expect(BidiUtils.hasAnyLtr('<br>123<', true), isFalse); | 47 expect(hasAnyLtr('<br>123<', true), isFalse); |
| 48 }); | 48 }); |
| 49 | 49 |
| 50 test('hasAnyRtl', () { | 50 test('hasAnyRtl', () { |
| 51 expect(BidiUtils.hasAnyRtl(''), isFalse); | 51 expect(hasAnyRtl(''), isFalse); |
| 52 expect(BidiUtils.hasAnyRtl('abc'), isFalse); | 52 expect(hasAnyRtl('abc'), isFalse); |
| 53 expect(BidiUtils.hasAnyRtl('ab\u05e0c'), isTrue); | 53 expect(hasAnyRtl('ab\u05e0c'), isTrue); |
| 54 expect(BidiUtils.hasAnyRtl('123\t... \n'), isFalse); | 54 expect(hasAnyRtl('123\t... \n'), isFalse); |
| 55 expect(BidiUtils.hasAnyRtl('<input value=\u05e0>123', false), isTrue); | 55 expect(hasAnyRtl('<input value=\u05e0>123', false), isTrue); |
| 56 expect(BidiUtils.hasAnyRtl('<input value=\u05e0>123', true), isFalse); | 56 expect(hasAnyRtl('<input value=\u05e0>123', true), isFalse); |
| 57 }); | 57 }); |
| 58 | 58 |
| 59 | 59 |
| 60 test('endsWithLtr', () { | 60 test('endsWithLtr', () { |
| 61 expect(BidiUtils.endsWithLtr('a'), isTrue); | 61 expect(endsWithLtr('a'), isTrue); |
| 62 expect(BidiUtils.endsWithLtr('abc'), isTrue); | 62 expect(endsWithLtr('abc'), isTrue); |
| 63 expect(BidiUtils.endsWithLtr('a (!)'), isTrue); | 63 expect(endsWithLtr('a (!)'), isTrue); |
| 64 expect(BidiUtils.endsWithLtr('a.1'), isTrue); | 64 expect(endsWithLtr('a.1'), isTrue); |
| 65 expect(BidiUtils.endsWithLtr('http://www.google.com '), isTrue); | 65 expect(endsWithLtr('http://www.google.com '), isTrue); |
| 66 expect(BidiUtils.endsWithLtr('\u05e0a'), isTrue); | 66 expect(endsWithLtr('\u05e0a'), isTrue); |
| 67 expect(BidiUtils.endsWithLtr(' \u05e0\u05e1a\u05e2\u05e3 a (!)'), isTrue); | 67 expect(endsWithLtr(' \u05e0\u05e1a\u05e2\u05e3 a (!)'), isTrue); |
| 68 expect(BidiUtils.endsWithLtr(''), isFalse); | 68 expect(endsWithLtr(''), isFalse); |
| 69 expect(BidiUtils.endsWithLtr(' '), isFalse); | 69 expect(endsWithLtr(' '), isFalse); |
| 70 expect(BidiUtils.endsWithLtr('1'), isFalse); | 70 expect(endsWithLtr('1'), isFalse); |
| 71 expect(BidiUtils.endsWithLtr('\u05e0'), isFalse); | 71 expect(endsWithLtr('\u05e0'), isFalse); |
| 72 expect(BidiUtils.endsWithLtr('\u05e0 1(!)'), isFalse); | 72 expect(endsWithLtr('\u05e0 1(!)'), isFalse); |
| 73 expect(BidiUtils.endsWithLtr('a\u05e0'), isFalse); | 73 expect(endsWithLtr('a\u05e0'), isFalse); |
| 74 expect(BidiUtils.endsWithLtr('a abc\u05e0\u05e1def\u05e2. 1'), isFalse); | 74 expect(endsWithLtr('a abc\u05e0\u05e1def\u05e2. 1'), isFalse); |
| 75 expect(BidiUtils.endsWithLtr(' \u05e0\u05e1a\u05e2 <', true), isFalse); | 75 expect(endsWithLtr(' \u05e0\u05e1a\u05e2 <', true), isFalse); |
| 76 expect(BidiUtils.endsWithLtr(' \u05e0\u05e1a\u05e2 <', false), isTrue); | 76 expect(endsWithLtr(' \u05e0\u05e1a\u05e2 <', false), isTrue); |
| 77 }); | 77 }); |
| 78 | 78 |
| 79 test('endsWithRtl', () { | 79 test('endsWithRtl', () { |
| 80 expect(BidiUtils.endsWithRtl('\u05e0'), isTrue); | 80 expect(endsWithRtl('\u05e0'), isTrue); |
| 81 expect(BidiUtils.endsWithRtl('\u05e0\u05e1\u05e2'), isTrue); | 81 expect(endsWithRtl('\u05e0\u05e1\u05e2'), isTrue); |
| 82 expect(BidiUtils.endsWithRtl('\u05e0 (!)'), isTrue); | 82 expect(endsWithRtl('\u05e0 (!)'), isTrue); |
| 83 expect(BidiUtils.endsWithRtl('\u05e0.1'), isTrue); | 83 expect(endsWithRtl('\u05e0.1'), isTrue); |
| 84 expect(BidiUtils.endsWithRtl('http://www.google.com/\u05e0 '), isTrue); | 84 expect(endsWithRtl('http://www.google.com/\u05e0 '), isTrue); |
| 85 expect(BidiUtils.endsWithRtl('a\u05e0'), isTrue); | 85 expect(endsWithRtl('a\u05e0'), isTrue); |
| 86 expect(BidiUtils.endsWithRtl(' a abc\u05e0def\u05e3. 1'), isTrue); | 86 expect(endsWithRtl(' a abc\u05e0def\u05e3. 1'), isTrue); |
| 87 expect(BidiUtils.endsWithRtl(''), isFalse); | 87 expect(endsWithRtl(''), isFalse); |
| 88 expect(BidiUtils.endsWithRtl(' '), isFalse); | 88 expect(endsWithRtl(' '), isFalse); |
| 89 expect(BidiUtils.endsWithRtl('1'), isFalse); | 89 expect(endsWithRtl('1'), isFalse); |
| 90 expect(BidiUtils.endsWithRtl('a'), isFalse); | 90 expect(endsWithRtl('a'), isFalse); |
| 91 expect(BidiUtils.endsWithRtl('a 1(!)'), isFalse); | 91 expect(endsWithRtl('a 1(!)'), isFalse); |
| 92 expect(BidiUtils.endsWithRtl('\u05e0a'), isFalse); | 92 expect(endsWithRtl('\u05e0a'), isFalse); |
| 93 expect(BidiUtils.endsWithRtl('\u05e0 \u05e0\u05e1ab\u05e2 a (!)'), isFalse); | 93 expect(endsWithRtl('\u05e0 \u05e0\u05e1ab\u05e2 a (!)'), isFalse); |
| 94 expect(BidiUtils.endsWithRtl(' \u05e0\u05e1a\u05e2 <', true), isTrue); | 94 expect(endsWithRtl(' \u05e0\u05e1a\u05e2 <', true), isTrue); |
| 95 expect(BidiUtils.endsWithRtl(' \u05e0\u05e1a\u05e2 <', false), isFalse); | 95 expect(endsWithRtl(' \u05e0\u05e1a\u05e2 <', false), isFalse); |
| 96 }); | 96 }); |
| 97 | 97 |
| 98 test('guardBracketInHtml', () { | 98 test('guardBracketInHtml', () { |
| 99 var strWithRtl = "asc \u05d0 (\u05d0\u05d0\u05d0)"; | 99 var strWithRtl = "asc \u05d0 (\u05d0\u05d0\u05d0)"; |
| 100 expect(BidiUtils.guardBracketInHtml(strWithRtl), | 100 expect(guardBracketInHtml(strWithRtl), |
| 101 equals("asc \u05d0 <span dir=rtl>(\u05d0\u05d0\u05d0)</span>")); | 101 equals("asc \u05d0 <span dir=rtl>(\u05d0\u05d0\u05d0)</span>")); |
| 102 expect(BidiUtils.guardBracketInHtml(strWithRtl, true), | 102 expect(guardBracketInHtml(strWithRtl, true), |
| 103 equals("asc \u05d0 <span dir=rtl>(\u05d0\u05d0\u05d0)</span>")); | 103 equals("asc \u05d0 <span dir=rtl>(\u05d0\u05d0\u05d0)</span>")); |
| 104 expect(BidiUtils.guardBracketInHtml(strWithRtl, false), | 104 expect(guardBracketInHtml(strWithRtl, false), |
| 105 equals("asc \u05d0 <span dir=ltr>(\u05d0\u05d0\u05d0)</span>")); | 105 equals("asc \u05d0 <span dir=ltr>(\u05d0\u05d0\u05d0)</span>")); |
| 106 | 106 |
| 107 var strWithRtl2 = "\u05d0 a (asc:))"; | 107 var strWithRtl2 = "\u05d0 a (asc:))"; |
| 108 expect(BidiUtils.guardBracketInHtml(strWithRtl2), | 108 expect(guardBracketInHtml(strWithRtl2), |
| 109 equals("\u05d0 a <span dir=rtl>(asc:))</span>")); | 109 equals("\u05d0 a <span dir=rtl>(asc:))</span>")); |
| 110 expect(BidiUtils.guardBracketInHtml(strWithRtl2, true), | 110 expect(guardBracketInHtml(strWithRtl2, true), |
| 111 equals("\u05d0 a <span dir=rtl>(asc:))</span>")); | 111 equals("\u05d0 a <span dir=rtl>(asc:))</span>")); |
| 112 expect(BidiUtils.guardBracketInHtml(strWithRtl2, false), | 112 expect(guardBracketInHtml(strWithRtl2, false), |
| 113 equals("\u05d0 a <span dir=ltr>(asc:))</span>")); | 113 equals("\u05d0 a <span dir=ltr>(asc:))</span>")); |
| 114 | 114 |
| 115 var strWithoutRtl = "a (asc) {{123}}"; | 115 var strWithoutRtl = "a (asc) {{123}}"; |
| 116 expect(BidiUtils.guardBracketInHtml(strWithoutRtl), | 116 expect(guardBracketInHtml(strWithoutRtl), |
| 117 equals("a <span dir=ltr>(asc)</span> <span dir=ltr>{{123}}</span>")); | 117 equals("a <span dir=ltr>(asc)</span> <span dir=ltr>{{123}}</span>")); |
| 118 expect(BidiUtils.guardBracketInHtml(strWithoutRtl, true), | 118 expect(guardBracketInHtml(strWithoutRtl, true), |
| 119 equals("a <span dir=rtl>(asc)</span> <span dir=rtl>{{123}}</span>")); | 119 equals("a <span dir=rtl>(asc)</span> <span dir=rtl>{{123}}</span>")); |
| 120 expect(BidiUtils.guardBracketInHtml(strWithoutRtl, false), | 120 expect(guardBracketInHtml(strWithoutRtl, false), |
| 121 equals("a <span dir=ltr>(asc)</span> <span dir=ltr>{{123}}</span>")); | 121 equals("a <span dir=ltr>(asc)</span> <span dir=ltr>{{123}}</span>")); |
| 122 | 122 |
| 123 }); | 123 }); |
| 124 | 124 |
| 125 test('guardBracketInText', () { | 125 test('guardBracketInText', () { |
| 126 var strWithRtl = "asc \u05d0 (\u05d0\u05d0\u05d0)"; | 126 var strWithRtl = "asc \u05d0 (\u05d0\u05d0\u05d0)"; |
| 127 expect(BidiUtils.guardBracketInText(strWithRtl), | 127 expect(guardBracketInText(strWithRtl), |
| 128 equals("asc \u05d0 \u200f(\u05d0\u05d0\u05d0)\u200f")); | 128 equals("asc \u05d0 \u200f(\u05d0\u05d0\u05d0)\u200f")); |
| 129 expect(BidiUtils.guardBracketInText(strWithRtl, true), | 129 expect(guardBracketInText(strWithRtl, true), |
| 130 equals("asc \u05d0 \u200f(\u05d0\u05d0\u05d0)\u200f")); | 130 equals("asc \u05d0 \u200f(\u05d0\u05d0\u05d0)\u200f")); |
| 131 expect(BidiUtils.guardBracketInText(strWithRtl, false), | 131 expect(guardBracketInText(strWithRtl, false), |
| 132 equals("asc \u05d0 \u200e(\u05d0\u05d0\u05d0)\u200e")); | 132 equals("asc \u05d0 \u200e(\u05d0\u05d0\u05d0)\u200e")); |
| 133 | 133 |
| 134 var strWithRtl2 = "\u05d0 a (asc:))"; | 134 var strWithRtl2 = "\u05d0 a (asc:))"; |
| 135 expect(BidiUtils.guardBracketInText(strWithRtl2), | 135 expect(guardBracketInText(strWithRtl2), |
| 136 equals("\u05d0 a \u200f(asc:))\u200f")); | 136 equals("\u05d0 a \u200f(asc:))\u200f")); |
| 137 expect(BidiUtils.guardBracketInText(strWithRtl2, true), | 137 expect(guardBracketInText(strWithRtl2, true), |
| 138 equals("\u05d0 a \u200f(asc:))\u200f")); | 138 equals("\u05d0 a \u200f(asc:))\u200f")); |
| 139 expect(BidiUtils.guardBracketInText(strWithRtl2, false), | 139 expect(guardBracketInText(strWithRtl2, false), |
| 140 equals("\u05d0 a \u200e(asc:))\u200e")); | 140 equals("\u05d0 a \u200e(asc:))\u200e")); |
| 141 | 141 |
| 142 var strWithoutRtl = "a (asc) {{123}}"; | 142 var strWithoutRtl = "a (asc) {{123}}"; |
| 143 expect(BidiUtils.guardBracketInText(strWithoutRtl), | 143 expect(guardBracketInText(strWithoutRtl), |
| 144 equals("a \u200e(asc)\u200e \u200e{{123}}\u200e")); | 144 equals("a \u200e(asc)\u200e \u200e{{123}}\u200e")); |
| 145 expect(BidiUtils.guardBracketInText(strWithoutRtl, true), | 145 expect(guardBracketInText(strWithoutRtl, true), |
| 146 equals("a \u200f(asc)\u200f \u200f{{123}}\u200f")); | 146 equals("a \u200f(asc)\u200f \u200f{{123}}\u200f")); |
| 147 expect(BidiUtils.guardBracketInText(strWithoutRtl, false), | 147 expect(guardBracketInText(strWithoutRtl, false), |
| 148 equals("a \u200e(asc)\u200e \u200e{{123}}\u200e")); | 148 equals("a \u200e(asc)\u200e \u200e{{123}}\u200e")); |
| 149 | 149 |
| 150 }); | 150 }); |
| 151 | 151 |
| 152 test('enforceRtlInHtml', () { | 152 test('enforceRtlInHtml', () { |
| 153 var str = '<div> first <br> second </div>'; | 153 var str = '<div> first <br> second </div>'; |
| 154 expect(BidiUtils.enforceRtlInHtml(str), | 154 expect(enforceRtlInHtml(str), |
| 155 equals('<div dir=rtl> first <br> second </div>')); | 155 equals('<div dir=rtl> first <br> second </div>')); |
| 156 str = 'first second'; | 156 str = 'first second'; |
| 157 expect(BidiUtils.enforceRtlInHtml(str), | 157 expect(enforceRtlInHtml(str), |
| 158 equals('\n<span dir=rtl>first second</span>')); | 158 equals('\n<span dir=rtl>first second</span>')); |
| 159 }); | 159 }); |
| 160 | 160 |
| 161 test('enforceRtlInText', () { | 161 test('enforceRtlInText', () { |
| 162 var str = 'first second'; | 162 var str = 'first second'; |
| 163 expect(BidiUtils.enforceRtlInText(str), equals('${RLE}first second$PDF')); | 163 expect(enforceRtlInText(str), equals('${RLE}first second$PDF')); |
| 164 }); | 164 }); |
| 165 | 165 |
| 166 test('enforceLtrInHtml', () { | 166 test('enforceLtrInHtml', () { |
| 167 var str = '<div> first <br> second </div>'; | 167 var str = '<div> first <br> second </div>'; |
| 168 expect(BidiUtils.enforceLtrInHtml(str), | 168 expect(enforceLtrInHtml(str), |
| 169 equals('<div dir=ltr> first <br> second </div>')); | 169 equals('<div dir=ltr> first <br> second </div>')); |
| 170 str = 'first second'; | 170 str = 'first second'; |
| 171 expect(BidiUtils.enforceLtrInHtml(str), | 171 expect(enforceLtrInHtml(str), |
| 172 equals('\n<span dir=ltr>first second</span>')); | 172 equals('\n<span dir=ltr>first second</span>')); |
| 173 }); | 173 }); |
| 174 | 174 |
| 175 test('enforceLtrInText', () { | 175 test('enforceLtrInText', () { |
| 176 var str = 'first second'; | 176 var str = 'first second'; |
| 177 expect(BidiUtils.enforceLtrInText(str), equals('${LRE}first second$PDF')); | 177 expect(enforceLtrInText(str), equals('${LRE}first second$PDF')); |
| 178 }); | 178 }); |
| 179 | 179 |
| 180 test('normalizeHebrewQuote', () { | 180 test('normalizeHebrewQuote', () { |
| 181 expect(BidiUtils.normalizeHebrewQuote('\u05d0"'), equals('\u05d0\u05f4')); | 181 expect(normalizeHebrewQuote('\u05d0"'), equals('\u05d0\u05f4')); |
| 182 expect(BidiUtils.normalizeHebrewQuote('\u05d0\''), equals('\u05d0\u05f3')); | 182 expect(normalizeHebrewQuote('\u05d0\''), equals('\u05d0\u05f3')); |
| 183 expect(BidiUtils.normalizeHebrewQuote('\u05d0"\u05d0\''), | 183 expect(normalizeHebrewQuote('\u05d0"\u05d0\''), |
| 184 equals('\u05d0\u05f4\u05d0\u05f3')); | 184 equals('\u05d0\u05f4\u05d0\u05f3')); |
| 185 }); | 185 }); |
| 186 | 186 |
| 187 test('estimateDirection', () { | 187 test('estimateDirectionOfText', () { |
| 188 expect(BidiUtils.estimateDirection('', false).value, | 188 expect(estimateDirectionOfText('', false).value, |
| 189 equals(TextDirection.UNKNOWN.value)); | 189 equals(TextDirection.UNKNOWN.value)); |
| 190 expect(BidiUtils.estimateDirection(' ', false).value, | 190 expect(estimateDirectionOfText(' ', false).value, |
| 191 equals(TextDirection.UNKNOWN.value)); | 191 equals(TextDirection.UNKNOWN.value)); |
| 192 expect(BidiUtils.estimateDirection('! (...)', false).value, | 192 expect(estimateDirectionOfText('! (...)', false).value, |
| 193 equals(TextDirection.UNKNOWN.value)); | 193 equals(TextDirection.UNKNOWN.value)); |
| 194 expect(BidiUtils.estimateDirection('All-Ascii content', false).value, | 194 expect(estimateDirectionOfText('All-Ascii content', false).value, |
| 195 equals(TextDirection.LTR.value)); | 195 equals(TextDirection.LTR.value)); |
| 196 expect(BidiUtils.estimateDirection('-17.0%', false).value, | 196 expect(estimateDirectionOfText('-17.0%', false).value, |
| 197 equals(TextDirection.LTR.value)); | 197 equals(TextDirection.LTR.value)); |
| 198 expect(BidiUtils.estimateDirection('http://foo/bar/', false).value, | 198 expect(estimateDirectionOfText('http://foo/bar/', false).value, |
| 199 equals(TextDirection.LTR.value)); | 199 equals(TextDirection.LTR.value)); |
| 200 expect(BidiUtils.estimateDirection( | 200 expect(estimateDirectionOfText( |
| 201 'http://foo/bar/?s=\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0' | 201 'http://foo/bar/?s=\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0' |
| 202 '\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0' | 202 '\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0' |
| 203 '\u05d0\u05d0\u05d0\u05d0\u05d0').value, | 203 '\u05d0\u05d0\u05d0\u05d0\u05d0').value, |
| 204 equals(TextDirection.LTR.value)); | 204 equals(TextDirection.LTR.value)); |
| 205 expect(BidiUtils.estimateDirection('\u05d0', false).value, | 205 expect(estimateDirectionOfText('\u05d0', false).value, |
| 206 equals(TextDirection.RTL.value)); | 206 equals(TextDirection.RTL.value)); |
| 207 expect(BidiUtils.estimateDirection( | 207 expect(estimateDirectionOfText( |
| 208 '9 \u05d0 -> 17.5, 23, 45, 19', false).value, | 208 '9 \u05d0 -> 17.5, 23, 45, 19', false).value, |
| 209 equals(TextDirection.RTL.value)); | 209 equals(TextDirection.RTL.value)); |
| 210 expect(BidiUtils.estimateDirection( | 210 expect(estimateDirectionOfText( |
| 211 'http://foo/bar/ \u05d0 http://foo2/bar2/ http://foo3/bar3/').value, | 211 'http://foo/bar/ \u05d0 http://foo2/bar2/ http://foo3/bar3/').value, |
| 212 equals(TextDirection.RTL.value)); | 212 equals(TextDirection.RTL.value)); |
| 213 expect(BidiUtils.estimateDirection( | 213 expect(estimateDirectionOfText( |
| 214 '\u05d0\u05d9\u05df \u05de\u05de\u05e9 \u05de\u05d4 \u05dc\u05e8\u05d0' | 214 '\u05d0\u05d9\u05df \u05de\u05de\u05e9 \u05de\u05d4 \u05dc\u05e8\u05d0' |
| 215 '\u05d5\u05ea: \u05dc\u05d0 \u05e6\u05d9\u05dc\u05de\u05ea\u05d9 \u05d4' | 215 '\u05d5\u05ea: \u05dc\u05d0 \u05e6\u05d9\u05dc\u05de\u05ea\u05d9 \u05d4' |
| 216 '\u05e8\u05d1\u05d4 \u05d5\u05d2\u05dd \u05d0\u05dd \u05d4\u05d9\u05d9' | 216 '\u05e8\u05d1\u05d4 \u05d5\u05d2\u05dd \u05d0\u05dd \u05d4\u05d9\u05d9' |
| 217 '\u05ea\u05d9 \u05de\u05e6\u05dc\u05dd, \u05d4\u05d9\u05d4 \u05e9' | 217 '\u05ea\u05d9 \u05de\u05e6\u05dc\u05dd, \u05d4\u05d9\u05d4 \u05e9' |
| 218 '\u05dd').value, | 218 '\u05dd').value, |
| 219 equals(TextDirection.RTL.value)); | 219 equals(TextDirection.RTL.value)); |
| 220 expect(BidiUtils.estimateDirection( | 220 expect(estimateDirectionOfText( |
| 221 '\u05db\u05d0 - http://geek.co.il/gallery/v/2007-06 - \u05d0\u05d9' | 221 '\u05db\u05d0 - http://geek.co.il/gallery/v/2007-06 - \u05d0\u05d9' |
| 222 '\u05df \u05de\u05de\u05e9 \u05de\u05d4 \u05dc\u05e8\u05d0\u05d5\u05ea:' | 222 '\u05df \u05de\u05de\u05e9 \u05de\u05d4 \u05dc\u05e8\u05d0\u05d5\u05ea:' |
| 223 ' \u05dc\u05d0 \u05e6\u05d9\u05dc\u05de\u05ea\u05d9 \u05d4\u05e8\u05d1 ' | 223 ' \u05dc\u05d0 \u05e6\u05d9\u05dc\u05de\u05ea\u05d9 \u05d4\u05e8\u05d1 ' |
| 224 '\u05d5\u05d2\u05dd \u05d0\u05dd \u05d4\u05d9\u05d9\u05d9 \u05de\u05e6' | 224 '\u05d5\u05d2\u05dd \u05d0\u05dd \u05d4\u05d9\u05d9\u05d9 \u05de\u05e6' |
| 225 '\u05dc\u05dd, \u05d4\u05d9\u05d4 \u05e9\u05dd \u05d1\u05e2\u05d9\u05e7' | 225 '\u05dc\u05dd, \u05d4\u05d9\u05d4 \u05e9\u05dd \u05d1\u05e2\u05d9\u05e7' |
| 226 ' \u05d4\u05e8\u05d1\u05d4 \u05d0\u05e0\u05e9\u05d9\u05dd. \u05de\u05d4' | 226 ' \u05d4\u05e8\u05d1\u05d4 \u05d0\u05e0\u05e9\u05d9\u05dd. \u05de\u05d4' |
| 227 ' \u05e9\u05db\u05df - \u05d0\u05e4\u05e9\u05e8 \u05dc\u05e0\u05e6' | 227 ' \u05e9\u05db\u05df - \u05d0\u05e4\u05e9\u05e8 \u05dc\u05e0\u05e6' |
| 228 '\u05dc \u05d0\u05ea \u05d4\u05d4 \u05d3\u05d6\u05de\u05e0\u05d5 ' | 228 '\u05dc \u05d0\u05ea \u05d4\u05d4 \u05d3\u05d6\u05de\u05e0\u05d5 ' |
| 229 '\u05dc\u05d4\u05e1\u05ea\u05db\u05dc \u05e2\u05dc \u05db\u05de\u05d4 ' | 229 '\u05dc\u05d4\u05e1\u05ea\u05db\u05dc \u05e2\u05dc \u05db\u05de\u05d4 ' |
| 230 '\u05ea\u05de\u05d5\u05e0\u05d5\u05ea \u05de\u05e9\u05e9\u05e2\u05d5' | 230 '\u05ea\u05de\u05d5\u05e0\u05d5\u05ea \u05de\u05e9\u05e9\u05e2\u05d5' |
| 231 '\u05ea \u05d9\u05e9\u05e0\u05d5 \u05d9\u05d5\u05ea\u05e8 \u05e9\u05d9' | 231 '\u05ea \u05d9\u05e9\u05e0\u05d5 \u05d9\u05d5\u05ea\u05e8 \u05e9\u05d9' |
| 232 '\u05e9 \u05dc\u05d9 \u05d1\u05d0\u05ea\u05e8', false).value, | 232 '\u05e9 \u05dc\u05d9 \u05d1\u05d0\u05ea\u05e8', false).value, |
| 233 equals(TextDirection.RTL.value)); | 233 equals(TextDirection.RTL.value)); |
| 234 expect(BidiUtils.estimateDirection( | 234 expect(estimateDirectionOfText( |
| 235 'CAPTCHA \u05de\u05e9\u05d5\u05db\u05dc\u05dc ' | 235 'CAPTCHA \u05de\u05e9\u05d5\u05db\u05dc\u05dc ' |
| 236 '\u05de\u05d3\u05d9?').value, | 236 '\u05de\u05d3\u05d9?').value, |
| 237 equals(TextDirection.RTL.value)); | 237 equals(TextDirection.RTL.value)); |
| 238 expect(BidiUtils.estimateDirection( | 238 expect(estimateDirectionOfText( |
| 239 'Yes Prime Minister \u05e2\u05d3\u05db\u05d5\u05df. \u05e9\u05d0\u05dc' | 239 'Yes Prime Minister \u05e2\u05d3\u05db\u05d5\u05df. \u05e9\u05d0\u05dc' |
| 240 '\u05d5 \u05d0\u05d5\u05ea\u05d9 \u05de\u05d4 \u05d0\u05e0\u05d9 ' | 240 '\u05d5 \u05d0\u05d5\u05ea\u05d9 \u05de\u05d4 \u05d0\u05e0\u05d9 ' |
| 241 '\u05e8\u05d5\u05e6\u05d4 \u05de\u05ea\u05e0\u05d4 \u05dc\u05d7' | 241 '\u05e8\u05d5\u05e6\u05d4 \u05de\u05ea\u05e0\u05d4 \u05dc\u05d7' |
| 242 '\u05d2').value, | 242 '\u05d2').value, |
| 243 equals(TextDirection.RTL.value)); | 243 equals(TextDirection.RTL.value)); |
| 244 expect(BidiUtils.estimateDirection( | 244 expect(estimateDirectionOfText( |
| 245 '17.4.02 \u05e9\u05e2\u05d4:13-20 .15-00 .\u05dc\u05d0 \u05d4\u05d9' | 245 '17.4.02 \u05e9\u05e2\u05d4:13-20 .15-00 .\u05dc\u05d0 \u05d4\u05d9' |
| 246 '\u05d9\u05ea\u05d9 \u05db\u05d0\u05df.').value, | 246 '\u05d9\u05ea\u05d9 \u05db\u05d0\u05df.').value, |
| 247 equals(TextDirection.RTL.value)); | 247 equals(TextDirection.RTL.value)); |
| 248 expect(BidiUtils.estimateDirection( | 248 expect(estimateDirectionOfText( |
| 249 '5710 5720 5730. \u05d4\u05d3\u05dc\u05ea. \u05d4\u05e0\u05e9\u05d9' | 249 '5710 5720 5730. \u05d4\u05d3\u05dc\u05ea. \u05d4\u05e0\u05e9\u05d9' |
| 250 '\u05e7\u05d4', false).value, | 250 '\u05e7\u05d4', false).value, |
| 251 equals(TextDirection.RTL.value)); | 251 equals(TextDirection.RTL.value)); |
| 252 expect(BidiUtils.estimateDirection( | 252 expect(estimateDirectionOfText( |
| 253 '\u05d4\u05d3\u05dc\u05ea http://www.google.com ' | 253 '\u05d4\u05d3\u05dc\u05ea http://www.google.com ' |
| 254 'http://www.gmail.com').value, | 254 'http://www.gmail.com').value, |
| 255 equals(TextDirection.RTL.value)); | 255 equals(TextDirection.RTL.value)); |
| 256 expect(BidiUtils.estimateDirection( | 256 expect(estimateDirectionOfText( |
| 257 '\u05d4\u05d3\u05dc <some quite nasty html mark up>').value, | 257 '\u05d4\u05d3\u05dc <some quite nasty html mark up>').value, |
| 258 equals(TextDirection.LTR.value)); | 258 equals(TextDirection.LTR.value)); |
| 259 expect(BidiUtils.estimateDirection( | 259 expect(estimateDirectionOfText( |
| 260 '\u05d4\u05d3\u05dc <some quite nasty html mark up>').value, | 260 '\u05d4\u05d3\u05dc <some quite nasty html mark up>').value, |
| 261 equals(TextDirection.LTR.value)); | 261 equals(TextDirection.LTR.value)); |
| 262 expect(BidiUtils.estimateDirection( | 262 expect(estimateDirectionOfText( |
| 263 '\u05d4\u05d3\u05dc\u05ea & < >').value, | 263 '\u05d4\u05d3\u05dc\u05ea & < >').value, |
| 264 equals(TextDirection.LTR.value)); | 264 equals(TextDirection.LTR.value)); |
| 265 expect(BidiUtils.estimateDirection( | 265 expect(estimateDirectionOfText( |
| 266 '\u05d4\u05d3\u05dc\u05ea & < >', true).value, | 266 '\u05d4\u05d3\u05dc\u05ea & < >', true).value, |
| 267 equals(TextDirection.RTL.value)); | 267 equals(TextDirection.RTL.value)); |
| 268 }); | 268 }); |
| 269 | 269 |
| 270 test('detectRtlDirectionality', () { | 270 test('detectRtlDirectionality', () { |
| 271 var bidiText = []; | 271 var bidiText = []; |
| 272 var item = new SampleItem('Pure Ascii content'); | 272 var item = new SampleItem('Pure Ascii content'); |
| 273 bidiText.add(item); | 273 bidiText.add(item); |
| 274 | 274 |
| 275 item = new SampleItem('\u05d0\u05d9\u05df \u05de\u05de\u05e9 \u05de\u05d4' | 275 item = new SampleItem('\u05d0\u05d9\u05df \u05de\u05de\u05e9 \u05de\u05d4' |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 'http://www.gmail.com', true); | 317 'http://www.gmail.com', true); |
| 318 bidiText.add(item); | 318 bidiText.add(item); |
| 319 | 319 |
| 320 item = new SampleItem('>\u05d4<', true, true); | 320 item = new SampleItem('>\u05d4<', true, true); |
| 321 bidiText.add(item); | 321 bidiText.add(item); |
| 322 | 322 |
| 323 item = new SampleItem('>\u05d4<', false); | 323 item = new SampleItem('>\u05d4<', false); |
| 324 bidiText.add(item); | 324 bidiText.add(item); |
| 325 | 325 |
| 326 for (var i = 0; i < bidiText.length; i++) { | 326 for (var i = 0; i < bidiText.length; i++) { |
| 327 var isRtlDir = BidiUtils.detectRtlDirectionality(bidiText[i].text, | 327 var isRtlDir = detectRtlDirectionality(bidiText[i].text, |
| 328 bidiText[i].isHtml); | 328 bidiText[i].isHtml); |
| 329 if (isRtlDir != bidiText[i].isRtl) { | 329 if (isRtlDir != bidiText[i].isRtl) { |
| 330 var str = '"${bidiText[i].text} " should be ' | 330 var str = '"${bidiText[i].text} " should be ' |
| 331 '${bidiText[i].isRtl ? "rtl" : "ltr"} but detected as ' | 331 '${bidiText[i].isRtl ? "rtl" : "ltr"} but detected as ' |
| 332 '${isRtlDir ? "rtl" : "ltr"}'; | 332 '${isRtlDir ? "rtl" : "ltr"}'; |
| 333 //alert(str); | 333 //alert(str); |
| 334 } | 334 } |
| 335 expect(bidiText[i].isRtl, isRtlDir); | 335 expect(bidiText[i].isRtl, isRtlDir); |
| 336 } | 336 } |
| 337 }); | 337 }); |
| 338 } | 338 } |
| 339 | 339 |
| 340 class SampleItem { | 340 class SampleItem { |
| 341 String text; | 341 String text; |
| 342 bool isRtl; | 342 bool isRtl; |
| 343 bool isHtml; | 343 bool isHtml; |
| 344 SampleItem([someText='', someIsRtl=false, isHtml=false]) : | 344 SampleItem([someText='', someIsRtl=false, isHtml=false]) : |
| 345 this.text=someText, this.isRtl=someIsRtl, this.isHtml=isHtml; | 345 this.text=someText, this.isRtl=someIsRtl, this.isHtml=isHtml; |
| 346 } | 346 } |
| OLD | NEW |