Skip to content

Commit 50712bf

Browse files
committed
Added diff walk end test
1 parent edae9e0 commit 50712bf

1 file changed

Lines changed: 37 additions & 17 deletions

File tree

test/convenience-difflist.js

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,54 @@ exports.method = function(test){
3939
*
4040
* @param {Object} test
4141
*/
42-
exports.walking = function(test) {
43-
test.expect(16);
42+
exports.walkingDiffs = function(test) {
43+
test.expect(15);
4444
git.repo('../.git', function(error, repository) {
4545
repository.commit(historyCountKnownSHA, function(error, commit) {
4646
commit.parents(function(error, parents) {
47-
test.equals(parents.length, 1, 'Commit should have exactly one parent');
4847
parents[0].sha(function(error, parentSha) {
4948
(new git.diffList(commit.rawRepo)).treeToTree(parentSha, historyCountKnownSHA, function(error, diffList) {
5049
test.equal(null, error, 'Should not error');
51-
diffList.walk().on('file', function(error, diff) {
50+
diffList.walk().on('delta', function(error, delta) {
51+
console.log(delta.content[0].range);
52+
process.exit();
5253
test.equal(null, error, 'Should not error');
53-
test.equal(diff.oldFile.path, 'README.md', 'Old file path should match expected');
54-
test.equal(diff.newFile.path, 'README.md', 'New file path should match expected');
55-
test.equal(diff.content.length, 5, 'Content array should be of known length');
56-
test.equal(diff.status, diffList.deltaTypes.GIT_DELTA_MODIFIED, 'Status should be known type');
57-
test.equal(diff.content[0].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'First content item should be context');
58-
test.equal(diff.content[1].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'Second content item should be context');
59-
test.equal(diff.content[2].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'Third content item should be context');
54+
test.equal(delta.oldFile.path, 'README.md', 'Old file path should match expected');
55+
test.equal(delta.newFile.path, 'README.md', 'New file path should match expected');
56+
test.equal(delta.content.length, 5, 'Content array should be of known length');
57+
test.equal(delta.status, diffList.deltaTypes.GIT_DELTA_MODIFIED, 'Status should be known type');
58+
test.equal(delta.content[0].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'First content item should be context');
59+
test.equal(delta.content[1].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'Second content item should be context');
60+
test.equal(delta.content[2].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'Third content item should be context');
6061

6162
var oldContent = '__Before submitting a pull request, please ensure both unit tests and lint checks pass.__\n';
62-
test.equal(diff.content[3].content, oldContent, 'Old content should match known value');
63-
test.equal(diff.content[3].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_DELETION, 'Fourth content item should be deletion');
64-
test.equal(diff.content[3].contentLength, 90, 'Fourth content length should match known value');
63+
test.equal(delta.content[3].content, oldContent, 'Old content should match known value');
64+
test.equal(delta.content[3].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_DELETION, 'Fourth content item should be deletion');
65+
test.equal(delta.content[3].contentLength, 90, 'Fourth content length should match known value');
6566

6667
var newContent = '__Before submitting a pull request, please ensure both that you\'ve added unit tests to cover your shiny new code, and that all unit tests and lint checks pass.__\n';
67-
test.equal(diff.content[4].content, newContent, 'New content should match known value');
68-
test.equal(diff.content[4].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_ADDITION, 'Fifth content item should be addition');
69-
test.equal(diff.content[4].contentLength, 162, 'Fifth content length should match known value');
68+
test.equal(delta.content[4].content, newContent, 'New content should match known value');
69+
test.equal(delta.content[4].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_ADDITION, 'Fifth content item should be addition');
70+
test.equal(delta.content[4].contentLength, 162, 'Fifth content length should match known value');
71+
test.done();
72+
});
73+
});
74+
});
75+
});
76+
});
77+
});
78+
};
79+
80+
exports.walkingEnd = function(test) {
81+
test.expect(2);
82+
git.repo('../.git', function(error, repository) {
83+
repository.commit(historyCountKnownSHA, function(error, commit) {
84+
commit.parents(function(error, parents) {
85+
parents[0].sha(function(error, parentSha) {
86+
(new git.diffList(commit.rawRepo)).treeToTree(parentSha, historyCountKnownSHA, function(error, diffList) {
87+
diffList.walk().on('end', function(error, diffs) {
88+
test.equal(null, error, 'Should not error');
89+
test.equal(diffs.length, 1, 'Diffs array should be of known length');
7090
test.done();
7191
});
7292
});

0 commit comments

Comments
 (0)