File indexing completed on 2025-01-05 05:19:42
0001 /* 0002 SPDX-FileCopyrightText: 2023 Waqar Ahmed <waqar.17a@gmail.com> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 #include "test_formatapply.h" 0006 0007 #include "FormatApply.h" 0008 #include <KTextEditor/Editor> 0009 0010 #include <QTest> 0011 0012 QTEST_MAIN(FormatApplyTest) 0013 0014 void FormatApplyTest::testFormatApply() 0015 { 0016 const char patch[] = 0017 R"(diff --git a/home/waqar/kde/src/utilities/kate/build/m.cpp b/tmp/kate.ypQGnu 0018 index dc6e4c4df..03f3d79d9 100644 0019 --- a/home/waqar/kde/src/utilities/kate/build/m.cpp 0020 +++ b/tmp/kate.ypQGnu 0021 @@ -1,4 +1,5 @@ 0022 #include <cstdio> 0023 -int main(){ 0024 +int main() 0025 +{ 0026 puts("hello"); 0027 } 0028 )"; 0029 0030 auto editor = KTextEditor::Editor::instance(); 0031 auto doc = editor->createDocument(this); 0032 const char unformatted[] = 0033 R"(#include <cstdio> 0034 int main(){ 0035 puts("hello"); 0036 })"; 0037 0038 doc->setText(QString::fromUtf8(unformatted)); 0039 const auto edits = parseDiff(doc, QString::fromUtf8(patch)); 0040 QVERIFY(!edits.empty()); 0041 0042 applyPatch(doc, edits); 0043 0044 const QString formatted = QStringLiteral( 0045 R"(#include <cstdio> 0046 int main() 0047 { 0048 puts("hello"); 0049 })"); 0050 QCOMPARE(doc->text(), formatted); 0051 } 0052 0053 #include "moc_test_formatapply.cpp"