| 1165 | } |
| 1166 | |
| 1167 | void TestCodeCompletion::testIncludePathCompletion() |
| 1168 | { |
| 1169 | QFETCH(QString, code); |
| 1170 | QFETCH(KTextEditor::Cursor, cursor); |
| 1171 | QFETCH(QString, itemId); |
| 1172 | QFETCH(QString, result); |
| 1173 | |
| 1174 | QTemporaryDir tempDir; |
| 1175 | QDir dir(tempDir.path()); |
| 1176 | QVERIFY(dir.mkpath("foo/bar/asdf")); |
| 1177 | TestFile file(code, QStringLiteral("cpp"), nullptr, tempDir.path()); |
| 1178 | { |
| 1179 | QFile otherFile(tempDir.path() + "/dash-file.h"); |
| 1180 | QVERIFY(otherFile.open(QIODevice::WriteOnly)); |
| 1181 | } |
| 1182 | IncludeTester tester(executeIncludePathCompletion(&file, cursor)); |
| 1183 | QVERIFY(tester.completionContext); |
| 1184 | QVERIFY(tester.completionContext->isValid()); |
| 1185 | |
| 1186 | auto item = tester.findItem(itemId); |
| 1187 | QVERIFY(item); |
| 1188 | |
| 1189 | auto view = createView(file.url().toUrl()); |
| 1190 | QVERIFY(view.get()); |
| 1191 | auto doc = view->document(); |
| 1192 | item->execute(view.get(), KTextEditor::Range(cursor, cursor)); |
| 1193 | QCOMPARE(doc->text(), result); |
| 1194 | |
| 1195 | const auto newCursor = view->cursorPosition(); |
| 1196 | QCOMPARE(newCursor.line(), cursor.line()); |
| 1197 | if (!itemId.endsWith('/')) { |
| 1198 | // file inserted, cursor should be at end of line |
| 1199 | QCOMPARE(newCursor.column(), doc->lineLength(cursor.line())); |
| 1200 | } else { |
| 1201 | // directory inserted, cursor should be before the " or > |
| 1202 | const auto cursorChar = doc->characterAt(newCursor); |
| 1203 | QVERIFY(cursorChar == '"' || cursorChar == '>'); |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | void TestCodeCompletion::testIncludePathCompletionLocal() |
| 1208 | { |
nothing calls this directly
no test coverage detected