| 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_format_test'); | 6 #library('bidi_format_test'); |
| 7 | 7 |
| 8 #import('../lib/intl.dart'); | 8 #import('../lib/intl.dart'); |
| 9 #import('../../../pkg/unittest/unittest.dart'); | 9 #import('../../../pkg/unittest/unittest.dart'); |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 expect(unkFmt.estimateDirection(''), equals(UNKNOWN)); | 35 expect(unkFmt.estimateDirection(''), equals(UNKNOWN)); |
| 36 expect(ltrFmt.estimateDirection(en), equals(LTR)); | 36 expect(ltrFmt.estimateDirection(en), equals(LTR)); |
| 37 expect(rtlFmt.estimateDirection(en), equals(LTR)); | 37 expect(rtlFmt.estimateDirection(en), equals(LTR)); |
| 38 expect(unkFmt.estimateDirection(en), equals(LTR)); | 38 expect(unkFmt.estimateDirection(en), equals(LTR)); |
| 39 expect(ltrFmt.estimateDirection(he), equals(RTL)); | 39 expect(ltrFmt.estimateDirection(he), equals(RTL)); |
| 40 expect(rtlFmt.estimateDirection(he), equals(RTL)); | 40 expect(rtlFmt.estimateDirection(he), equals(RTL)); |
| 41 expect(unkFmt.estimateDirection(he), equals(RTL)); | 41 expect(unkFmt.estimateDirection(he), equals(RTL)); |
| 42 | 42 |
| 43 // Text contains HTML or HTML-escaping. | 43 // Text contains HTML or HTML-escaping. |
| 44 expect(ltrFmt.estimateDirection( | 44 expect(ltrFmt.estimateDirection( |
| 45 '<some sort of tag/>$he &', false), equals(LTR)); | 45 '<some sort of tag/>$he &', isHtml: false), equals(LTR)); |
| 46 expect(ltrFmt.estimateDirection( | 46 expect(ltrFmt.estimateDirection( |
| 47 '<some sort of tag/>$he &', true), equals(RTL)); | 47 '<some sort of tag/>$he &', isHtml: true), equals(RTL)); |
| 48 }); | 48 }); |
| 49 | 49 |
| 50 test('wrapWithSpan', () { | 50 test('wrapWithSpan', () { |
| 51 // Test overall dir matches context dir (LTR), no dirReset. | 51 // Test overall dir matches context dir (LTR), no dirReset. |
| 52 expect(ltrFmt.wrapWithSpan(en, true, false), equals(en)); | 52 expect(ltrFmt.wrapWithSpan(en, isHtml: true, resetDir: false), equals(en)); |
| 53 // Test overall dir matches context dir (LTR), dirReset. | 53 // Test overall dir matches context dir (LTR), dirReset. |
| 54 expect(ltrFmt.wrapWithSpan(en, true, true), equals(en)); | 54 expect(ltrFmt.wrapWithSpan(en, isHtml: true, resetDir: true), equals(en)); |
| 55 // Test overall dir matches context dir (RTL), no dirReset'. | 55 // Test overall dir matches context dir (RTL), no dirReset'. |
| 56 expect(rtlFmt.wrapWithSpan(he, true, false), equals(he)); | 56 expect(rtlFmt.wrapWithSpan(he, isHtml: true, resetDir: false), equals(he)); |
| 57 // Test overall dir matches context dir (RTL), dirReset. | 57 // Test overall dir matches context dir (RTL), dirReset. |
| 58 expect(rtlFmt.wrapWithSpan(he, true, true), equals(he)); | 58 expect(rtlFmt.wrapWithSpan(he, isHtml: true, resetDir: true), equals(he)); |
| 59 // Test overall dir (RTL) doesn't match context dir (LTR), no dirReset. | 59 // Test overall dir (RTL) doesn't match context dir (LTR), no dirReset. |
| 60 expect(ltrFmt.wrapWithSpan(he, true, false), | 60 expect(ltrFmt.wrapWithSpan(he, isHtml: true, resetDir: false), |
| 61 equals('<span dir=rtl>$he</span>')); | 61 equals('<span dir=rtl>$he</span>')); |
| 62 // Test overall dir (RTL) doesn't match context dir (LTR), dirReset. | 62 // Test overall dir (RTL) doesn't match context dir (LTR), dirReset. |
| 63 expect(ltrFmt.wrapWithSpan(he, true, true), | 63 expect(ltrFmt.wrapWithSpan(he, isHtml: true, resetDir: true), |
| 64 equals('<span dir=rtl>$he</span>$LRM')); | 64 equals('<span dir=rtl>$he</span>$LRM')); |
| 65 // Test overall dir (LTR) doesn't match context dir (RTL), no dirReset. | 65 // Test overall dir (LTR) doesn't match context dir (RTL), no dirReset. |
| 66 expect(rtlFmt.wrapWithSpan(en, true, false), | 66 expect(rtlFmt.wrapWithSpan(en, isHtml: true, resetDir: false), |
| 67 equals('<span dir=ltr>$en</span>')); | 67 equals('<span dir=ltr>$en</span>')); |
| 68 // Test overall dir (LTR) doesn't match context dir (RTL), dirReset. | 68 // Test overall dir (LTR) doesn't match context dir (RTL), dirReset. |
| 69 expect(rtlFmt.wrapWithSpan(en, true, true), | 69 expect(rtlFmt.wrapWithSpan(en, isHtml: true, resetDir: true), |
| 70 equals('<span dir=ltr>$en</span>$RLM')); | 70 equals('<span dir=ltr>$en</span>$RLM')); |
| 71 // Test overall dir (LTR) doesn't match context dir (unknown), no dirReset. | 71 // Test overall dir (LTR) doesn't match context dir (unknown), no dirReset. |
| 72 expect(unkFmt.wrapWithSpan(en, true, false), | 72 expect(unkFmt.wrapWithSpan(en, isHtml: true, resetDir: false), |
| 73 equals('<span dir=ltr>$en</span>')); | 73 equals('<span dir=ltr>$en</span>')); |
| 74 // Test overall dir (RTL) doesn't match context dir (unknown), dirReset. | 74 // Test overall dir (RTL) doesn't match context dir (unknown), dirReset. |
| 75 expect(unkFmt.wrapWithSpan(he, true, true), | 75 expect(unkFmt.wrapWithSpan(he, isHtml: true, resetDir: true), |
| 76 equals('<span dir=rtl>$he</span>')); | 76 equals('<span dir=rtl>$he</span>')); |
| 77 // Test overall dir (neutral) doesn't match context dir (LTR), dirReset. | 77 // Test overall dir (neutral) doesn't match context dir (LTR), dirReset. |
| 78 expect(ltrFmt.wrapWithSpan('', true, true), equals('')); | 78 expect(ltrFmt.wrapWithSpan('', isHtml: true, resetDir: true), equals('')); |
| 79 | 79 |
| 80 // Test exit dir (but not overall dir) is opposite to context dir, dirReset. | 80 // Test exit dir (but not overall dir) is opposite to context dir, dirReset. |
| 81 expect(ltrFmt.wrapWithSpan('$longEn$he$html', true, true), | 81 expect(ltrFmt.wrapWithSpan('$longEn$he$html', isHtml: true, resetDir: true), |
| 82 equals('$longEn$he$html$LRM')); | 82 equals('$longEn$he$html$LRM')); |
| 83 // Test overall dir (but not exit dir) is opposite to context dir, dirReset. | 83 // Test overall dir (but not exit dir) is opposite to context dir, dirReset. |
| 84 expect(rtlFmt.wrapWithSpan('$longEn$he', true, true), | 84 expect(rtlFmt.wrapWithSpan('$longEn$he', isHtml: true, resetDir: true), |
| 85 equals('<span dir=ltr>$longEn$he</span>$RLM')); | 85 equals('<span dir=ltr>$longEn$he</span>$RLM')); |
| 86 | 86 |
| 87 // Test input is plain text (not escaped). | 87 // Test input is plain text (not escaped). |
| 88 expect(ltrFmt.wrapWithSpan('<br>$en', false, false), | 88 expect(ltrFmt.wrapWithSpan('<br>$en', isHtml: false, resetDir: false), |
| 89 equals('<br>$en')); | 89 equals('<br>$en')); |
| 90 | 90 |
| 91 var ltrAlwaysSpanFmt = new BidiFormatter.LTR(true); | 91 var ltrAlwaysSpanFmt = new BidiFormatter.LTR(true); |
| 92 var rtlAlwaysSpanFmt = new BidiFormatter.RTL(true); | 92 var rtlAlwaysSpanFmt = new BidiFormatter.RTL(true); |
| 93 var unkAlwaysSpanFmt = new BidiFormatter.UNKNOWN(true); | 93 var unkAlwaysSpanFmt = new BidiFormatter.UNKNOWN(true); |
| 94 | 94 |
| 95 // Test alwaysSpan, overall dir matches context dir (LTR), no dirReset. | 95 // Test alwaysSpan, overall dir matches context dir (LTR), no dirReset. |
| 96 expect(ltrAlwaysSpanFmt.wrapWithSpan(en, true, false), | 96 expect(ltrAlwaysSpanFmt.wrapWithSpan(en, isHtml: true, resetDir: false), |
| 97 equals('<span>$en</span>')); | 97 equals('<span>$en</span>')); |
| 98 // Test alwaysSpan, overall dir matches context dir (LTR), dirReset. | 98 // Test alwaysSpan, overall dir matches context dir (LTR), dirReset. |
| 99 expect(ltrAlwaysSpanFmt.wrapWithSpan(en, true, true), | 99 expect(ltrAlwaysSpanFmt.wrapWithSpan(en, isHtml: true, resetDir: true), |
| 100 equals('<span>$en</span>')); | 100 equals('<span>$en</span>')); |
| 101 // Test alwaysSpan, overall dir matches context dir (RTL), no dirReset. | 101 // Test alwaysSpan, overall dir matches context dir (RTL), no dirReset. |
| 102 expect(rtlAlwaysSpanFmt.wrapWithSpan(he, true, false), | 102 expect(rtlAlwaysSpanFmt.wrapWithSpan(he, isHtml: true, resetDir: false), |
| 103 equals('<span>$he</span>')); | 103 equals('<span>$he</span>')); |
| 104 // Test alwaysSpan, overall dir matches context dir (RTL), dirReset. | 104 // Test alwaysSpan, overall dir matches context dir (RTL), dirReset. |
| 105 expect(rtlAlwaysSpanFmt.wrapWithSpan(he, true, true), | 105 expect(rtlAlwaysSpanFmt.wrapWithSpan(he, isHtml: true, resetDir: true), |
| 106 equals('<span>$he</span>')); | 106 equals('<span>$he</span>')); |
| 107 | 107 |
| 108 // Test alwaysSpan, overall dir (RTL) doesn't match context dir (LTR), | 108 // Test alwaysSpan, overall dir (RTL) doesn't match context dir (LTR), |
| 109 // no dirReset. | 109 // no dirReset. |
| 110 expect(ltrAlwaysSpanFmt.wrapWithSpan(he, true, false), | 110 expect(ltrAlwaysSpanFmt.wrapWithSpan(he, isHtml: true, resetDir: false), |
| 111 equals('<span dir=rtl>$he</span>')); | 111 equals('<span dir=rtl>$he</span>')); |
| 112 // Test alwaysSpan, overall dir (RTL) doesn't match context dir (LTR), | 112 // Test alwaysSpan, overall dir (RTL) doesn't match context dir (LTR), |
| 113 // dirReset. | 113 // dirReset. |
| 114 expect(ltrAlwaysSpanFmt.wrapWithSpan(he, true, true), | 114 expect(ltrAlwaysSpanFmt.wrapWithSpan(he, isHtml: true, resetDir: true), |
| 115 equals('<span dir=rtl>$he</span>$LRM')); | 115 equals('<span dir=rtl>$he</span>$LRM')); |
| 116 // Test alwaysSpan, overall dir (neutral) doesn't match context dir (LTR), | 116 // Test alwaysSpan, overall dir (neutral) doesn't match context dir (LTR), |
| 117 // dirReset | 117 // dirReset |
| 118 expect(ltrAlwaysSpanFmt.wrapWithSpan('', true, true), | 118 expect(ltrAlwaysSpanFmt.wrapWithSpan('', isHtml: true, resetDir: true), |
| 119 equals('<span></span>')); | 119 equals('<span></span>')); |
| 120 | 120 |
| 121 // Test overall dir matches context dir (LTR. | 121 // Test overall dir matches context dir (LTR. |
| 122 expect(ltrFmt.wrapWithSpan(en, direction : TextDirection.LTR), equals(en)); | 122 expect(ltrFmt.wrapWithSpan(en, direction : TextDirection.LTR), equals(en)); |
| 123 // Test overall dir (but not exit dir) supposedly matches context dir (LTR). | 123 // Test overall dir (but not exit dir) supposedly matches context dir (LTR). |
| 124 expect(ltrFmt.wrapWithSpan(he, direction : TextDirection.LTR), | 124 expect(ltrFmt.wrapWithSpan(he, direction : TextDirection.LTR), |
| 125 equals('$he$LRM')); | 125 equals('$he$LRM')); |
| 126 // Test overall dir matches context dir (RTL. | 126 // Test overall dir matches context dir (RTL. |
| 127 expect(rtlFmt.wrapWithSpan(he, direction : TextDirection.RTL), equals(he)); | 127 expect(rtlFmt.wrapWithSpan(he, direction : TextDirection.RTL), equals(he)); |
| 128 // Test overall dir (but not exit dir) supposedly matches context dir (RTL). | 128 // Test overall dir (but not exit dir) supposedly matches context dir (RTL). |
| (...skipping 15 matching lines...) Expand all Loading... |
| 144 // Test supposed overall dir (LTR) doesn't match context dir (unknown). | 144 // Test supposed overall dir (LTR) doesn't match context dir (unknown). |
| 145 expect(unkFmt.wrapWithSpan(he, direction : TextDirection.LTR), | 145 expect(unkFmt.wrapWithSpan(he, direction : TextDirection.LTR), |
| 146 equals('<span dir=ltr>$he</span>')); | 146 equals('<span dir=ltr>$he</span>')); |
| 147 // Test supposed overall dir (neutral) doesn't match context dir (LTR). | 147 // Test supposed overall dir (neutral) doesn't match context dir (LTR). |
| 148 expect(ltrFmt.wrapWithSpan(he, direction : TextDirection.UNKNOWN), | 148 expect(ltrFmt.wrapWithSpan(he, direction : TextDirection.UNKNOWN), |
| 149 equals('$he$LRM')); | 149 equals('$he$LRM')); |
| 150 }); | 150 }); |
| 151 | 151 |
| 152 test('wrapWithUnicode', () { | 152 test('wrapWithUnicode', () { |
| 153 // Test overall dir matches context dir (LTR), no dirReset. | 153 // Test overall dir matches context dir (LTR), no dirReset. |
| 154 expect(ltrFmt.wrapWithUnicode(en, true, false), equals(en)); | 154 expect(ltrFmt.wrapWithUnicode(en, isHtml: true, resetDir: false), |
| 155 equals(en)); |
| 155 // Test overall dir matches context dir (LTR), dirReset. | 156 // Test overall dir matches context dir (LTR), dirReset. |
| 156 expect(ltrFmt.wrapWithUnicode(en, true, true), equals(en)); | 157 expect(ltrFmt.wrapWithUnicode(en, isHtml: true, resetDir: true), |
| 158 equals(en)); |
| 157 // Test overall dir matches context dir (RTL), no dirReset. | 159 // Test overall dir matches context dir (RTL), no dirReset. |
| 158 expect(rtlFmt.wrapWithUnicode(he, true, false), equals(he)); | 160 expect(rtlFmt.wrapWithUnicode(he, isHtml: true, resetDir: false), |
| 161 equals(he)); |
| 159 // Test overall dir matches context dir (RTL), dirReset. | 162 // Test overall dir matches context dir (RTL), dirReset. |
| 160 expect(rtlFmt.wrapWithUnicode(he, true, true), equals(he)); | 163 expect(rtlFmt.wrapWithUnicode(he, isHtml: true, resetDir: true), |
| 164 equals(he)); |
| 161 | 165 |
| 162 // Test overall dir (RTL) doesn't match context dir (LTR), no dirReset. | 166 // Test overall dir (RTL) doesn't match context dir (LTR), no dirReset. |
| 163 expect(ltrFmt.wrapWithUnicode(he, true, false), equals('$RLE$he$PDF')); | 167 expect(ltrFmt.wrapWithUnicode(he, isHtml: true, resetDir: false), |
| 168 equals('$RLE$he$PDF')); |
| 164 // Test overall dir (RTL) doesn't match context dir (LTR), dirReset. | 169 // Test overall dir (RTL) doesn't match context dir (LTR), dirReset. |
| 165 expect(ltrFmt.wrapWithUnicode(he, true, true), equals('$RLE$he$PDF$LRM')); | 170 expect(ltrFmt.wrapWithUnicode(he, isHtml: true, resetDir: true), |
| 171 equals('$RLE$he$PDF$LRM')); |
| 166 // Test overall dir (LTR) doesn't match context dir (RTL), no dirReset. | 172 // Test overall dir (LTR) doesn't match context dir (RTL), no dirReset. |
| 167 expect(rtlFmt.wrapWithUnicode(en, true, false), equals('$LRE$en$PDF')); | 173 expect(rtlFmt.wrapWithUnicode(en, isHtml: true, resetDir: false), |
| 174 equals('$LRE$en$PDF')); |
| 168 // Test overall dir (LTR) doesn't match context dir (RTL), dirReset. | 175 // Test overall dir (LTR) doesn't match context dir (RTL), dirReset. |
| 169 expect(rtlFmt.wrapWithUnicode(en, true, true), equals('$LRE$en$PDF$RLM')); | 176 expect(rtlFmt.wrapWithUnicode(en, isHtml: true, resetDir: true), |
| 177 equals('$LRE$en$PDF$RLM')); |
| 170 // Test overall dir (LTR) doesn't match context dir (unknown), no dirReset. | 178 // Test overall dir (LTR) doesn't match context dir (unknown), no dirReset. |
| 171 expect(unkFmt.wrapWithUnicode(en, true, false), equals('$LRE$en$PDF')); | 179 expect(unkFmt.wrapWithUnicode(en, isHtml: true, resetDir: false), |
| 180 equals('$LRE$en$PDF')); |
| 172 // Test overall dir (RTL) doesn't match context dir (unknown), dirReset. | 181 // Test overall dir (RTL) doesn't match context dir (unknown), dirReset. |
| 173 expect(unkFmt.wrapWithUnicode(he, true, true), equals('$RLE$he$PDF')); | 182 expect(unkFmt.wrapWithUnicode(he, isHtml: true, resetDir: true), |
| 183 equals('$RLE$he$PDF')); |
| 174 // Test overall dir (neutral) doesn't match context dir (LTR), dirReset. | 184 // Test overall dir (neutral) doesn't match context dir (LTR), dirReset. |
| 175 expect(ltrFmt.wrapWithUnicode('', true, true), equals('')); | 185 expect(ltrFmt.wrapWithUnicode('', isHtml: true, resetDir: true), |
| 186 equals('')); |
| 176 | 187 |
| 177 // Test exit dir (but not overall dir) is opposite to context dir, dirReset. | 188 // Test exit dir (but not overall dir) is opposite to context dir, dirReset. |
| 178 expect(ltrFmt.wrapWithUnicode('$longEn$he$html', true, true), | 189 expect(ltrFmt.wrapWithUnicode('$longEn$he$html', isHtml: true, |
| 179 equals('$longEn$he$html$LRM')); | 190 resetDir: true), equals('$longEn$he$html$LRM')); |
| 180 // Test overall dir (but not exit dir) is opposite to context dir, dirReset. | 191 // Test overall dir (but not exit dir) is opposite to context dir, dirReset. |
| 181 expect(rtlFmt.wrapWithUnicode('$longEn$he', true, true), | 192 expect(rtlFmt.wrapWithUnicode('$longEn$he', isHtml: true, resetDir: true), |
| 182 equals('$LRE$longEn$he$PDF$RLM')); | 193 equals('$LRE$longEn$he$PDF$RLM')); |
| 183 | 194 |
| 184 // Test overall dir matches context dir (LTR). | 195 // Test overall dir matches context dir (LTR). |
| 185 expect(ltrFmt.wrapWithUnicode(en, | 196 expect(ltrFmt.wrapWithUnicode(en, |
| 186 direction : TextDirection.LTR), equals(en)); | 197 direction : TextDirection.LTR), equals(en)); |
| 187 // Test overall dir (but not exit dir) supposedly matches context dir (LTR). | 198 // Test overall dir (but not exit dir) supposedly matches context dir (LTR). |
| 188 expect(ltrFmt.wrapWithUnicode(he, direction : TextDirection.LTR), | 199 expect(ltrFmt.wrapWithUnicode(he, direction : TextDirection.LTR), |
| 189 equals('$he$LRM')); | 200 equals('$he$LRM')); |
| 190 // Test overall dir matches context dir (RTL). | 201 // Test overall dir matches context dir (RTL). |
| 191 expect(rtlFmt.wrapWithUnicode(he, | 202 expect(rtlFmt.wrapWithUnicode(he, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 207 expect(rtlFmt.wrapWithUnicode(he, direction : TextDirection.LTR), | 218 expect(rtlFmt.wrapWithUnicode(he, direction : TextDirection.LTR), |
| 208 equals('$LRE$he$PDF$RLM')); | 219 equals('$LRE$he$PDF$RLM')); |
| 209 // Test supposed overall dir (LTR) doesn't match context dir (unknown). | 220 // Test supposed overall dir (LTR) doesn't match context dir (unknown). |
| 210 expect(unkFmt.wrapWithUnicode(he, direction : TextDirection.LTR), | 221 expect(unkFmt.wrapWithUnicode(he, direction : TextDirection.LTR), |
| 211 equals('$LRE$he$PDF')); | 222 equals('$LRE$he$PDF')); |
| 212 // Test supposed overall dir (neutral) doesn't match context dir (LTR). | 223 // Test supposed overall dir (neutral) doesn't match context dir (LTR). |
| 213 expect(ltrFmt.wrapWithUnicode(he, direction : TextDirection.UNKNOWN), | 224 expect(ltrFmt.wrapWithUnicode(he, direction : TextDirection.UNKNOWN), |
| 214 equals('$he$LRM')); | 225 equals('$he$LRM')); |
| 215 }); | 226 }); |
| 216 } | 227 } |
| OLD | NEW |