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