Document xapian-compact --blocksize takes an argument
[xapian.git] / xapian-core / tests / api_stem.cc
blob50e8aea7c5b2aac8cecd6fd28b0cfd6da0465653
1 /** @file api_stem.cc
2 * @brief Test the stemming API
3 */
4 /* Copyright (C) 2010,2012 Olly Betts
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <config.h>
23 #include "api_stem.h"
25 #include <xapian.h>
27 #include "apitest.h"
28 #include "testsuite.h"
29 #include "testutils.h"
31 using namespace std;
33 class MyStemImpl : public Xapian::StemImplementation {
34 string operator()(const string & word) {
35 return word.substr(0, 3);
38 string get_description() const {
39 return "MyStem()";
43 /// Test user stemming algorithms.
44 DEFINE_TESTCASE(stem1, !backend) {
45 Xapian::Stem st(new MyStemImpl);
47 TEST_EQUAL(st.get_description(), "Xapian::Stem(MyStem())");
48 TEST_EQUAL(st("a"), "a");
49 TEST_EQUAL(st("foo"), "foo");
50 TEST_EQUAL(st("food"), "foo");
52 return true;
55 /// New feature in 1.0.21/1.2.1 - "nb" and "nn" select the Norwegian stemmer.
56 DEFINE_TESTCASE(stem2, !backend) {
57 Xapian::Stem st_norwegian("norwegian");
58 TEST_EQUAL(st_norwegian.get_description(),
59 Xapian::Stem("nb").get_description());
60 TEST_EQUAL(st_norwegian.get_description(),
61 Xapian::Stem("nn").get_description());
62 TEST_EQUAL(st_norwegian.get_description(),
63 Xapian::Stem("no").get_description());
64 TEST_NOT_EQUAL(st_norwegian.get_description(),
65 Xapian::Stem("en").get_description());
66 TEST_NOT_EQUAL(st_norwegian.get_description(),
67 Xapian::Stem("none").get_description());
68 return true;
71 /// Test add a stemmer test
72 DEFINE_TESTCASE(stem3, !backend) {
73 Xapian::Stem earlyenglish("earlyenglish");
74 TEST_EQUAL(earlyenglish("loved"), "love");
75 TEST_EQUAL(earlyenglish("loving"), "love");
76 TEST_EQUAL(earlyenglish("loveth"), "love");
77 TEST_EQUAL(earlyenglish("givest"), "give");
78 return true;
81 /// Test invalid language names with various characters in.
82 DEFINE_TESTCASE(stemlangs2, !backend) {
83 string lang("xdummy");
84 for (unsigned ch = 0; ch <= 255; ++ch) {
85 lang[0] = ch;
86 TEST_EXCEPTION(Xapian::InvalidArgumentError, Xapian::Stem stem(lang));
88 return true;