00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include "api_stem.h"
00024
00025 #include <xapian.h>
00026
00027 #include "apitest.h"
00028 #include "testsuite.h"
00029 #include "testutils.h"
00030
00031 using namespace std;
00032
00033 class MyStemImpl : public Xapian::StemImplementation {
00034 string operator()(const string & word) {
00035 return word.substr(0, 3);
00036 }
00037
00038 string get_description() const {
00039 return "MyStem()";
00040 }
00041 };
00042
00044 DEFINE_TESTCASE(stem1, !backend) {
00045 Xapian::Stem st(new MyStemImpl);
00046
00047 TEST_EQUAL(st("a"), "a");
00048 TEST_EQUAL(st("foo"), "foo");
00049 TEST_EQUAL(st("food"), "foo");
00050
00051 return true;
00052 }
00053
00055 DEFINE_TESTCASE(stem2, !backend) {
00056 Xapian::Stem st_norwegian("norwegian");
00057 TEST_EQUAL(st_norwegian.get_description(),
00058 Xapian::Stem("nb").get_description());
00059 TEST_EQUAL(st_norwegian.get_description(),
00060 Xapian::Stem("nn").get_description());
00061 TEST_EQUAL(st_norwegian.get_description(),
00062 Xapian::Stem("no").get_description());
00063 TEST_NOT_EQUAL(st_norwegian.get_description(),
00064 Xapian::Stem("en").get_description());
00065 return true;
00066 }
00067
00068
00069 DEFINE_TESTCASE(stemlangs2, !backend) {
00070 string lang("xdummy");
00071 for (unsigned ch = 0; ch <= 255; ++ch) {
00072 lang[0] = ch;
00073 TEST_EXCEPTION(Xapian::InvalidArgumentError, Xapian::Stem stem(lang));
00074 }
00075 return true;
00076 }