1/* 2 * Copyright (C) 2010,2011 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 19import android.test.AndroidTestCase; 20 21import com.android.inputmethod.latin.tests.R; 22 23public class UtilsTests extends AndroidTestCase { 24 25 // The following is meant to be a reasonable default for 26 // the "word_separators" resource. 27 private static final String sSeparators = ".,:;!?-"; 28 29 @Override 30 protected void setUp() throws Exception { 31 super.setUp(); 32 } 33 34 /************************** Tests ************************/ 35 36 /** 37 * Test for getting previous word (for bigram suggestions) 38 */ 39 public void testGetPreviousWord() { 40 // If one of the following cases breaks, the bigram suggestions won't work. 41 assertEquals(EditingUtils.getPreviousWord("abc def", sSeparators), "abc"); 42 assertNull(EditingUtils.getPreviousWord("abc", sSeparators)); 43 assertNull(EditingUtils.getPreviousWord("abc. def", sSeparators)); 44 45 // The following tests reflect the current behavior of the function 46 // EditingUtils#getPreviousWord. 47 // TODO: However at this time, the code does never go 48 // into such a path, so it should be safe to change the behavior of 49 // this function if needed - especially since it does not seem very 50 // logical. These tests are just there to catch any unintentional 51 // changes in the behavior of the EditingUtils#getPreviousWord method. 52 assertEquals(EditingUtils.getPreviousWord("abc def ", sSeparators), "abc"); 53 assertEquals(EditingUtils.getPreviousWord("abc def.", sSeparators), "abc"); 54 assertEquals(EditingUtils.getPreviousWord("abc def .", sSeparators), "def"); 55 assertNull(EditingUtils.getPreviousWord("abc ", sSeparators)); 56 } 57 58 /** 59 * Test for getting the word before the cursor (for bigram) 60 */ 61 public void testGetThisWord() { 62 assertEquals(EditingUtils.getThisWord("abc def", sSeparators), "def"); 63 assertEquals(EditingUtils.getThisWord("abc def ", sSeparators), "def"); 64 assertNull(EditingUtils.getThisWord("abc def.", sSeparators)); 65 assertNull(EditingUtils.getThisWord("abc def .", sSeparators)); 66 } 67} 68