mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
refactor!: use class names instead of aliases from Repository in tests (#37)
BREAKING CHANGE: move API methods related to diffing into Diff class
This commit is contained in:
parent
3e1ece4e6f
commit
08cbe8a17f
28 changed files with 943 additions and 834 deletions
|
@ -26,20 +26,20 @@ void main() {
|
|||
|
||||
group('Blob', () {
|
||||
test('lookups blob with provided oid', () {
|
||||
final blob = repo.lookupBlob(repo[blobSHA]);
|
||||
final blob = Blob.lookup(repo: repo, oid: repo[blobSHA]);
|
||||
expect(blob, isA<Blob>());
|
||||
blob.free();
|
||||
});
|
||||
|
||||
test('throws when trying to lookup with invalid oid', () {
|
||||
expect(
|
||||
() => repo.lookupBlob(repo['0' * 40]),
|
||||
() => Blob.lookup(repo: repo, oid: repo['0' * 40]),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns correct values', () {
|
||||
final blob = repo.lookupBlob(repo[blobSHA]);
|
||||
final blob = Blob.lookup(repo: repo, oid: repo[blobSHA]);
|
||||
|
||||
expect(blob.oid.sha, blobSHA);
|
||||
expect(blob.isBinary, false);
|
||||
|
@ -50,8 +50,8 @@ void main() {
|
|||
});
|
||||
|
||||
test('creates new blob with provided content', () {
|
||||
final oid = repo.createBlob(newBlobContent);
|
||||
final newBlob = repo.lookupBlob(oid);
|
||||
final oid = Blob.create(repo: repo, content: newBlobContent);
|
||||
final newBlob = Blob.lookup(repo: repo, oid: oid);
|
||||
|
||||
expect(newBlob.oid.sha, '18fdaeef018e57a92bcad2d4a35b577f34089af6');
|
||||
expect(newBlob.isBinary, false);
|
||||
|
@ -70,8 +70,11 @@ void main() {
|
|||
});
|
||||
|
||||
test('creates new blob from file at provided relative path', () {
|
||||
final oid = repo.createBlobFromWorkdir('feature_file');
|
||||
final newBlob = repo.lookupBlob(oid);
|
||||
final oid = Blob.createFromWorkdir(
|
||||
repo: repo,
|
||||
relativePath: 'feature_file',
|
||||
);
|
||||
final newBlob = Blob.lookup(repo: repo, oid: oid);
|
||||
|
||||
expect(newBlob.oid.sha, blobSHA);
|
||||
expect(newBlob.isBinary, false);
|
||||
|
@ -83,7 +86,10 @@ void main() {
|
|||
|
||||
test('throws when creating new blob from invalid path', () {
|
||||
expect(
|
||||
() => repo.createBlobFromWorkdir('invalid/path.txt'),
|
||||
() => Blob.createFromWorkdir(
|
||||
repo: repo,
|
||||
relativePath: 'invalid/path.txt',
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -92,8 +98,8 @@ void main() {
|
|||
final outsideFile = File(
|
||||
p.join(Directory.current.absolute.path, 'test', 'blob_test.dart'),
|
||||
);
|
||||
final oid = repo.createBlobFromDisk(outsideFile.path);
|
||||
final newBlob = repo.lookupBlob(oid);
|
||||
final oid = Blob.createFromDisk(repo: repo, path: outsideFile.path);
|
||||
final newBlob = Blob.lookup(repo: repo, oid: oid);
|
||||
|
||||
expect(newBlob, isA<Blob>());
|
||||
expect(newBlob.isBinary, false);
|
||||
|
@ -103,13 +109,13 @@ void main() {
|
|||
|
||||
test('throws when trying to create from invalid path', () {
|
||||
expect(
|
||||
() => repo.createBlobFromDisk('invalid.file'),
|
||||
() => Blob.createFromDisk(repo: repo, path: 'invalid.file'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('duplicates blob', () {
|
||||
final blob = repo.lookupBlob(repo[blobSHA]);
|
||||
final blob = Blob.lookup(repo: repo, oid: repo[blobSHA]);
|
||||
final dupBlob = blob.duplicate();
|
||||
|
||||
expect(blob.oid.sha, dupBlob.oid.sha);
|
||||
|
@ -119,8 +125,8 @@ void main() {
|
|||
});
|
||||
|
||||
test('filters content of a blob', () {
|
||||
final blobOid = repo.createBlob('clrf\nclrf\n');
|
||||
final blob = repo.lookupBlob(blobOid);
|
||||
final blobOid = Blob.create(repo: repo, content: 'clrf\nclrf\n');
|
||||
final blob = Blob.lookup(repo: repo, oid: blobOid);
|
||||
|
||||
expect(blob.filterContent(asPath: 'file.crlf'), 'clrf\r\nclrf\r\n');
|
||||
|
||||
|
@ -130,11 +136,12 @@ void main() {
|
|||
test('filters content of a blob with provided commit for attributes', () {
|
||||
repo.checkout(target: 'refs/tags/v0.2');
|
||||
|
||||
final blobOid = repo.createBlob('clrf\nclrf\n');
|
||||
final blob = repo.lookupBlob(blobOid);
|
||||
final blobOid = Blob.create(repo: repo, content: 'clrf\nclrf\n');
|
||||
final blob = Blob.lookup(repo: repo, oid: blobOid);
|
||||
|
||||
final commit = repo.lookupCommit(
|
||||
repo['d2f3abc9324a22a9f80fec2c131ec43c93430618'],
|
||||
final commit = Commit.lookup(
|
||||
repo: repo,
|
||||
oid: repo['d2f3abc9324a22a9f80fec2c131ec43c93430618'],
|
||||
);
|
||||
|
||||
expect(
|
||||
|
@ -176,31 +183,26 @@ index e69de29..0000000
|
|||
+++ /dev/null
|
||||
""";
|
||||
test('creates patch with changes between blobs', () {
|
||||
final a = repo.lookupBlob(
|
||||
repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'],
|
||||
);
|
||||
final b = repo.lookupBlob(
|
||||
repo['9c78c21d6680a7ffebc76f7ac68cacc11d8f48bc'],
|
||||
);
|
||||
final patch = repo.diffBlobs(
|
||||
a: a,
|
||||
b: b,
|
||||
aPath: path,
|
||||
bPath: path,
|
||||
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();
|
||||
a.free();
|
||||
b.free();
|
||||
oldBlob.free();
|
||||
newBlob.free();
|
||||
});
|
||||
|
||||
test('creates patch with changes between blobs from one blob (delete)',
|
||||
() {
|
||||
final blob = repo.lookupBlob(
|
||||
repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'],
|
||||
);
|
||||
final blob = Blob.lookup(repo: repo, oid: repo['e69de29']);
|
||||
|
||||
final patch = blob.diff(
|
||||
newBlob: null,
|
||||
oldAsPath: path,
|
||||
|
@ -214,9 +216,7 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('creates patch with changes between blob and buffer', () {
|
||||
final blob = repo.lookupBlob(
|
||||
repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'],
|
||||
);
|
||||
final blob = Blob.lookup(repo: repo, oid: repo['e69de29']);
|
||||
|
||||
final patch = blob.diffToBuffer(
|
||||
buffer: 'Feature edit\n',
|
||||
|
@ -229,25 +229,19 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('creates patch with changes between blob and buffer (delete)', () {
|
||||
final a = repo.lookupBlob(
|
||||
repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'],
|
||||
);
|
||||
final patch = Patch.create(
|
||||
a: a,
|
||||
b: null,
|
||||
aPath: path,
|
||||
bPath: path,
|
||||
);
|
||||
final blob = Blob.lookup(repo: repo, oid: repo['e69de29']);
|
||||
|
||||
final patch = blob.diffToBuffer(buffer: null, oldAsPath: path);
|
||||
|
||||
expect(patch.text, blobPatchDelete);
|
||||
|
||||
patch.free();
|
||||
a.free();
|
||||
blob.free();
|
||||
});
|
||||
});
|
||||
|
||||
test('returns string representation of Blob object', () {
|
||||
final blob = repo.lookupBlob(repo[blobSHA]);
|
||||
final blob = Blob.lookup(repo: repo, oid: repo[blobSHA]);
|
||||
expect(blob.toString(), contains('Blob{'));
|
||||
blob.free();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue