Various fixes for revert/unrevert
[vng.git] / tests / parsediff / TestParseDiff.cpp
blob133895d031a31eca553d8134f8097c20bdcbcca6
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"
10 "--- /dev/null\n"
11 "+++ b/FOO\n"
12 "@@ -0,0 +1,674 @@\n"
13 "+file content\n"
14 "diff --git a/BAR b/BAR\n"
15 "deleted file mode 100644\n"
16 "index 94a9ed0..0000000\n"
17 "--- a/BAR\n"
18 "+++ /dev/null\n"
19 "@@ -1,674 +0,0 @@\n"
20 "-file content2\n"
21 " \n"
22 "diff --git a/todo b/todo\n"
23 "index a4c7321..a0417af 100644\n"
24 "--- a/todo\n"
25 "+++ b/todo\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"
35 "--- a/README\n"
36 "+++ b/README\n"
37 "@@ -6,8 +6,6 @@ Compiling\n"
38 " To compile this project you need Qt4.4 or later, only the qt-core library is used.\n"
39 " \n"
40 " To generate a makefile call the 'qmake' command in the vng directory. Make\n"
41 "-sure you call the one from the right Qt release.\n"
42 "-Some linux distros ship this command names 'qmake-qt4'\n"
43 " \n"
44 " After calling qmake, compile the project like you would any other. This is\n"
45 " platform dependent and could be \"nmake\", \"make\" etc.\n"
46 " \n";
48 QByteArray bytes(diff);
49 QBuffer buffer(&bytes, 0);
50 buffer.open(QBuffer::ReadOnly);
51 QList<File> answer = ChangeSet::readGitDiff(buffer);
52 QCOMPARE(answer.count(), 3);
54 File file1 = answer[0];
55 QCOMPARE(file1.fileName(), QByteArray("todo"));
56 QCOMPARE(file1.oldFileName(), QByteArray("todo"));
57 QCOMPARE(file1.oldSha1(), QString("a4c7321"));
58 QCOMPARE(file1.sha1(), QString("a0417af"));
59 QCOMPARE(file1.protection(), QString("100644"));
60 QCOMPARE(file1.hunks().count(), 1);
62 File file2 = answer[1];
63 QCOMPARE(file2.oldFileName(), QByteArray("README"));
64 QCOMPARE(file2.fileName(), QByteArray("README"));
65 QCOMPARE(file2.sha1(), QString());
66 QCOMPARE(file2.oldSha1(), QString());
67 QCOMPARE(file2.protection(), QString());
68 QCOMPARE(file2.hunks().count(), 1);
70 File renamed = answer.last(); // renamed files go at the end..
71 QCOMPARE(renamed.oldFileName(), QByteArray("BAR"));
72 QCOMPARE(renamed.fileName(), QByteArray("FOO"));
73 QCOMPARE(renamed.sha1(), QString("94a9ed0"));
74 QCOMPARE(renamed.oldSha1(), QString("94a9ed0"));
75 QCOMPARE(renamed.protection(), QString("100644"));
76 QCOMPARE(renamed.hunks().count(), 1);
79 QTEST_MAIN(TestParseDiff)