File indexing completed on 2024-05-05 17:51:19
0001 // clang-format off 0002 /** 0003 * KDiff3 - Text Diff And Merge Tool 0004 * 0005 * SPDX-FileCopyrightText: 2021 Michael Reeves <reeves.87@gmail.com> 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 * 0008 */ 0009 // clang-format on 0010 0011 #include "../diff.h" 0012 #include "../options.h" 0013 0014 #include <memory> 0015 0016 #include <QObject> 0017 #include <QTest> 0018 0019 std::unique_ptr<Options> gOptions = std::make_unique<Options>(); 0020 0021 class Diff3LineTest: public QObject 0022 { 0023 Q_OBJECT; 0024 private Q_SLOTS: 0025 void initTestCase() 0026 { 0027 Diff3LineList diffList; 0028 Diff3Line entry; 0029 0030 QVERIFY(diffList.empty()); 0031 QVERIFY(!entry.isEqualAB()); 0032 QVERIFY(!entry.isEqualBC()); 0033 QVERIFY(!entry.isEqualAC()); 0034 QVERIFY(!entry.isWhiteLine(e_SrcSelector::A)); 0035 QVERIFY(!entry.isWhiteLine(e_SrcSelector::B)); 0036 QVERIFY(!entry.isWhiteLine(e_SrcSelector::C)); 0037 } 0038 0039 void calcDiffTest() 0040 { 0041 Diff3LineList diff3List; 0042 /* 0043 Start with something simple. This diff list indicates one different line fallowed by three equal lines 0044 *This was generated with a two-way compare. 0045 0046 Not all functions in Diff3Line will work since there is no data actually loaded. 0047 */ 0048 DiffList diffList = {{0, 1, 1}, {3, 0, 0}}; 0049 0050 diff3List.calcDiff3LineListUsingAB(&diffList); 0051 QCOMPARE(diff3List.size(), 4); 0052 0053 Diff3LineList::const_iterator entry = diff3List.begin(); 0054 QCOMPARE(entry->getLineA(), 0); 0055 QCOMPARE(entry->getLineB(), 0); 0056 QCOMPARE(entry->getLineC(), LineRef::invalid); 0057 QVERIFY(!entry->isEqualAB()); 0058 QVERIFY(!entry->isEqualAC()); 0059 QVERIFY(!entry->isEqualBC()); 0060 ++entry; 0061 0062 QCOMPARE(entry->getLineA(), 1); 0063 QCOMPARE(entry->getLineB(), 1); 0064 QCOMPARE(entry->getLineC(), LineRef::invalid); 0065 QVERIFY(entry->isEqualAB()); 0066 QVERIFY(!entry->isEqualAC()); 0067 QVERIFY(!entry->isEqualBC()); 0068 ++entry; 0069 0070 QCOMPARE(entry->getLineA(), 2); 0071 QCOMPARE(entry->getLineB(), 2); 0072 QCOMPARE(entry->getLineC(), LineRef::invalid); 0073 QVERIFY(entry->isEqualAB()); 0074 QVERIFY(!entry->isEqualAC()); 0075 QVERIFY(!entry->isEqualBC()); 0076 ++entry; 0077 0078 QCOMPARE(entry->getLineA(), 3); 0079 QCOMPARE(entry->getLineB(), 3); 0080 QCOMPARE(entry->getLineC(), LineRef::invalid); 0081 QVERIFY(entry->isEqualAB()); 0082 QVERIFY(!entry->isEqualAC()); 0083 QVERIFY(!entry->isEqualBC()); 0084 ++entry; 0085 } 0086 }; 0087 0088 QTEST_MAIN(Diff3LineTest); 0089 0090 #include "Diff3LineTest.moc"