Home | History | Annotate | Download | only in utils
      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 com.android.inputmethod.latin.utils;
     18 
     19 import android.test.AndroidTestCase;
     20 import android.test.suitebuilder.annotation.SmallTest;
     21 
     22 import com.android.inputmethod.latin.common.Constants;
     23 
     24 import java.util.Locale;
     25 
     26 @SmallTest
     27 public class RecapitalizeStatusTests extends AndroidTestCase {
     28     private static final int[] SPACE = { Constants.CODE_SPACE };
     29 
     30     public void testTrim() {
     31         final RecapitalizeStatus status = new RecapitalizeStatus();
     32         status.start(30, 40, "abcdefghij", Locale.ENGLISH, SPACE);
     33         status.trim();
     34         assertEquals("abcdefghij", status.getRecapitalizedString());
     35         assertEquals(30, status.getNewCursorStart());
     36         assertEquals(40, status.getNewCursorEnd());
     37 
     38         status.start(30, 44, "    abcdefghij", Locale.ENGLISH, SPACE);
     39         status.trim();
     40         assertEquals("abcdefghij", status.getRecapitalizedString());
     41         assertEquals(34, status.getNewCursorStart());
     42         assertEquals(44, status.getNewCursorEnd());
     43 
     44         status.start(30, 40, "abcdefgh  ", Locale.ENGLISH, SPACE);
     45         status.trim();
     46         assertEquals("abcdefgh", status.getRecapitalizedString());
     47         assertEquals(30, status.getNewCursorStart());
     48         assertEquals(38, status.getNewCursorEnd());
     49 
     50         status.start(30, 45, "   abcdefghij  ", Locale.ENGLISH, SPACE);
     51         status.trim();
     52         assertEquals("abcdefghij", status.getRecapitalizedString());
     53         assertEquals(33, status.getNewCursorStart());
     54         assertEquals(43, status.getNewCursorEnd());
     55     }
     56 
     57     public void testRotate() {
     58         final RecapitalizeStatus status = new RecapitalizeStatus();
     59         status.start(29, 40, "abcd efghij", Locale.ENGLISH, SPACE);
     60         status.rotate();
     61         assertEquals("Abcd Efghij", status.getRecapitalizedString());
     62         assertEquals(29, status.getNewCursorStart());
     63         assertEquals(40, status.getNewCursorEnd());
     64         status.rotate();
     65         assertEquals("ABCD EFGHIJ", status.getRecapitalizedString());
     66         status.rotate();
     67         assertEquals("abcd efghij", status.getRecapitalizedString());
     68         status.rotate();
     69         assertEquals("Abcd Efghij", status.getRecapitalizedString());
     70 
     71         status.start(29, 40, "Abcd Efghij", Locale.ENGLISH, SPACE);
     72         status.rotate();
     73         assertEquals("ABCD EFGHIJ", status.getRecapitalizedString());
     74         assertEquals(29, status.getNewCursorStart());
     75         assertEquals(40, status.getNewCursorEnd());
     76         status.rotate();
     77         assertEquals("abcd efghij", status.getRecapitalizedString());
     78         status.rotate();
     79         assertEquals("Abcd Efghij", status.getRecapitalizedString());
     80         status.rotate();
     81         assertEquals("ABCD EFGHIJ", status.getRecapitalizedString());
     82 
     83         status.start(29, 40, "ABCD EFGHIJ", Locale.ENGLISH, SPACE);
     84         status.rotate();
     85         assertEquals("abcd efghij", status.getRecapitalizedString());
     86         assertEquals(29, status.getNewCursorStart());
     87         assertEquals(40, status.getNewCursorEnd());
     88         status.rotate();
     89         assertEquals("Abcd Efghij", status.getRecapitalizedString());
     90         status.rotate();
     91         assertEquals("ABCD EFGHIJ", status.getRecapitalizedString());
     92         status.rotate();
     93         assertEquals("abcd efghij", status.getRecapitalizedString());
     94 
     95         status.start(29, 39, "AbCDefghij", Locale.ENGLISH, SPACE);
     96         status.rotate();
     97         assertEquals("abcdefghij", status.getRecapitalizedString());
     98         assertEquals(29, status.getNewCursorStart());
     99         assertEquals(39, status.getNewCursorEnd());
    100         status.rotate();
    101         assertEquals("Abcdefghij", status.getRecapitalizedString());
    102         status.rotate();
    103         assertEquals("ABCDEFGHIJ", status.getRecapitalizedString());
    104         status.rotate();
    105         assertEquals("AbCDefghij", status.getRecapitalizedString());
    106         status.rotate();
    107         assertEquals("abcdefghij", status.getRecapitalizedString());
    108 
    109         status.start(29, 40, "Abcd efghij", Locale.ENGLISH, SPACE);
    110         status.rotate();
    111         assertEquals("abcd efghij", status.getRecapitalizedString());
    112         assertEquals(29, status.getNewCursorStart());
    113         assertEquals(40, status.getNewCursorEnd());
    114         status.rotate();
    115         assertEquals("Abcd Efghij", status.getRecapitalizedString());
    116         status.rotate();
    117         assertEquals("ABCD EFGHIJ", status.getRecapitalizedString());
    118         status.rotate();
    119         assertEquals("Abcd efghij", status.getRecapitalizedString());
    120         status.rotate();
    121         assertEquals("abcd efghij", status.getRecapitalizedString());
    122 
    123         status.start(30, 34, "gr", Locale.GERMAN, SPACE);
    124         status.rotate();
    125         assertEquals("Gr", status.getRecapitalizedString());
    126         assertEquals(30, status.getNewCursorStart());
    127         assertEquals(34, status.getNewCursorEnd());
    128         status.rotate();
    129         assertEquals("GRSS", status.getRecapitalizedString());
    130         assertEquals(30, status.getNewCursorStart());
    131         assertEquals(35, status.getNewCursorEnd());
    132         status.rotate();
    133         assertEquals("gr", status.getRecapitalizedString());
    134         assertEquals(30, status.getNewCursorStart());
    135         assertEquals(34, status.getNewCursorEnd());
    136         status.rotate();
    137         assertEquals("Gr", status.getRecapitalizedString());
    138         assertEquals(30, status.getNewCursorStart());
    139         assertEquals(34, status.getNewCursorEnd());
    140 
    141         status.start(30, 33, "uf", Locale.FRENCH, SPACE);
    142         status.rotate();
    143         assertEquals("uf", status.getRecapitalizedString());
    144         assertEquals(30, status.getNewCursorStart());
    145         assertEquals(33, status.getNewCursorEnd());
    146         status.rotate();
    147         assertEquals("UF", status.getRecapitalizedString());
    148         assertEquals(30, status.getNewCursorStart());
    149         assertEquals(33, status.getNewCursorEnd());
    150         status.rotate();
    151         assertEquals("uf", status.getRecapitalizedString());
    152         assertEquals(30, status.getNewCursorStart());
    153         assertEquals(33, status.getNewCursorEnd());
    154         status.rotate();
    155         assertEquals("uf", status.getRecapitalizedString());
    156         assertEquals(30, status.getNewCursorStart());
    157         assertEquals(33, status.getNewCursorEnd());
    158 
    159         status.start(30, 33, "Uf", Locale.FRENCH, SPACE);
    160         status.rotate();
    161         assertEquals("uf", status.getRecapitalizedString());
    162         assertEquals(30, status.getNewCursorStart());
    163         assertEquals(33, status.getNewCursorEnd());
    164         status.rotate();
    165         assertEquals("uf", status.getRecapitalizedString());
    166         assertEquals(30, status.getNewCursorStart());
    167         assertEquals(33, status.getNewCursorEnd());
    168         status.rotate();
    169         assertEquals("UF", status.getRecapitalizedString());
    170         assertEquals(30, status.getNewCursorStart());
    171         assertEquals(33, status.getNewCursorEnd());
    172         status.rotate();
    173         assertEquals("Uf", status.getRecapitalizedString());
    174         assertEquals(30, status.getNewCursorStart());
    175         assertEquals(33, status.getNewCursorEnd());
    176         status.rotate();
    177         assertEquals("uf", status.getRecapitalizedString());
    178         assertEquals(30, status.getNewCursorStart());
    179         assertEquals(33, status.getNewCursorEnd());
    180 
    181         status.start(30, 35, "cole", Locale.FRENCH, SPACE);
    182         status.rotate();
    183         assertEquals("cole", status.getRecapitalizedString());
    184         assertEquals(30, status.getNewCursorStart());
    185         assertEquals(35, status.getNewCursorEnd());
    186         status.rotate();
    187         assertEquals("COLE", status.getRecapitalizedString());
    188         assertEquals(30, status.getNewCursorStart());
    189         assertEquals(35, status.getNewCursorEnd());
    190         status.rotate();
    191         assertEquals("cole", status.getRecapitalizedString());
    192         assertEquals(30, status.getNewCursorStart());
    193         assertEquals(35, status.getNewCursorEnd());
    194         status.rotate();
    195         assertEquals("cole", status.getRecapitalizedString());
    196         assertEquals(30, status.getNewCursorStart());
    197         assertEquals(35, status.getNewCursorEnd());
    198     }
    199 }
    200