Changeset View
Changeset View
Standalone View
Standalone View
autotests/unit/engine/termgeneratortest.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 35 | private Q_SLOTS: | |||
---|---|---|---|---|---|
49 | } | 49 | } | ||
50 | }; | 50 | }; | ||
51 | 51 | | |||
52 | void TermGeneratorTest::testWordBoundaries() | 52 | void TermGeneratorTest::testWordBoundaries() | ||
53 | { | 53 | { | ||
54 | QString str = QString::fromLatin1("The quick (\"brown\") 'fox' can't jump 32.3 feet, right? No-Wrong;xx.txt"); | 54 | QString str = QString::fromLatin1("The quick (\"brown\") 'fox' can't jump 32.3 feet, right? No-Wrong;xx.txt"); | ||
55 | 55 | | |||
56 | Document doc; | 56 | Document doc; | ||
57 | TermGenerator termGen(&doc); | 57 | TermGenerator termGen(doc); | ||
58 | termGen.indexText(str); | 58 | termGen.indexText(str); | ||
59 | 59 | | |||
60 | QList<QByteArray> words = allWords(doc); | 60 | QList<QByteArray> words = allWords(doc); | ||
61 | 61 | | |||
62 | QList<QByteArray> expectedWords; | 62 | QList<QByteArray> expectedWords; | ||
63 | expectedWords << QByteArray("32.3") << QByteArray("brown") << QByteArray("can't") << QByteArray("feet") << QByteArray("fox") << QByteArray("jump") | 63 | expectedWords << QByteArray("32.3") << QByteArray("brown") << QByteArray("can't") << QByteArray("feet") << QByteArray("fox") << QByteArray("jump") | ||
64 | << QByteArray("no") << QByteArray("quick") << QByteArray("right") << QByteArray("the") << QByteArray("txt") << QByteArray("wrong") | 64 | << QByteArray("no") << QByteArray("quick") << QByteArray("right") << QByteArray("the") << QByteArray("txt") << QByteArray("wrong") | ||
65 | << QByteArray("xx"); | 65 | << QByteArray("xx"); | ||
66 | 66 | | |||
67 | QCOMPARE(words, expectedWords); | 67 | QCOMPARE(words, expectedWords); | ||
68 | } | 68 | } | ||
69 | 69 | | |||
70 | void TermGeneratorTest::testUnderscoreWord() | 70 | void TermGeneratorTest::testUnderscoreWord() | ||
71 | { | 71 | { | ||
72 | QString str = QString::fromLatin1("_plant"); | 72 | QString str = QString::fromLatin1("_plant"); | ||
73 | 73 | | |||
74 | Document doc; | 74 | Document doc; | ||
75 | TermGenerator termGen(&doc); | 75 | TermGenerator termGen(doc); | ||
76 | termGen.indexText(str); | 76 | termGen.indexText(str); | ||
77 | 77 | | |||
78 | QList<QByteArray> words = allWords(doc); | 78 | QList<QByteArray> words = allWords(doc); | ||
79 | 79 | | |||
80 | QList<QByteArray> expectedWords; | 80 | QList<QByteArray> expectedWords; | ||
81 | expectedWords << QByteArray("plant"); | 81 | expectedWords << QByteArray("plant"); | ||
82 | 82 | | |||
83 | QCOMPARE(words, expectedWords); | 83 | QCOMPARE(words, expectedWords); | ||
84 | } | 84 | } | ||
85 | 85 | | |||
86 | void TermGeneratorTest::testUnderscore_splitting() | 86 | void TermGeneratorTest::testUnderscore_splitting() | ||
87 | { | 87 | { | ||
88 | QString str = QString::fromLatin1("Hello_Howdy"); | 88 | QString str = QString::fromLatin1("Hello_Howdy"); | ||
89 | 89 | | |||
90 | Document doc; | 90 | Document doc; | ||
91 | TermGenerator termGen(&doc); | 91 | TermGenerator termGen(doc); | ||
92 | termGen.indexText(str); | 92 | termGen.indexText(str); | ||
93 | 93 | | |||
94 | QList<QByteArray> words = allWords(doc); | 94 | QList<QByteArray> words = allWords(doc); | ||
95 | 95 | | |||
96 | QList<QByteArray> expectedWords; | 96 | QList<QByteArray> expectedWords; | ||
97 | expectedWords << QByteArray("hello") << QByteArray("howdy"); | 97 | expectedWords << QByteArray("hello") << QByteArray("howdy"); | ||
98 | 98 | | |||
99 | QCOMPARE(words, expectedWords); | 99 | QCOMPARE(words, expectedWords); | ||
100 | } | 100 | } | ||
101 | 101 | | |||
102 | void TermGeneratorTest::testAccentCharacters() | 102 | void TermGeneratorTest::testAccentCharacters() | ||
103 | { | 103 | { | ||
104 | QString str = QString::fromUtf8("Como est\xC3\xA1 K\xC3\xBBg"); // "Como está Kûg" | 104 | QString str = QString::fromUtf8("Como est\xC3\xA1 K\xC3\xBBg"); // "Como está Kûg" | ||
105 | 105 | | |||
106 | Document doc; | 106 | Document doc; | ||
107 | TermGenerator termGen(&doc); | 107 | TermGenerator termGen(doc); | ||
108 | termGen.indexText(str); | 108 | termGen.indexText(str); | ||
109 | 109 | | |||
110 | QList<QByteArray> words = allWords(doc); | 110 | QList<QByteArray> words = allWords(doc); | ||
111 | 111 | | |||
112 | QList<QByteArray> expectedWords; | 112 | QList<QByteArray> expectedWords; | ||
113 | expectedWords << QByteArray("como") << QByteArray("esta") << QByteArray("kug"); | 113 | expectedWords << QByteArray("como") << QByteArray("esta") << QByteArray("kug"); | ||
114 | 114 | | |||
115 | QCOMPARE(words, expectedWords); | 115 | QCOMPARE(words, expectedWords); | ||
116 | } | 116 | } | ||
117 | 117 | | |||
118 | void TermGeneratorTest::testUnicodeCompatibleComposition() | 118 | void TermGeneratorTest::testUnicodeCompatibleComposition() | ||
119 | { | 119 | { | ||
120 | // The 0xfb00 corresponds to U+FB00 which is a 'ff' ligature | 120 | // The 0xfb00 corresponds to U+FB00 which is a 'ff' ligature | ||
121 | QString str = QLatin1Literal("maffab"); | 121 | QString str = QLatin1Literal("maffab"); | ||
122 | QString str2 = QLatin1Literal("ma") + QChar(0xfb00) + QStringLiteral("ab"); | 122 | QString str2 = QLatin1Literal("ma") + QChar(0xfb00) + QStringLiteral("ab"); | ||
123 | 123 | | |||
124 | Document doc; | 124 | Document doc; | ||
125 | TermGenerator termGen(&doc); | 125 | TermGenerator termGen(doc); | ||
126 | termGen.indexText(str2); | 126 | termGen.indexText(str2); | ||
127 | 127 | | |||
128 | QList<QByteArray> words = allWords(doc); | 128 | QList<QByteArray> words = allWords(doc); | ||
129 | QCOMPARE(words.size(), 1); | 129 | QCOMPARE(words.size(), 1); | ||
130 | 130 | | |||
131 | QByteArray output = words.first(); | 131 | QByteArray output = words.first(); | ||
132 | QCOMPARE(str.toUtf8(), output); | 132 | QCOMPARE(str.toUtf8(), output); | ||
133 | } | 133 | } | ||
134 | 134 | | |||
135 | void TermGeneratorTest::testUnicodeLowering() | 135 | void TermGeneratorTest::testUnicodeLowering() | ||
136 | { | 136 | { | ||
137 | // This string is unicode mathematical italic "Hedge" | 137 | // This string is unicode mathematical italic "Hedge" | ||
138 | QString str = QString::fromUtf8("\xF0\x9D\x90\xBB\xF0\x9D\x91\x92\xF0\x9D\x91\x91\xF0\x9D\x91\x94\xF0\x9D\x91\x92"); | 138 | QString str = QString::fromUtf8("\xF0\x9D\x90\xBB\xF0\x9D\x91\x92\xF0\x9D\x91\x91\xF0\x9D\x91\x94\xF0\x9D\x91\x92"); | ||
139 | 139 | | |||
140 | Document doc; | 140 | Document doc; | ||
141 | TermGenerator termGen(&doc); | 141 | TermGenerator termGen(doc); | ||
142 | termGen.indexText(str); | 142 | termGen.indexText(str); | ||
143 | 143 | | |||
144 | QList<QByteArray> words = allWords(doc); | 144 | QList<QByteArray> words = allWords(doc); | ||
145 | 145 | | |||
146 | QCOMPARE(words, {QByteArray("hedge")}); | 146 | QCOMPARE(words, {QByteArray("hedge")}); | ||
147 | } | 147 | } | ||
148 | 148 | | |||
149 | void TermGeneratorTest::testEmails() | 149 | void TermGeneratorTest::testEmails() | ||
150 | { | 150 | { | ||
151 | QString str = QString::fromLatin1("me@vhanda.in"); | 151 | QString str = QString::fromLatin1("me@vhanda.in"); | ||
152 | 152 | | |||
153 | Document doc; | 153 | Document doc; | ||
154 | TermGenerator termGen(&doc); | 154 | TermGenerator termGen(doc); | ||
155 | termGen.indexText(str); | 155 | termGen.indexText(str); | ||
156 | 156 | | |||
157 | QList<QByteArray> words = allWords(doc); | 157 | QList<QByteArray> words = allWords(doc); | ||
158 | 158 | | |||
159 | QList<QByteArray> expectedWords; | 159 | QList<QByteArray> expectedWords; | ||
160 | expectedWords << QByteArray("in") << QByteArray("me") << QByteArray("vhanda"); | 160 | expectedWords << QByteArray("in") << QByteArray("me") << QByteArray("vhanda"); | ||
161 | 161 | | |||
162 | QCOMPARE(words, expectedWords); | 162 | QCOMPARE(words, expectedWords); | ||
163 | } | 163 | } | ||
164 | 164 | | |||
165 | void TermGeneratorTest::testWordPositions() | 165 | void TermGeneratorTest::testWordPositions() | ||
166 | { | 166 | { | ||
167 | Document doc; | 167 | Document doc; | ||
168 | TermGenerator termGen(&doc); | 168 | TermGenerator termGen(doc); | ||
169 | 169 | | |||
170 | QString str = QString::fromLatin1("Hello hi how hi"); | 170 | QString str = QString::fromLatin1("Hello hi how hi"); | ||
171 | termGen.indexText(str); | 171 | termGen.indexText(str); | ||
172 | 172 | | |||
173 | QList<QByteArray> words = allWords(doc); | 173 | QList<QByteArray> words = allWords(doc); | ||
174 | 174 | | |||
175 | QList<QByteArray> expectedWords; | 175 | QList<QByteArray> expectedWords; | ||
176 | expectedWords << QByteArray("hello") << QByteArray("hi") << QByteArray("how"); | 176 | expectedWords << QByteArray("hello") << QByteArray("hi") << QByteArray("how"); | ||
Show All 35 Lines |