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