1 /* 2 * Copyright (C) 2013 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 package android.text; 18 19 import static org.junit.Assert.assertEquals; 20 21 import android.support.test.filters.SmallTest; 22 import android.support.test.runner.AndroidJUnit4; 23 24 import org.junit.Test; 25 import org.junit.runner.RunWith; 26 27 @SmallTest 28 @RunWith(AndroidJUnit4.class) 29 public class BidiFormatterTest { 30 private static final BidiFormatter LTR_FMT = BidiFormatter.getInstance(false /* LTR context */); 31 private static final BidiFormatter RTL_FMT = BidiFormatter.getInstance(true /* RTL context */); 32 33 private static final String EN = "abba"; 34 private static final String HE = "\u05E0\u05E1"; 35 36 private static final String LRM = "\u200E"; 37 private static final String RLM = "\u200F"; 38 39 @Test 40 public void testMarkAfter() { 41 assertEquals("uniform dir matches LTR context", 42 "", LTR_FMT.markAfter(EN, TextDirectionHeuristics.LTR)); 43 assertEquals("uniform dir matches RTL context", 44 "", RTL_FMT.markAfter(HE, TextDirectionHeuristics.RTL)); 45 46 assertEquals("exit dir opposite to LTR context", 47 LRM, LTR_FMT.markAfter(EN + HE, TextDirectionHeuristics.LTR)); 48 assertEquals("exit dir opposite to RTL context", 49 RLM, RTL_FMT.markAfter(HE + EN, TextDirectionHeuristics.RTL)); 50 51 assertEquals("overall dir (but not exit dir) opposite to LTR context", 52 LRM, LTR_FMT.markAfter(HE + EN, TextDirectionHeuristics.RTL)); 53 assertEquals("overall dir (but not exit dir) opposite to RTL context", 54 RLM, RTL_FMT.markAfter(EN + HE, TextDirectionHeuristics.LTR)); 55 56 assertEquals("exit dir neutral, overall dir matches LTR context", 57 "", LTR_FMT.markAfter(".", TextDirectionHeuristics.LTR)); 58 assertEquals("exit dir neutral, overall dir matches RTL context", 59 "", RTL_FMT.markAfter(".", TextDirectionHeuristics.RTL)); 60 } 61 62 @Test 63 public void testMarkBefore() { 64 assertEquals("uniform dir matches LTR context", 65 "", LTR_FMT.markBefore(EN, TextDirectionHeuristics.LTR)); 66 assertEquals("uniform dir matches RTL context", 67 "", RTL_FMT.markBefore(HE, TextDirectionHeuristics.RTL)); 68 69 assertEquals("entry dir opposite to LTR context", 70 LRM, LTR_FMT.markBefore(HE + EN, TextDirectionHeuristics.LTR)); 71 assertEquals("entry dir opposite to RTL context", 72 RLM, RTL_FMT.markBefore(EN + HE, TextDirectionHeuristics.RTL)); 73 74 assertEquals("overall dir (but not entry dir) opposite to LTR context", 75 LRM, LTR_FMT.markBefore(EN + HE, TextDirectionHeuristics.RTL)); 76 assertEquals("overall dir (but not entry dir) opposite to RTL context", 77 RLM, RTL_FMT.markBefore(HE + EN, TextDirectionHeuristics.LTR)); 78 79 assertEquals("exit dir neutral, overall dir matches LTR context", 80 "", LTR_FMT.markBefore(".", TextDirectionHeuristics.LTR)); 81 assertEquals("exit dir neutral, overall dir matches RTL context", 82 "", RTL_FMT.markBefore(".", TextDirectionHeuristics.RTL)); 83 } 84 } 85