213ec2c66a391b834a371a3581bd0e0255c642fe
1 #include "TestParseDiff.h"
3 #include "hunks/ChangeSet.h"
5 void TestParseDiff::testBasis()
7 const char *diff
= "diff --git a/FOO b/FOO\n"
8 "new file mode 100644\n"
9 "index 0000000..94a9ed0\n"
14 "diff --git a/BAR b/BAR\n"
15 "deleted file mode 100644\n"
16 "index 94a9ed0..0000000\n"
22 "diff --git a/todo b/todo\n"
23 "index a4c7321..a0417af 100644\n"
26 "@@ -4,8 +4,6 @@ Commands still missing completely;\n"
27 " setpref Set a value for a preference (test, predist, ...).\n"
28 " rollback Record an inverse patch without changing the working directory.\n"
29 " annotate Display which patch last modified something.\n"
30 "- trackdown Locate the most recent version lacking an error.\n"
31 "- query Query information which is stored by vng.\n"
32 " unpull Opposite of pull; unsafe if patch is not in remote repository.\n"
33 " obliterate Delete selected patches from the repository. (UNSAFE!)\n"
34 " send Send by email a bundle of one or more patches.\n";
36 QByteArray
bytes(diff
);
37 QBuffer
buffer(&bytes
, 0);
38 buffer
.open(QBuffer::ReadOnly
);
39 QList
<File
> answer
= ChangeSet::readGitDiff(buffer
);
40 QCOMPARE(answer
.count(), 3);
42 File file1
= answer
[0];
43 QVERIFY(file1
.oldFileName().isEmpty());
44 QCOMPARE(file1
.fileName(), QByteArray("FOO"));
45 QCOMPARE(file1
.sha1(), QString("94a9ed0"));
46 QCOMPARE(file1
.oldSha1(), QString("0000000"));
47 QCOMPARE(file1
.protection(), QString("100644"));
48 QCOMPARE(file1
.hunks().count(), 1);
50 File file2
= answer
[1];
51 QVERIFY(file2
.fileName().isEmpty());
52 QCOMPARE(file2
.oldFileName(), QByteArray("BAR"));
53 QCOMPARE(file2
.oldSha1(), QString("94a9ed0"));
54 QCOMPARE(file2
.sha1(), QString("0000000"));
55 QCOMPARE(file2
.protection(), QString("100644"));
56 QCOMPARE(file2
.hunks().count(), 1);
58 File file3
= answer
[2];
59 QCOMPARE(file3
.fileName(), QByteArray("todo"));
60 QCOMPARE(file3
.oldFileName(), QByteArray("todo"));
61 QCOMPARE(file3
.oldSha1(), QString("a4c7321"));
62 QCOMPARE(file3
.sha1(), QString("a0417af"));
63 QCOMPARE(file3
.protection(), QString("100644"));
64 QCOMPARE(file3
.hunks().count(), 1);
67 QTEST_MAIN(TestParseDiff
)