Skip to content

Commit c729360

Browse files
committed
Added convenience-difflist tests
1 parent 2bb2290 commit c729360

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

test/convenience-difflist.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
var git = require('../'),
2+
rimraf = require('rimraf'),
3+
fs = require( 'fs' );
4+
5+
var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6';
6+
7+
// Helper functions
8+
var helper = {
9+
// Test if obj is a true function
10+
testFunction: function(test, obj, label) {
11+
// The object reports itself as a function
12+
test(typeof obj, 'function', label + ' reports as a function.');
13+
// This ensures the repo is actually a derivative of the Function [[Class]]
14+
test(toString.call(obj), '[object Function]', label + ' [[Class]] is of type function.');
15+
},
16+
// Test code and handle exception thrown
17+
testException: function(test, fun, label) {
18+
try {
19+
fun();
20+
test(false, label);
21+
}
22+
catch (ex) {
23+
test(true, label);
24+
}
25+
}
26+
};
27+
28+
/**
29+
* Test that the commit object is present.
30+
*/
31+
exports.method = function(test){
32+
test.expect(2);
33+
helper.testFunction(test.equals, git.diffList, 'DiffList');
34+
test.done();
35+
};
36+
37+
/**
38+
* Test that retreiving parent works as expected.
39+
*
40+
* @param {Object} test
41+
*/
42+
exports.walking = function(test) {
43+
test.expect(16);
44+
git.repo('../.git', function(error, repository) {
45+
repository.commit(historyCountKnownSHA, function(error, commit) {
46+
commit.parents(function(error, parents) {
47+
test.equals(parents.length, 1, 'Commit should have exactly one parent');
48+
parents[0].sha(function(error, parentSha) {
49+
(new git.diffList(commit.rawRepo)).treeToTree(parentSha, historyCountKnownSHA, function(error, diffList) {
50+
test.equal(null, error, 'Should not error');
51+
diffList.walk().on('file', function(error, diff) {
52+
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');
60+
61+
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');
65+
66+
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');
70+
test.done();
71+
});
72+
});
73+
});
74+
});
75+
});
76+
});
77+
};
78+
79+
exports.deltaTypes = function(test) {
80+
test.expect(9);
81+
var diffList = new git.diffList((new git.repo()).rawRepo);
82+
test.equal(diffList.deltaTypes.GIT_DELTA_UNMODIFIED, git.raw.DiffList.deltaTypes.GIT_DELTA_UNMODIFIED, 'GIT_DELTA_UNMODIFIED delta type should match expected value');
83+
test.equal(diffList.deltaTypes.GIT_DELTA_ADDED, git.raw.DiffList.deltaTypes.GIT_DELTA_ADDED, 'GIT_DELTA_ADDED delta type should match expected value');
84+
test.equal(diffList.deltaTypes.GIT_DELTA_DELETED, git.raw.DiffList.deltaTypes.GIT_DELTA_DELETED, 'GIT_DELTA_DELETED delta type should match expected value');
85+
test.equal(diffList.deltaTypes.GIT_DELTA_MODIFIED, git.raw.DiffList.deltaTypes.GIT_DELTA_MODIFIED, 'GIT_DELTA_MODIFIED delta type should match expected value');
86+
test.equal(diffList.deltaTypes.GIT_DELTA_RENAMED, git.raw.DiffList.deltaTypes.GIT_DELTA_RENAMED, 'GIT_DELTA_RENAMED delta type should match expected value');
87+
test.equal(diffList.deltaTypes.GIT_DELTA_COPIED, git.raw.DiffList.deltaTypes.GIT_DELTA_COPIED, 'GIT_DELTA_COPIED delta type should match expected value');
88+
test.equal(diffList.deltaTypes.GIT_DELTA_IGNORED, git.raw.DiffList.deltaTypes.GIT_DELTA_IGNORED, 'GIT_DELTA_IGNORED delta type should match expected value');
89+
test.equal(diffList.deltaTypes.GIT_DELTA_UNTRACKED, git.raw.DiffList.deltaTypes.GIT_DELTA_UNTRACKED, 'GIT_DELTA_UNTRACKED delta type should match expected value');
90+
test.equal(diffList.deltaTypes.GIT_DELTA_TYPECHANGE, git.raw.DiffList.deltaTypes.GIT_DELTA_TYPECHANGE, 'GIT_DELTA_TYPECHANGE delta type should match expected value');
91+
test.done();
92+
};
93+
94+
exports.lineOriginTypes = function(test) {
95+
test.expect(8);
96+
var diffList = new git.diffList((new git.repo()).rawRepo);
97+
test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'GIT_DIFF_LINE_CONTEXT line origin type should match expected value');
98+
test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_ADDITION, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_ADDITION, 'GIT_DIFF_LINE_ADDITION line origin type should match expected value');
99+
test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_DELETION, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_DELETION, 'GIT_DIFF_LINE_DELETION line origin type should match expected value');
100+
test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_ADD_EOFNL, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_ADD_EOFNL, 'GIT_DIFF_LINE_ADD_EOFNL line origin type should match expected value');
101+
test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_DEL_EOFNL, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_DEL_EOFNL, 'GIT_DIFF_LINE_DEL_EOFNL line origin type should match expected value');
102+
test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_FILE_HDR, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_FILE_HDR, 'GIT_DIFF_LINE_FILE_HDR line origin type should match expected value');
103+
test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_HUNK_HDR, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_HUNK_HDR, 'GIT_DIFF_LINE_HUNK_HDR line origin type should match expected value');
104+
test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_BINARY, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_BINARY, 'GIT_DIFF_LINE_BINARY line origin type should match expected value');
105+
test.done();
106+
};

0 commit comments

Comments
 (0)