PunctuationTests.java revision 6aaa105a851c1dc558a09a19fa716e9ad54270e4
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
17package com.android.inputmethod.latin;
18
19public class PunctuationTests extends InputTestsBase {
20
21    public void testWordThenSpaceThenPunctuationFromStripTwice() {
22        final String WORD_TO_TYPE = "this ";
23        final String PUNCTUATION_FROM_STRIP = "!";
24        final String EXPECTED_RESULT = "this!! ";
25        type(WORD_TO_TYPE);
26        sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
27        runMessages();
28        assertTrue("type word then type space should display punctuation strip",
29                mLatinIME.isShowingPunctuationList());
30        mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
31        mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
32        assertEquals("type word then type space then punctuation from strip twice", EXPECTED_RESULT,
33                mTextView.getText().toString());
34    }
35
36    public void testWordThenSpaceThenPunctuationFromKeyboardTwice() {
37        final String WORD_TO_TYPE = "this !!";
38        final String EXPECTED_RESULT = "this !!";
39        type(WORD_TO_TYPE);
40        assertEquals("manual pick then space then punctuation from keyboard twice", EXPECTED_RESULT,
41                mTextView.getText().toString());
42    }
43
44    public void testManualPickThenPunctuationFromStripTwiceThenType() {
45        final String WORD1_TO_TYPE = "this";
46        final String WORD2_TO_TYPE = "is";
47        final String PUNCTUATION_FROM_STRIP = "!";
48        final String EXPECTED_RESULT = "this!! is";
49        type(WORD1_TO_TYPE);
50        mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE);
51        mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
52        mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
53        type(WORD2_TO_TYPE);
54        assertEquals("pick word then pick punctuation twice then type", EXPECTED_RESULT,
55                mTextView.getText().toString());
56    }
57
58    public void testManualPickThenManualPickWithPunctAtStart() {
59        final String WORD1_TO_TYPE = "this";
60        final String WORD2_TO_PICK = "!is";
61        final String EXPECTED_RESULT = "this!is";
62        type(WORD1_TO_TYPE);
63        mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE);
64        mLatinIME.pickSuggestionManually(1, WORD2_TO_PICK);
65        assertEquals("manual pick then manual pick a word with punct at start", EXPECTED_RESULT,
66                mTextView.getText().toString());
67    }
68
69    public void testManuallyPickedWordThenColon() {
70        final String WORD_TO_TYPE = "this";
71        final String PUNCTUATION = ":";
72        final String EXPECTED_RESULT = "this:";
73        type(WORD_TO_TYPE);
74        mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE);
75        type(PUNCTUATION);
76        assertEquals("manually pick word then colon",
77                EXPECTED_RESULT, mTextView.getText().toString());
78    }
79
80    public void testManuallyPickedWordThenOpenParen() {
81        final String WORD_TO_TYPE = "this";
82        final String PUNCTUATION = "(";
83        final String EXPECTED_RESULT = "this (";
84        type(WORD_TO_TYPE);
85        mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE);
86        type(PUNCTUATION);
87        assertEquals("manually pick word then open paren",
88                EXPECTED_RESULT, mTextView.getText().toString());
89    }
90
91    public void testManuallyPickedWordThenCloseParen() {
92        final String WORD_TO_TYPE = "this";
93        final String PUNCTUATION = ")";
94        final String EXPECTED_RESULT = "this)";
95        type(WORD_TO_TYPE);
96        mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE);
97        type(PUNCTUATION);
98        assertEquals("manually pick word then close paren",
99                EXPECTED_RESULT, mTextView.getText().toString());
100    }
101
102    public void testManuallyPickedWordThenSmiley() {
103        final String WORD_TO_TYPE = "this";
104        final String SPECIAL_KEY = ":-)";
105        final String EXPECTED_RESULT = "this :-)";
106        type(WORD_TO_TYPE);
107        mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE);
108        mLatinIME.onTextInput(SPECIAL_KEY);
109        assertEquals("manually pick word then press the smiley key",
110                EXPECTED_RESULT, mTextView.getText().toString());
111    }
112
113    public void testManuallyPickedWordThenDotCom() {
114        final String WORD_TO_TYPE = "this";
115        final String SPECIAL_KEY = ".com";
116        final String EXPECTED_RESULT = "this.com";
117        type(WORD_TO_TYPE);
118        mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE);
119        mLatinIME.onTextInput(SPECIAL_KEY);
120        assertEquals("manually pick word then press the .com key",
121                EXPECTED_RESULT, mTextView.getText().toString());
122    }
123
124    public void testTypeWordTypeDotThenPressDotCom() {
125        final String WORD_TO_TYPE = "this.";
126        final String SPECIAL_KEY = ".com";
127        final String EXPECTED_RESULT = "this.com";
128        type(WORD_TO_TYPE);
129        mLatinIME.onTextInput(SPECIAL_KEY);
130        assertEquals("type word type dot then press the .com key",
131                EXPECTED_RESULT, mTextView.getText().toString());
132    }
133
134    public void testAutoCorrectionWithSingleQuoteInside() {
135        final String WORD_TO_TYPE = "you'f ";
136        final String EXPECTED_RESULT = "you'd ";
137        type(WORD_TO_TYPE);
138        assertEquals("auto-correction with single quote inside",
139                EXPECTED_RESULT, mTextView.getText().toString());
140    }
141
142    public void testAutoCorrectionWithSingleQuotesAround() {
143        final String WORD_TO_TYPE = "'tgis' ";
144        final String EXPECTED_RESULT = "'this' ";
145        type(WORD_TO_TYPE);
146        assertEquals("auto-correction with single quotes around",
147                EXPECTED_RESULT, mTextView.getText().toString());
148    }
149}
150