feat(patch)!: divide Patch.create() into specific methods (#38)

BREAKING CHANGE: remove patch generation methods from Blob class
This commit is contained in:
Aleksey Kulikov 2022-01-25 15:58:06 +03:00 committed by GitHub
parent 08cbe8a17f
commit 0844f03387
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
106 changed files with 156 additions and 6171 deletions

View file

@ -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{'));