Apache Solr open-source search software
LUCENE-5480: add the tests i have so far... (not including this bug yet though)
Robert Muira7506921b9fe
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/StemmerTestBase.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/StemmerTestBase.javanew file mode 100644index 00000000000..67b1eca66cd--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/StemmerTestBase.java@@ -0,0 +1,79 @@+package org.apache.lucene.analysis.hunspell;++/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You 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.+ */++import java.io.FileNotFoundException;+import java.io.IOException;+import java.io.InputStream;+import java.text.ParseException;+import java.util.Arrays;+import java.util.List;++import org.apache.lucene.util.CharsRef;+import org.apache.lucene.util.IOUtils;+import org.apache.lucene.util.LuceneTestCase;++/** base class for hunspell stemmer tests */+abstract class StemmerTestBase extends LuceneTestCase {+ private static Stemmer stemmer;++ static void init(String affix, String dictionary) throws IOException, ParseException {+ init(false, affix, dictionary);+ }++ static void init(boolean ignoreCase, String affix, String... dictionaries) throws IOException, ParseException {+ if (dictionaries.length == 0) {+ throw new IllegalArgumentException("there must be at least one dictionary");+ }++ InputStream affixStream = StemmerTestBase.class.getResourceAsStream(affix);+ if (affixStream == null) {+ throw new FileNotFoundException("file not found: " + affix);+ }++ InputStream dictStreams[] = new InputStream[dictionaries.length];+ for (int i = 0; i < dictionaries.length; i++) {+ dictStreams[i] = StemmerTestBase.class.getResourceAsStream(dictionaries[i]);+ if (dictStreams[i] == null) {+ throw new FileNotFoundException("file not found: " + dictStreams[i]);+ }+ }++ try {+ Dictionary dictionary = new Dictionary(affixStream, Arrays.asList(dictStreams), true);+ stemmer = new Stemmer(dictionary);+ } finally {+ IOUtils.closeWhileHandlingException(affixStream);+ IOUtils.closeWhileHandlingException(dictStreams);+ }+ }++ static void assertStemsTo(String s, String... expected) {+ assertNotNull(stemmer);+ Arrays.sort(expected);++ List<CharsRef> stems = stemmer.stem(s);+ String actual[] = new String[stems.size()];+ for (int i = 0; i < actual.length; i++) {+ actual[i] = stems.get(i).toString();+ }+ Arrays.sort(actual);++ assertArrayEquals(expected, actual);+ }+}diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestCaseInsensitive.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestCaseInsensitive.javaindex 64bdb41e8c7..b1e7c1347ee 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestCaseInsensitive.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestCaseInsensitive.java@@ -17,33 +17,13 @@ package org.apache.lucene.analysis.hunspell;* limitations under the License.*/-import org.apache.lucene.analysis.hunspell.Dictionary;-import org.apache.lucene.analysis.hunspell.Stemmer;-import org.apache.lucene.util.CharsRef;-import org.apache.lucene.util.LuceneTestCase;-import org.junit.AfterClass;import org.junit.BeforeClass;-import java.io.InputStream;-import java.util.Arrays;-import java.util.Collections;-import java.util.List;--public class TestCaseInsensitive extends LuceneTestCase {- private static Stemmer stemmer;+public class TestCaseInsensitive extends StemmerTestBase {@BeforeClasspublic static void beforeClass() throws Exception {- try (InputStream affixStream = TestCaseInsensitive.class.getResourceAsStream("simple.aff");- InputStream dictStream = TestCaseInsensitive.class.getResourceAsStream("mixedcase.dic")) {- Dictionary dictionary = new Dictionary(affixStream, Collections.singletonList(dictStream), true);- stemmer = new Stemmer(dictionary);- }- }-- @AfterClass- public static void afterClass() {- stemmer = null;+ init(true, "simple.aff", "mixedcase.dic");}public void testCaseInsensitivity() {@@ -94,17 +74,4 @@ public class TestCaseInsensitive extends LuceneTestCase {assertStemsTo("lucenee");assertStemsTo("solre");}-- private void assertStemsTo(String s, String... expected) {- Arrays.sort(expected);-- List<CharsRef> stems = stemmer.stem(s);- String actual[] = new String[stems.size()];- for (int i = 0; i < actual.length; i++) {- actual[i] = stems.get(i).toString();- }- Arrays.sort(actual);-- assertArrayEquals(expected, actual);- }}diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestMorph.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestMorph.javanew file mode 100644index 00000000000..121744948cf--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestMorph.java@@ -0,0 +1,33 @@+package org.apache.lucene.analysis.hunspell;++/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You 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.+ */++import org.junit.BeforeClass;++public class TestMorph extends StemmerTestBase {++ @BeforeClass+ public static void beforeClass() throws Exception {+ init("morph.aff", "morph.dic");+ }++ public void testExamples() {+ assertStemsTo("drink", "drink");+ assertStemsTo("drinkable", "drink");+ }+}diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestStemmer.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestStemmer.javaindex dca9faa6b16..19a5e2a3d6d 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestStemmer.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestStemmer.java@@ -17,32 +17,13 @@ package org.apache.lucene.analysis.hunspell;* limitations under the License.*/-import org.apache.lucene.analysis.hunspell.Dictionary;-import org.apache.lucene.analysis.hunspell.Stemmer;-import org.apache.lucene.util.CharsRef;-import org.apache.lucene.util.LuceneTestCase;-import org.junit.AfterClass;import org.junit.BeforeClass;-import java.io.InputStream;-import java.util.Arrays;-import java.util.List;--public class TestStemmer extends LuceneTestCase {- private static Stemmer stemmer;+public class TestStemmer extends StemmerTestBase {@BeforeClasspublic static void beforeClass() throws Exception {- try (InputStream affixStream = TestStemmer.class.getResourceAsStream("simple.aff");- InputStream dictStream = TestStemmer.class.getResourceAsStream("simple.dic")) {- Dictionary dictionary = new Dictionary(affixStream, dictStream);- stemmer = new Stemmer(dictionary);- }- }-- @AfterClass- public static void afterClass() {- stemmer = null;+ init("simple.aff", "simple.dic");}public void testSimpleSuffix() {@@ -91,17 +72,4 @@ public class TestStemmer extends LuceneTestCase {assertStemsTo("lucenee");assertStemsTo("solre");}-- private void assertStemsTo(String s, String... expected) {- Arrays.sort(expected);-- List<CharsRef> stems = stemmer.stem(s);- String actual[] = new String[stems.size()];- for (int i = 0; i < actual.length; i++) {- actual[i] = stems.get(i).toString();- }- Arrays.sort(actual);-- assertArrayEquals(expected, actual);- }}diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestTwoFold.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestTwoFold.javanew file mode 100644index 00000000000..313b4ded1a9--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestTwoFold.java@@ -0,0 +1,34 @@+package org.apache.lucene.analysis.hunspell;++/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You 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.+ */++import org.junit.BeforeClass;++public class TestTwoFold extends StemmerTestBase {++ @BeforeClass+ public static void beforeClass() throws Exception {+ init("twofold.aff", "morph.dic");+ }++ public void testExamples() {+ assertStemsTo("drink", "drink");+ assertStemsTo("drinkable", "drink");+ assertStemsTo("drinkables", "drink");+ }+}diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.aff b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.affnew file mode 100644index 00000000000..78cae52f4b4--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.aff@@ -0,0 +1,4 @@+SET UTF-8++SFX X Y 1+SFX X 0 able . +ABLEdiff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.dic b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.dicnew file mode 100644index 00000000000..6b68dc80cc0--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.dic@@ -0,0 +1,2 @@+1+drink/X [VERB]diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/twofold.aff b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/twofold.affnew file mode 100644index 00000000000..caea726ca95--- /dev/null+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/twofold.aff@@ -0,0 +1,7 @@+SET UTF-8++SFX Y Y 1+SFX Y 0 s . +PLUR++SFX X Y 1+SFX X 0 able/Y . +ABLE