• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 package com.android.inputmethod.latin;
18 
19 import com.android.inputmethod.latin.R;
20 
21 public class PunctuationTests extends InputTestsBase {
22 
23     final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction";
24 
testWordThenSpaceThenPunctuationFromStripTwice()25     public void testWordThenSpaceThenPunctuationFromStripTwice() {
26         final String WORD_TO_TYPE = "this ";
27         final String PUNCTUATION_FROM_STRIP = "!";
28         final String EXPECTED_RESULT = "this!! ";
29         final boolean defaultNextWordPredictionOption =
30                 mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction);
31         final boolean previousNextWordPredictionOption =
32                 setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, false,
33                         defaultNextWordPredictionOption);
34         try {
35             mLatinIME.loadSettings();
36             type(WORD_TO_TYPE);
37             sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
38             runMessages();
39             assertTrue("type word then type space should display punctuation strip",
40                     mLatinIME.isShowingPunctuationList());
41             pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
42             pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
43             assertEquals("type word then type space then punctuation from strip twice",
44                     EXPECTED_RESULT, mTextView.getText().toString());
45         } finally {
46             setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption,
47                     defaultNextWordPredictionOption);
48         }
49     }
50 
testWordThenSpaceThenPunctuationFromKeyboardTwice()51     public void testWordThenSpaceThenPunctuationFromKeyboardTwice() {
52         final String WORD_TO_TYPE = "this !!";
53         final String EXPECTED_RESULT = "this !!";
54         type(WORD_TO_TYPE);
55         assertEquals("manual pick then space then punctuation from keyboard twice", EXPECTED_RESULT,
56                 mTextView.getText().toString());
57     }
58 
testManualPickThenPunctuationFromStripTwiceThenType()59     public void testManualPickThenPunctuationFromStripTwiceThenType() {
60         final String WORD1_TO_TYPE = "this";
61         final String WORD2_TO_TYPE = "is";
62         final String PUNCTUATION_FROM_STRIP = "!";
63         final String EXPECTED_RESULT = "this!! is";
64         type(WORD1_TO_TYPE);
65         pickSuggestionManually(0, WORD1_TO_TYPE);
66         pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
67         pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
68         type(WORD2_TO_TYPE);
69         assertEquals("pick word then pick punctuation twice then type", EXPECTED_RESULT,
70                 mTextView.getText().toString());
71     }
72 
testManualPickThenManualPickWithPunctAtStart()73     public void testManualPickThenManualPickWithPunctAtStart() {
74         final String WORD1_TO_TYPE = "this";
75         final String WORD2_TO_PICK = "!is";
76         final String EXPECTED_RESULT = "this!is";
77         type(WORD1_TO_TYPE);
78         pickSuggestionManually(0, WORD1_TO_TYPE);
79         pickSuggestionManually(1, WORD2_TO_PICK);
80         assertEquals("manual pick then manual pick a word with punct at start", EXPECTED_RESULT,
81                 mTextView.getText().toString());
82     }
83 
testManuallyPickedWordThenColon()84     public void testManuallyPickedWordThenColon() {
85         final String WORD_TO_TYPE = "this";
86         final String PUNCTUATION = ":";
87         final String EXPECTED_RESULT = "this:";
88         type(WORD_TO_TYPE);
89         pickSuggestionManually(0, WORD_TO_TYPE);
90         type(PUNCTUATION);
91         assertEquals("manually pick word then colon",
92                 EXPECTED_RESULT, mTextView.getText().toString());
93     }
94 
testManuallyPickedWordThenOpenParen()95     public void testManuallyPickedWordThenOpenParen() {
96         final String WORD_TO_TYPE = "this";
97         final String PUNCTUATION = "(";
98         final String EXPECTED_RESULT = "this (";
99         type(WORD_TO_TYPE);
100         pickSuggestionManually(0, WORD_TO_TYPE);
101         type(PUNCTUATION);
102         assertEquals("manually pick word then open paren",
103                 EXPECTED_RESULT, mTextView.getText().toString());
104     }
105 
testManuallyPickedWordThenCloseParen()106     public void testManuallyPickedWordThenCloseParen() {
107         final String WORD_TO_TYPE = "this";
108         final String PUNCTUATION = ")";
109         final String EXPECTED_RESULT = "this)";
110         type(WORD_TO_TYPE);
111         pickSuggestionManually(0, WORD_TO_TYPE);
112         type(PUNCTUATION);
113         assertEquals("manually pick word then close paren",
114                 EXPECTED_RESULT, mTextView.getText().toString());
115     }
116 
testManuallyPickedWordThenSmiley()117     public void testManuallyPickedWordThenSmiley() {
118         final String WORD_TO_TYPE = "this";
119         final String SPECIAL_KEY = ":-)";
120         final String EXPECTED_RESULT = "this :-)";
121         type(WORD_TO_TYPE);
122         pickSuggestionManually(0, WORD_TO_TYPE);
123         mLatinIME.onTextInput(SPECIAL_KEY);
124         assertEquals("manually pick word then press the smiley key",
125                 EXPECTED_RESULT, mTextView.getText().toString());
126     }
127 
testManuallyPickedWordThenDotCom()128     public void testManuallyPickedWordThenDotCom() {
129         final String WORD_TO_TYPE = "this";
130         final String SPECIAL_KEY = ".com";
131         final String EXPECTED_RESULT = "this.com";
132         type(WORD_TO_TYPE);
133         pickSuggestionManually(0, WORD_TO_TYPE);
134         mLatinIME.onTextInput(SPECIAL_KEY);
135         assertEquals("manually pick word then press the .com key",
136                 EXPECTED_RESULT, mTextView.getText().toString());
137     }
138 
testTypeWordTypeDotThenPressDotCom()139     public void testTypeWordTypeDotThenPressDotCom() {
140         final String WORD_TO_TYPE = "this.";
141         final String SPECIAL_KEY = ".com";
142         final String EXPECTED_RESULT = "this.com";
143         type(WORD_TO_TYPE);
144         mLatinIME.onTextInput(SPECIAL_KEY);
145         assertEquals("type word type dot then press the .com key",
146                 EXPECTED_RESULT, mTextView.getText().toString());
147     }
148 
testAutoCorrectionWithSingleQuoteInside()149     public void testAutoCorrectionWithSingleQuoteInside() {
150         final String WORD_TO_TYPE = "you'f ";
151         final String EXPECTED_RESULT = "you'd ";
152         type(WORD_TO_TYPE);
153         assertEquals("auto-correction with single quote inside",
154                 EXPECTED_RESULT, mTextView.getText().toString());
155     }
156 
testAutoCorrectionWithSingleQuotesAround()157     public void testAutoCorrectionWithSingleQuotesAround() {
158         final String WORD_TO_TYPE = "'tgis' ";
159         final String EXPECTED_RESULT = "'this' ";
160         type(WORD_TO_TYPE);
161         assertEquals("auto-correction with single quotes around",
162                 EXPECTED_RESULT, mTextView.getText().toString());
163     }
164 }
165