File indexing completed on 2024-05-19 04:39:59
0001 /* 0002 SPDX-FileCopyrightText: 2016 Kevin Funk <kfunk@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "test_texteditorhelpers.h" 0008 0009 #include "texteditorhelpers.h" 0010 0011 #include <QTest> 0012 #include <QStandardPaths> 0013 0014 QTEST_MAIN(TestKTextEditorHelpers) 0015 0016 using namespace KDevelop; 0017 0018 void TestKTextEditorHelpers::initTestCase() 0019 { 0020 QStandardPaths::setTestModeEnabled(true); 0021 } 0022 0023 void TestKTextEditorHelpers::testExtractCursor() 0024 { 0025 QFETCH(QString, input); 0026 QFETCH(KTextEditor::Cursor, expectedCursor); 0027 QFETCH(QString, expectedPath); 0028 0029 int pathLen; 0030 const auto cursor = KTextEditorHelpers::extractCursor(input, &pathLen); 0031 QCOMPARE(cursor, expectedCursor); 0032 QCOMPARE(input.mid(0, pathLen), expectedPath); 0033 } 0034 0035 void TestKTextEditorHelpers::testExtractCursor_data() 0036 { 0037 QTest::addColumn<QString>("input"); 0038 QTest::addColumn<KTextEditor::Cursor>("expectedCursor"); 0039 QTest::addColumn<QString>("expectedPath"); 0040 0041 // valid input 0042 QTest::newRow("file") 0043 << QStringLiteral("widget.cpp") 0044 << KTextEditor::Cursor::invalid() 0045 << QStringLiteral("widget.cpp"); 0046 QTest::newRow("file:line") 0047 << QStringLiteral("widget.cpp:12") 0048 << KTextEditor::Cursor(11, 0) 0049 << QStringLiteral("widget.cpp"); 0050 QTest::newRow("file:line:column") 0051 << QStringLiteral("widget.cpp:12:5") 0052 << KTextEditor::Cursor(11, 4) 0053 << QStringLiteral("widget.cpp"); 0054 QTest::newRow("file:line") 0055 << QStringLiteral("widget.cpp#12") 0056 << KTextEditor::Cursor(11, 0) 0057 << QStringLiteral("widget.cpp"); 0058 QTest::newRow("file:line") 0059 << QStringLiteral("widget.cpp#L12") 0060 << KTextEditor::Cursor(11, 0) 0061 << QStringLiteral("widget.cpp"); 0062 QTest::newRow("file:line") 0063 << QStringLiteral("widget.cpp#n12") 0064 << KTextEditor::Cursor(11, 0) 0065 << QStringLiteral("widget.cpp"); 0066 // partially invalid input 0067 QTest::newRow("file:") 0068 << QStringLiteral("widget.cpp:") 0069 << KTextEditor::Cursor::invalid() 0070 << QStringLiteral("widget.cpp:"); 0071 QTest::newRow("file:") 0072 << QStringLiteral("widget.cpp#") 0073 << KTextEditor::Cursor::invalid() 0074 << QStringLiteral("widget.cpp#"); 0075 QTest::newRow("file:") 0076 << QStringLiteral("widget.cpp#L") 0077 << KTextEditor::Cursor::invalid() 0078 << QStringLiteral("widget.cpp#L"); 0079 QTest::newRow("file:") 0080 << QStringLiteral("widget.cpp#n") 0081 << KTextEditor::Cursor::invalid() 0082 << QStringLiteral("widget.cpp#n"); 0083 } 0084 0085 #include "moc_test_texteditorhelpers.cpp"