mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 12:49:08 -04:00
refactor(patch): initialize DiffHunk with all the information accessible immediately
This commit is contained in:
parent
28f08e308a
commit
77a34c3335
4 changed files with 167 additions and 149 deletions
|
@ -559,33 +559,6 @@ index e69de29..c217c63 100644
|
|||
expect(Diff.parse(patchText).patch, patchText);
|
||||
});
|
||||
|
||||
test('returns hunks in a patch', () {
|
||||
final patch = Patch.fromDiff(diff: Diff.parse(patchText), index: 0);
|
||||
final hunk = patch.hunks[0];
|
||||
|
||||
expect(patch.hunks.length, 1);
|
||||
expect(hunk.linesCount, 1);
|
||||
expect(hunk.oldStart, 0);
|
||||
expect(hunk.oldLines, 0);
|
||||
expect(hunk.newStart, 1);
|
||||
expect(hunk.newLines, 1);
|
||||
expect(hunk.header, '@@ -0,0 +1 @@\n');
|
||||
});
|
||||
|
||||
test('returns lines in a hunk', () {
|
||||
final patch = Patch.fromDiff(diff: Diff.parse(patchText), index: 0);
|
||||
final hunk = patch.hunks[0];
|
||||
final line = hunk.lines[0];
|
||||
|
||||
expect(hunk.lines.length, 1);
|
||||
expect(line.origin, GitDiffLine.addition);
|
||||
expect(line.oldLineNumber, -1);
|
||||
expect(line.newLineNumber, 1);
|
||||
expect(line.numLines, 1);
|
||||
expect(line.contentOffset, 155);
|
||||
expect(line.content, 'Modified content\n');
|
||||
});
|
||||
|
||||
test('manually releases allocated memory', () {
|
||||
final diff = Diff.parse(patchText);
|
||||
expect(() => diff.free(), returnsNormally);
|
||||
|
@ -597,8 +570,8 @@ index e69de29..c217c63 100644
|
|||
});
|
||||
|
||||
test(
|
||||
'returns string representation of Diff, DiffDelta, DiffFile, '
|
||||
'DiffHunk, DiffLine and DiffStats objects', () {
|
||||
'returns string representation of Diff, DiffDelta, DiffFile '
|
||||
' and DiffStats objects', () {
|
||||
final diff = Diff.parse(patchText);
|
||||
final patch = Patch.fromDiff(diff: diff, index: 0);
|
||||
final stats = diff.stats;
|
||||
|
@ -606,8 +579,6 @@ index e69de29..c217c63 100644
|
|||
expect(diff.toString(), contains('Diff{'));
|
||||
expect(patch.delta.toString(), contains('DiffDelta{'));
|
||||
expect(patch.delta.oldFile.toString(), contains('DiffFile{'));
|
||||
expect(patch.hunks[0].toString(), contains('DiffHunk{'));
|
||||
expect(patch.hunks[0].lines[0].toString(), contains('DiffLine{'));
|
||||
expect(stats.toString(), contains('DiffStats{'));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -155,6 +155,43 @@ index e69de29..0000000
|
|||
expect(() => Patch(nullptr).text, throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('returns hunks in a patch', () {
|
||||
final patch = Patch.fromBuffers(
|
||||
oldBuffer: oldBuffer,
|
||||
newBuffer: newBuffer,
|
||||
oldBufferPath: path,
|
||||
newBufferPath: path,
|
||||
);
|
||||
final hunk = patch.hunks[0];
|
||||
|
||||
expect(patch.hunks.length, 1);
|
||||
expect(hunk.linesCount, 1);
|
||||
expect(hunk.oldStart, 0);
|
||||
expect(hunk.oldLines, 0);
|
||||
expect(hunk.newStart, 1);
|
||||
expect(hunk.newLines, 1);
|
||||
expect(hunk.header, '@@ -0,0 +1 @@\n');
|
||||
});
|
||||
|
||||
test('returns lines in a hunk', () {
|
||||
final patch = Patch.fromBuffers(
|
||||
oldBuffer: oldBuffer,
|
||||
newBuffer: newBuffer,
|
||||
oldBufferPath: path,
|
||||
newBufferPath: path,
|
||||
);
|
||||
final hunk = patch.hunks[0];
|
||||
final line = hunk.lines[0];
|
||||
|
||||
expect(hunk.lines.length, 1);
|
||||
expect(line.origin, GitDiffLine.addition);
|
||||
expect(line.oldLineNumber, -1);
|
||||
expect(line.newLineNumber, 1);
|
||||
expect(line.numLines, 1);
|
||||
expect(line.contentOffset, 0);
|
||||
expect(line.content, 'Feature edit\n');
|
||||
});
|
||||
|
||||
test('returns line counts of each type in a patch', () {
|
||||
final patch = Patch.fromBuffers(
|
||||
oldBuffer: oldBuffer,
|
||||
|
@ -180,7 +217,9 @@ index e69de29..0000000
|
|||
expect(() => patch.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('returns string representation of Patch object', () {
|
||||
test(
|
||||
'returns string representation of Patch, DiffHunk and DiffLine objects',
|
||||
() {
|
||||
final patch = Patch.fromBuffers(
|
||||
oldBuffer: oldBuffer,
|
||||
newBuffer: newBuffer,
|
||||
|
@ -189,6 +228,8 @@ index e69de29..0000000
|
|||
);
|
||||
|
||||
expect(patch.toString(), contains('Patch{'));
|
||||
expect(patch.hunks[0].toString(), contains('DiffHunk{'));
|
||||
expect(patch.hunks[0].lines[0].toString(), contains('DiffLine{'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue