| 55 | } |
| 56 | |
| 57 | void TestVcsDiff::testSubDiff() |
| 58 | { |
| 59 | /************************** |
| 60 | * Test a real world diff * |
| 61 | **************************/ |
| 62 | VcsDiff diff; |
| 63 | diff.setDiff(sampleDiff); |
| 64 | QString expected(R"diff(--- a/kdevplatform/vcs/vcsdiff.cpp |
| 65 | +++ b/kdevplatform/vcs/vcsdiff.cpp |
| 66 | @@ -39,7 +39,7 @@ public: |
| 67 | , oldCount |
| 68 | , newStart |
| 69 | , newCount |
| 70 | - , firstLineIdx |
| 71 | + , firstLineIdx /**< The 0-based line number (in the whole diff) of the hunk header line (the one starting with `@@`) */ |
| 72 | ; |
| 73 | QString srcFile /**< The source filename */ |
| 74 | , tgtFile /**< The target filename */ |
| 75 | )diff"); |
| 76 | const auto subHunkDiffs = { |
| 77 | diff.subDiffHunk(15), |
| 78 | }; |
| 79 | for(auto df: subHunkDiffs) { |
| 80 | QVERIFY(df.fileNames().count()>0); |
| 81 | QCOMPARE(df.fileNames().front().source, "kdevplatform/vcs/vcsdiff.cpp"); |
| 82 | QCOMPARE(df.diff(), expected); |
| 83 | } |
| 84 | |
| 85 | VcsDiff subHunkDiff = diff.subDiff(15, 50); |
| 86 | QVERIFY(subHunkDiff.fileNames().count()>0); |
| 87 | QCOMPARE(subHunkDiff.fileNames().front().source, "kdevplatform/vcs/vcsdiff.cpp"); |
| 88 | |
| 89 | /********************************* |
| 90 | * Test start offset computation * |
| 91 | *********************************/ |
| 92 | VcsDiff skipDiff; |
| 93 | skipDiff.setDiff(R"diff(--- a/skip |
| 94 | +++ b/skip |
| 95 | @@ -1,2 +3,2 @@ heading |
| 96 | + increase offset |
| 97 | |
| 98 | + dont increase offset |
| 99 | - deletion |
| 100 | - second deletion |
| 101 | )diff"); |
| 102 | expected = QStringLiteral(R"diff(--- a/skip |
| 103 | +++ b/skip |
| 104 | @@ -2,3 +4,2 @@ heading |
| 105 | |
| 106 | - deletion |
| 107 | second deletion |
| 108 | )diff"); |
| 109 | auto subDiff = skipDiff.subDiff(6,6); |
| 110 | QCOMPARE(subDiff.diff(), expected); |
| 111 | |
| 112 | } |
| 113 | |
| 114 | void TestVcsDiff::testConflicts() |