File indexing completed on 2024-06-16 04:23:10

0001 /*
0002     SPDX-FileCopyrightText: 2013 Milian Wolff <mail@milianw.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "test_documentchangeset.h"
0008 
0009 #include <language/codegen/documentchangeset.h>
0010 
0011 #include <tests/testcore.h>
0012 #include <tests/autotestshell.h>
0013 #include <tests/testfile.h>
0014 #include <QTest>
0015 
0016 QTEST_GUILESS_MAIN(TestDocumentchangeset)
0017 
0018 using namespace KDevelop;
0019 
0020 void TestDocumentchangeset::initTestCase()
0021 {
0022     AutoTestShell::init();
0023     TestCore::initialize(Core::NoUi);
0024 }
0025 
0026 void TestDocumentchangeset::cleanupTestCase()
0027 {
0028     TestCore::shutdown();
0029 }
0030 
0031 void TestDocumentchangeset::testReplaceSameLine()
0032 {
0033     TestFile file(QStringLiteral("abc def ghi"), QStringLiteral("cpp"));
0034     qDebug() << file.fileContents();
0035     DocumentChangeSet changes;
0036     changes.addChange(
0037         DocumentChange(
0038             file.url(),
0039             KTextEditor::Range(0, 0, 0, 3),
0040             QStringLiteral("abc"), QStringLiteral("foobar")
0041     ));
0042     changes.addChange(
0043         DocumentChange(
0044             file.url(),
0045             KTextEditor::Range(0, 4, 0, 7),
0046             QStringLiteral("def"), QStringLiteral("foobar")
0047     ));
0048     changes.addChange(
0049         DocumentChange(
0050             file.url(),
0051             KTextEditor::Range(0, 8, 0, 11),
0052             QStringLiteral("ghi"), QStringLiteral("foobar")
0053     ));
0054 
0055     DocumentChangeSet::ChangeResult result = changes.applyAllChanges();
0056     qDebug() << result.m_failureReason << result.m_success;
0057     QVERIFY(result);
0058 }
0059 
0060 #include "moc_test_documentchangeset.cpp"