mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
feat(patch)!: divide Patch.create() into specific methods (#38)
BREAKING CHANGE: remove patch generation methods from Blob class
This commit is contained in:
parent
08cbe8a17f
commit
0844f03387
106 changed files with 156 additions and 6171 deletions
|
@ -164,82 +164,6 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
group('patch', () {
|
||||
const path = 'feature_file';
|
||||
const blobPatch = """
|
||||
diff --git a/feature_file b/feature_file
|
||||
index e69de29..9c78c21 100644
|
||||
--- a/feature_file
|
||||
+++ b/feature_file
|
||||
@@ -0,0 +1 @@
|
||||
+Feature edit
|
||||
""";
|
||||
|
||||
const blobPatchDelete = """
|
||||
diff --git a/feature_file b/feature_file
|
||||
deleted file mode 100644
|
||||
index e69de29..0000000
|
||||
--- a/feature_file
|
||||
+++ /dev/null
|
||||
""";
|
||||
test('creates patch with changes between blobs', () {
|
||||
final oldBlob = Blob.lookup(repo: repo, oid: repo['e69de29']);
|
||||
final newBlob = Blob.lookup(repo: repo, oid: repo['9c78c21']);
|
||||
|
||||
final patch = oldBlob.diff(
|
||||
newBlob: newBlob,
|
||||
oldAsPath: path,
|
||||
newAsPath: path,
|
||||
);
|
||||
|
||||
expect(patch.text, blobPatch);
|
||||
|
||||
patch.free();
|
||||
oldBlob.free();
|
||||
newBlob.free();
|
||||
});
|
||||
|
||||
test('creates patch with changes between blobs from one blob (delete)',
|
||||
() {
|
||||
final blob = Blob.lookup(repo: repo, oid: repo['e69de29']);
|
||||
|
||||
final patch = blob.diff(
|
||||
newBlob: null,
|
||||
oldAsPath: path,
|
||||
newAsPath: path,
|
||||
);
|
||||
|
||||
expect(patch.text, blobPatchDelete);
|
||||
|
||||
blob.free();
|
||||
patch.free();
|
||||
});
|
||||
|
||||
test('creates patch with changes between blob and buffer', () {
|
||||
final blob = Blob.lookup(repo: repo, oid: repo['e69de29']);
|
||||
|
||||
final patch = blob.diffToBuffer(
|
||||
buffer: 'Feature edit\n',
|
||||
oldAsPath: path,
|
||||
);
|
||||
expect(patch.text, blobPatch);
|
||||
|
||||
patch.free();
|
||||
blob.free();
|
||||
});
|
||||
|
||||
test('creates patch with changes between blob and buffer (delete)', () {
|
||||
final blob = Blob.lookup(repo: repo, oid: repo['e69de29']);
|
||||
|
||||
final patch = blob.diffToBuffer(buffer: null, oldAsPath: path);
|
||||
|
||||
expect(patch.text, blobPatchDelete);
|
||||
|
||||
patch.free();
|
||||
blob.free();
|
||||
});
|
||||
});
|
||||
|
||||
test('returns string representation of Blob object', () {
|
||||
final blob = Blob.lookup(repo: repo, oid: repo[blobSHA]);
|
||||
expect(blob.toString(), contains('Blob{'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue