test: improve coverage

This commit is contained in:
Aleksey Kulikov 2021-10-15 17:37:38 +03:00
parent d75acbfdd3
commit d6eae1e9ed
71 changed files with 710 additions and 229 deletions

View file

@ -30,10 +30,41 @@ void main() {
mode: FileMode.append,
);
repo.createStash(stasher: stasher, includeUntracked: true);
repo.createStash(stasher: stasher);
expect(repo.status.isEmpty, true);
});
test('successfully saves changes to stash including ignored', () {
final swpPath = File('${tmpDir.path}/some.swp');
swpPath.writeAsStringSync('ignored');
repo.createStash(
stasher: stasher,
includeUntracked: true,
includeIgnored: true,
);
expect(repo.status.isEmpty, true);
expect(swpPath.existsSync(), false);
repo.applyStash();
expect(swpPath.existsSync(), true);
});
test('leaves changes added to index intact', () {
File('${tmpDir.path}/file').writeAsStringSync(
'edit',
mode: FileMode.append,
);
final index = repo.index;
index.add('file');
repo.createStash(stasher: stasher, keepIndex: true);
expect(repo.status.isEmpty, false);
expect(repo.stashes.length, 1);
index.free();
});
test('successfully applies changes from stash', () {
File('${tmpDir.path}/file').writeAsStringSync(
'edit',
@ -47,6 +78,23 @@ void main() {
expect(repo.status, contains('file'));
});
test('successfully applies changes from stash including index changes', () {
File('${tmpDir.path}/stash.this').writeAsStringSync('stash');
final index = repo.index;
index.add('stash.this');
expect(index.find('stash.this'), true);
repo.createStash(stasher: stasher, includeUntracked: true);
expect(repo.status.isEmpty, true);
expect(index.find('stash.this'), false);
repo.applyStash(reinstateIndex: true);
expect(repo.status, contains('stash.this'));
expect(index.find('stash.this'), true);
index.free();
});
test('successfully drops stash', () {
File('${tmpDir.path}/file').writeAsStringSync(
'edit',
@ -71,6 +119,23 @@ void main() {
expect(() => repo.applyStash(), throwsA(isA<LibGit2Error>()));
});
test('successfully pops from stash including index changes', () {
File('${tmpDir.path}/stash.this').writeAsStringSync('stash');
final index = repo.index;
index.add('stash.this');
expect(index.find('stash.this'), true);
repo.createStash(stasher: stasher, includeUntracked: true);
expect(repo.status.isEmpty, true);
expect(index.find('stash.this'), false);
repo.popStash(reinstateIndex: true);
expect(repo.status, contains('stash.this'));
expect(index.find('stash.this'), true);
index.free();
});
test('returns list of stashes', () {
File('${tmpDir.path}/file').writeAsStringSync(
'edit',
@ -85,5 +150,11 @@ void main() {
expect(stash.index, 0);
expect(stash.message, 'On master: WIP');
});
test('returns string representation of Stash object', () {
File('${tmpDir.path}/stash.this').writeAsStringSync('stash');
repo.createStash(stasher: stasher, includeUntracked: true);
expect(repo.stashes[0].toString(), contains('Stash{'));
});
});
}