diff options
author | 2013-10-03 13:20:51 -0700 | |
---|---|---|
committer | 2013-10-03 13:20:51 -0700 | |
commit | 9ca0e511e8a604dabb2ce0055ed38501af66eb6d (patch) | |
tree | 53eb6e06377a3df55f72b062ca599fff4f399a7c /tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java | |
parent | 12f9d9cc8599fcff2e250c4d62e8a4fb69a4db33 (diff) | |
parent | 086ffdcc30196bf5aae1dbc95ea1b0463880035a (diff) | |
download | latinime-9ca0e511e8a604dabb2ce0055ed38501af66eb6d.tar.gz latinime-9ca0e511e8a604dabb2ce0055ed38501af66eb6d.tar.xz latinime-9ca0e511e8a604dabb2ce0055ed38501af66eb6d.zip |
am 086ffdcc: am 6c0e48b1: am 4350a93a: Merge "Fix the offdevice regression test build"
* commit '086ffdcc30196bf5aae1dbc95ea1b0463880035a':
Fix the offdevice regression test build
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java new file mode 100644 index 000000000..fa6ad16c1 --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.inputmethod.latin.utils; + +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; +import android.text.style.SuggestionSpan; +import android.text.style.URLSpan; +import android.text.SpannableStringBuilder; +import android.text.Spannable; +import android.text.Spanned; + +@SmallTest +public class SpannableStringUtilsTests extends AndroidTestCase { + public void testConcatWithSuggestionSpansOnly() { + SpannableStringBuilder s = new SpannableStringBuilder("test string\ntest string\n" + + "test string\ntest string\ntest string\ntest string\ntest string\ntest string\n" + + "test string\ntest string\n"); + final int N = 10; + for (int i = 0; i < N; ++i) { + // Put a PARAGRAPH-flagged span that should not be found in the result. + s.setSpan(new SuggestionSpan(getContext(), + new String[] {"" + i}, Spannable.SPAN_PARAGRAPH), + i * 12, i * 12 + 12, Spannable.SPAN_PARAGRAPH); + // Put a normal suggestion span that should be found in the result. + s.setSpan(new SuggestionSpan(getContext(), new String[] {"" + i}, 0), i, i * 2, 0); + // Put a URL span than should not be found in the result. + s.setSpan(new URLSpan("http://a"), i, i * 2, 0); + } + + final CharSequence a = s.subSequence(0, 15); + final CharSequence b = s.subSequence(15, s.length()); + final Spanned result = + (Spanned)SpannableStringUtils.concatWithNonParagraphSuggestionSpansOnly(a, b); + + Object[] spans = result.getSpans(0, result.length(), SuggestionSpan.class); + for (int i = 0; i < spans.length; i++) { + final int flags = result.getSpanFlags(spans[i]); + assertEquals("Should not find a span with PARAGRAPH flag", + flags & Spannable.SPAN_PARAGRAPH, 0); + assertTrue("Should be a SuggestionSpan", spans[i] instanceof SuggestionSpan); + } + } +} |