Changeset View
Changeset View
Standalone View
Standalone View
autotests/src/variable_test.cpp
Show All 20 Lines | |||||
21 | #include "moc_variable_test.cpp" | 21 | #include "moc_variable_test.cpp" | ||
22 | 22 | | |||
23 | #include <kateglobal.h> | 23 | #include <kateglobal.h> | ||
24 | #include <ktexteditor/editor.h> | 24 | #include <ktexteditor/editor.h> | ||
25 | #include <ktexteditor/document.h> | 25 | #include <ktexteditor/document.h> | ||
26 | #include <ktexteditor/view.h> | 26 | #include <ktexteditor/view.h> | ||
27 | 27 | | |||
28 | #include <QtTest> | 28 | #include <QtTest> | ||
29 | #include <QUuid> | ||||
29 | 30 | | |||
30 | using namespace KTextEditor; | 31 | using namespace KTextEditor; | ||
31 | 32 | | |||
32 | QTEST_MAIN(VariableTest) | 33 | QTEST_MAIN(VariableTest) | ||
33 | 34 | | |||
34 | VariableTest::VariableTest() | 35 | VariableTest::VariableTest() | ||
35 | : QObject() | 36 | : QObject() | ||
36 | { | 37 | { | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | 143 | { | |||
156 | QString output; | 157 | QString output; | ||
157 | editor->expandText(QStringLiteral("Hello %{Doc:%{Doc:Text}}!"), view, output); | 158 | editor->expandText(QStringLiteral("Hello %{Doc:%{Doc:Text}}!"), view, output); | ||
158 | QCOMPARE(output, QStringLiteral("Hello Text!")); | 159 | QCOMPARE(output, QStringLiteral("Hello Text!")); | ||
159 | 160 | | |||
160 | QVERIFY(editor->unregisterVariableMatch(name)); | 161 | QVERIFY(editor->unregisterVariableMatch(name)); | ||
161 | delete doc; | 162 | delete doc; | ||
162 | } | 163 | } | ||
163 | 164 | | |||
165 | void VariableTest::testBuiltins() | ||||
166 | { | ||||
167 | auto editor = KTextEditor::Editor::instance(); | ||||
168 | auto doc = editor->createDocument(nullptr); | ||||
169 | doc->openUrl(QUrl::fromLocalFile(QDir::homePath() + QStringLiteral("/kate-v5.tar.gz"))); | ||||
170 | doc->setText(QStringLiteral("get an edge in editing\n:-)")); | ||||
171 | auto view = doc->createView(nullptr); | ||||
172 | view->setCursorPosition(KTextEditor::Cursor(1, 2)); | ||||
173 | view->show(); | ||||
174 | | ||||
175 | QString out; | ||||
176 | | ||||
177 | // CurrentDocument:FileBaseName | ||||
178 | editor->expandText(QStringLiteral("%{CurrentDocument:FileBaseName}"), view, out); | ||||
179 | QCOMPARE(out, QStringLiteral("kate-v5")); | ||||
180 | | ||||
181 | // CurrentDocument:FileExtension | ||||
182 | editor->expandText(QStringLiteral("%{CurrentDocument:FileExtension}"), view, out); | ||||
183 | QCOMPARE(out, QStringLiteral("tar.gz")); | ||||
184 | | ||||
185 | // CurrentDocument:FileName | ||||
186 | editor->expandText(QStringLiteral("%{CurrentDocument:FileName}"), view, out); | ||||
187 | QCOMPARE(out, QStringLiteral("kate-v5.tar.gz")); | ||||
188 | | ||||
189 | // CurrentDocument:FilePath | ||||
190 | editor->expandText(QStringLiteral("%{CurrentDocument:FilePath}"), view, out); | ||||
191 | QCOMPARE(out, QFileInfo(view->document()->url().toLocalFile()).absoluteFilePath()); | ||||
192 | | ||||
193 | // CurrentDocument:Text | ||||
194 | editor->expandText(QStringLiteral("%{CurrentDocument:Text}"), view, out); | ||||
195 | QCOMPARE(out, QStringLiteral("get an edge in editing\n:-)")); | ||||
196 | | ||||
197 | // CurrentDocument:Path | ||||
198 | editor->expandText(QStringLiteral("%{CurrentDocument:Path}"), view, out); | ||||
199 | QCOMPARE(out, QFileInfo(doc->url().toLocalFile()).absolutePath()); | ||||
200 | | ||||
201 | // CurrentDocument:NativeFilePath | ||||
202 | editor->expandText(QStringLiteral("%{CurrentDocument:NativeFilePath}"), view, out); | ||||
203 | QCOMPARE(out, QDir::toNativeSeparators(QFileInfo(doc->url().toLocalFile()).absoluteFilePath())); | ||||
204 | | ||||
205 | // CurrentDocument:NativePath | ||||
206 | editor->expandText(QStringLiteral("%{CurrentDocument:NativePath}"), view, out); | ||||
207 | QCOMPARE(out, QDir::toNativeSeparators(QFileInfo(doc->url().toLocalFile()).absolutePath())); | ||||
208 | | ||||
209 | // CurrentDocument:NativePath | ||||
210 | editor->expandText(QStringLiteral("%{CurrentDocument:NativePath}"), view, out); | ||||
211 | QCOMPARE(out, QDir::toNativeSeparators(QFileInfo(doc->url().toLocalFile()).absolutePath())); | ||||
212 | | ||||
213 | // CurrentDocument:Cursor:Line | ||||
214 | editor->expandText(QStringLiteral("%{CurrentDocument:Cursor:Line}"), view, out); | ||||
215 | QCOMPARE(out, QStringLiteral("1")); | ||||
216 | | ||||
217 | // CurrentDocument:Cursor:Column | ||||
218 | editor->expandText(QStringLiteral("%{CurrentDocument:Cursor:Column}"), view, out); | ||||
219 | QCOMPARE(out, QStringLiteral("2")); | ||||
220 | | ||||
221 | // CurrentDocument:Cursor:XPos | ||||
222 | editor->expandText(QStringLiteral("%{CurrentDocument:Cursor:XPos}"), view, out); | ||||
223 | QVERIFY(out.toInt() > 0); | ||||
224 | | ||||
225 | // CurrentDocument:Cursor:YPos | ||||
226 | editor->expandText(QStringLiteral("%{CurrentDocument:Cursor:YPos}"), view, out); | ||||
227 | QVERIFY(out.toInt() > 0); | ||||
228 | | ||||
229 | | ||||
230 | view->setSelection(KTextEditor::Range(1, 0, 1, 3)); | ||||
231 | // CurrentDocument:Selection:Text | ||||
232 | editor->expandText(QStringLiteral("%{CurrentDocument:Selection:Text}"), view, out); | ||||
233 | QCOMPARE(out, QStringLiteral(":-)")); | ||||
234 | | ||||
235 | // CurrentDocument:Selection:StartLine | ||||
236 | editor->expandText(QStringLiteral("%{CurrentDocument:Selection:StartLine}"), view, out); | ||||
237 | QCOMPARE(out, QStringLiteral("1")); | ||||
238 | | ||||
239 | // CurrentDocument:Selection:StartColumn | ||||
240 | editor->expandText(QStringLiteral("%{CurrentDocument:Selection:StartColumn}"), view, out); | ||||
241 | QCOMPARE(out, QStringLiteral("0")); | ||||
242 | | ||||
243 | // CurrentDocument:Selection:EndLine | ||||
244 | editor->expandText(QStringLiteral("%{CurrentDocument:Selection:EndLine}"), view, out); | ||||
245 | QCOMPARE(out, QStringLiteral("1")); | ||||
246 | | ||||
247 | // CurrentDocument:Selection:EndColumn | ||||
248 | editor->expandText(QStringLiteral("%{CurrentDocument:Selection:EndColumn}"), view, out); | ||||
249 | QCOMPARE(out, QStringLiteral("3")); | ||||
250 | | ||||
251 | // CurrentDocument:RowCount | ||||
252 | editor->expandText(QStringLiteral("%{CurrentDocument:RowCount}"), view, out); | ||||
253 | QCOMPARE(out, QStringLiteral("2")); | ||||
254 | | ||||
255 | // Date:Locale | ||||
256 | editor->expandText(QStringLiteral("%{Date:Locale}"), view, out); | ||||
257 | QVERIFY(!out.isEmpty()); | ||||
258 | | ||||
259 | // Date:ISO | ||||
260 | editor->expandText(QStringLiteral("%{Date:ISO}"), view, out); | ||||
261 | QVERIFY(!out.isEmpty()); | ||||
262 | | ||||
263 | // Date:yyyy-MM-dd | ||||
264 | editor->expandText(QStringLiteral("%{Date:yyyy-MM-dd}"), view, out); | ||||
265 | QVERIFY(QDate::fromString(out, QStringLiteral("yyyy-MM-dd")).isValid()); | ||||
266 | | ||||
267 | // Time:Locale | ||||
268 | editor->expandText(QStringLiteral("%{Time:Locale}"), view, out); | ||||
269 | QVERIFY(!out.isEmpty()); | ||||
270 | | ||||
271 | // Time:ISO | ||||
272 | editor->expandText(QStringLiteral("%{Time:ISO}"), view, out); | ||||
273 | QVERIFY(!out.isEmpty()); | ||||
274 | | ||||
275 | // Time:hh-mm-ss | ||||
276 | editor->expandText(QStringLiteral("%{Time:hh-mm-ss}"), view, out); | ||||
277 | QVERIFY(QTime::fromString(out, QStringLiteral("hh-mm-ss")).isValid()); | ||||
278 | | ||||
279 | // ENV:HOME | ||||
280 | editor->expandText(QStringLiteral("%{ENV:HOME}"), view, out); | ||||
281 | QCOMPARE(out, QDir::homePath()); | ||||
282 | | ||||
283 | // JS:<code> | ||||
284 | editor->expandText(QStringLiteral("%{JS:3 + %{JS:2 + 1}}"), view, out); | ||||
285 | QCOMPARE(out, QStringLiteral("6")); | ||||
286 | | ||||
287 | // UUID | ||||
288 | editor->expandText(QStringLiteral("%{UUID}"), view, out); | ||||
289 | QCOMPARE(out.count(QLatin1Char('-')), 4); | ||||
290 | } | ||||
291 | | ||||
164 | // kate: indent-mode cstyle; indent-width 4; replace-tabs on; | 292 | // kate: indent-mode cstyle; indent-width 4; replace-tabs on; |