diff options
author | George Fraser <george@fivetran.com> | 2018-12-29 01:15:04 -0800 |
---|---|---|
committer | George Fraser <george@fivetran.com> | 2018-12-29 01:15:04 -0800 |
commit | 42db035b1099267db8ad4c7f39e3991ff4aad697 (patch) | |
tree | d10256ce649d53ed1c4d25f0cc13f14f6825d72e /src/test/java | |
parent | f342aa14b13149cf061942584edd447f37edd3cd (diff) | |
download | java-language-server-42db035b1099267db8ad4c7f39e3991ff4aad697.zip |
Boyer–Moore string search is faster but not the same semantics
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/org/javacs/StringSearchTest.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/test/java/org/javacs/StringSearchTest.java b/src/test/java/org/javacs/StringSearchTest.java new file mode 100644 index 0000000..7827fcd --- /dev/null +++ b/src/test/java/org/javacs/StringSearchTest.java @@ -0,0 +1,32 @@ +package org.javacs; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +import org.junit.Test; + +public class StringSearchTest { + private void testNext(String pat, String text, int index) { + var got = new StringSearch(pat).next(text); + assertThat(got, equalTo(index)); + } + + @Test + public void testFinderNext() { + testNext("", "", 0); + testNext("", "abc", 0); + testNext("abc", "", -1); + testNext("abc", "abc", 0); + testNext("d", "abcdefg", 3); + testNext("nan", "banana", 2); + testNext("pan", "anpanman", 2); + testNext("nnaaman", "anpanmanam", -1); + testNext("abcd", "abc", -1); + testNext("abcd", "bcd", -1); + testNext("bcd", "abcd", 1); + testNext("abc", "acca", -1); + testNext("aa", "aaa", 0); + testNext("baa", "aaaaa", -1); + testNext("at that", "which finally halts. at that point", 22); + } +} |