diff --git a/xapian/autotests/termgeneratortest.cpp b/xapian/autotests/termgeneratortest.cpp index 786759e..bbf7649 100644 --- a/xapian/autotests/termgeneratortest.cpp +++ b/xapian/autotests/termgeneratortest.cpp @@ -1,167 +1,167 @@ /* * * Copyright (C) 2014 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "termgeneratortest.h" #include "../xapiantermgenerator.h" #include "../xapiandatabase.h" #include #include "akonadi_search_xapian_debug.h" #include using namespace Akonadi::Search; namespace { QStringList allWords(const Xapian::Document &doc) { QStringList words; for (auto it = doc.termlist_begin(); it != doc.termlist_end(); it++) { std::string str = *it; words << QString::fromUtf8(str.c_str(), str.length()); } return words; } } void TermGeneratorTest::testWordBoundaries() { QString str = QStringLiteral("The quick (\"brown\") 'fox' can't jump 32.3 feet, right? No-Wrong;xx.txt"); Xapian::Document doc; XapianTermGenerator termGen(&doc); termGen.indexText(str); QStringList words = allWords(doc); QStringList expectedWords; expectedWords << QStringLiteral("32.3") << QStringLiteral("brown") << QStringLiteral("can't") << QStringLiteral("feet") << QStringLiteral("fox") << QStringLiteral("jump") << QStringLiteral("no") << QStringLiteral("quick") << QStringLiteral("right") << QStringLiteral("the") << QStringLiteral("txt") << QStringLiteral("wrong") << QStringLiteral("xx"); QCOMPARE(words, expectedWords); } void TermGeneratorTest::testUnderscore_splitting() { QString str = QStringLiteral("Hello_Howdy"); Xapian::Document doc; XapianTermGenerator termGen(&doc); termGen.indexText(str); QStringList words = allWords(doc); QStringList expectedWords; expectedWords << QStringLiteral("hello") << QStringLiteral("howdy"); QCOMPARE(words, expectedWords); } void TermGeneratorTest::testAccetCharacters() { QString str = QString::fromLatin1("Como estį Kūg"); Xapian::Document doc; XapianTermGenerator termGen(&doc); termGen.indexText(str); QStringList words = allWords(doc); QStringList expectedWords; expectedWords << QStringLiteral("como") << QStringLiteral("esta") << QStringLiteral("kug"); QCOMPARE(words, expectedWords); } void TermGeneratorTest::testUnicodeCompatibleComposition() { // The 0xfb00 corresponds to U+FB00 which is a 'ff' QString str = QStringLiteral("maffab"); - QString str2 = QLatin1Literal("ma") + QChar(0xfb00) + QStringLiteral("ab"); + QString str2 = QLatin1String("ma") + QChar(0xfb00) + QStringLiteral("ab"); Xapian::Document doc; XapianTermGenerator termGen(&doc); termGen.indexText(str2); QStringList words = allWords(doc); QCOMPARE(words.size(), 1); QString output = words.first(); QCOMPARE(str, output); } void TermGeneratorTest::testEmails() { QString str = QStringLiteral("me@vhanda.in"); Xapian::Document doc; XapianTermGenerator termGen(&doc); termGen.indexText(str); QStringList words = allWords(doc); QStringList expectedWords; expectedWords << QStringLiteral("in") << QStringLiteral("me") << QStringLiteral("vhanda"); QCOMPARE(words, expectedWords); } void TermGeneratorTest::testWordPositions() { QTemporaryDir dir; XapianDatabase db(dir.path(), true); Xapian::Document doc; XapianTermGenerator termGen(&doc); QString str = QStringLiteral("Hello hi how hi"); termGen.indexText(str); db.replaceDocument(1, doc); Xapian::Database *xap = db.db(); Xapian::PositionIterator it = xap->positionlist_begin(1, "hello"); Xapian::PositionIterator end = xap->positionlist_end(1, "hello"); QVERIFY(it != end); QCOMPARE(*it, (uint)1); it++; QVERIFY(it == end); it = xap->positionlist_begin(1, "hi"); end = xap->positionlist_end(1, "hi"); QVERIFY(it != end); QCOMPARE(*it, (uint)2); it++; QCOMPARE(*it, (uint)4); it++; QVERIFY(it == end); it = xap->positionlist_begin(1, "how"); end = xap->positionlist_end(1, "how"); QVERIFY(it != end); QCOMPARE(*it, (uint)3); it++; QVERIFY(it == end); } QTEST_MAIN(TermGeneratorTest)