test: organize tests into groups

This commit is contained in:
Aleksey Kulikov 2021-06-18 17:36:44 +03:00
parent 4bc2da5800
commit dadd235b66
3 changed files with 58 additions and 48 deletions

View file

@ -204,7 +204,7 @@ Map<String, String> getEntries(Pointer<git_config> cfg) {
/// (usually the local one). /// (usually the local one).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void deleteVariable(Pointer<git_config> cfg, String variable) { void deleteEntry(Pointer<git_config> cfg, String variable) {
final name = variable.toNativeUtf8().cast<Int8>(); final name = variable.toNativeUtf8().cast<Int8>();
final error = libgit2.git_config_delete_entry(cfg, name); final error = libgit2.git_config_delete_entry(cfg, name);
calloc.free(name); calloc.free(name);
@ -218,7 +218,7 @@ void deleteVariable(Pointer<git_config> cfg, String variable) {
/// ///
/// If regexp is present, then the iterator will only iterate over all /// If regexp is present, then the iterator will only iterate over all
/// values which match the pattern. /// values which match the pattern.
List<String> getMultivar( List<String> getMultivarValue(
Pointer<git_config> cfg, Pointer<git_config> cfg,
String variable, String variable,
String? regexp, String? regexp,
@ -252,7 +252,7 @@ List<String> getMultivar(
/// highest level (usually the local one). /// highest level (usually the local one).
/// ///
/// The regular expression is applied case-sensitively on the value. /// The regular expression is applied case-sensitively on the value.
void setMultivar( void setMultivarValue(
Pointer<git_config> cfg, Pointer<git_config> cfg,
String variable, String variable,
String regexp, String regexp,

View file

@ -138,9 +138,9 @@ class Config {
/// (usually the local one). /// (usually the local one).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void deleteVariable(String variable) { void deleteEntry(String variable) {
try { try {
config.deleteVariable(configPointer.value, variable); config.deleteEntry(configPointer.value, variable);
} catch (e) { } catch (e) {
rethrow; rethrow;
} }
@ -150,8 +150,8 @@ class Config {
/// ///
/// If [regexp] is present, then the iterator will only iterate over all /// If [regexp] is present, then the iterator will only iterate over all
/// values which match the pattern. /// values which match the pattern.
List<String> getMultivar(String variable, {String? regexp}) { List<String> getMultivarValue(String variable, {String? regexp}) {
return config.getMultivar(configPointer.value, variable, regexp); return config.getMultivarValue(configPointer.value, variable, regexp);
} }
/// Sets the [value] of a multivar [variable] in the config file with the /// Sets the [value] of a multivar [variable] in the config file with the
@ -159,8 +159,8 @@ class Config {
/// ///
/// The [regexp] is applied case-sensitively on the value. /// The [regexp] is applied case-sensitively on the value.
/// Empty [regexp] sets [value] for all values of a multivar [variable] /// Empty [regexp] sets [value] for all values of a multivar [variable]
void setMultivar(String variable, String regexp, String value) { void setMultivarValue(String variable, String regexp, String value) {
config.setMultivar(configPointer.value, variable, regexp, value); config.setMultivarValue(configPointer.value, variable, regexp, value);
} }
/// Releases memory allocated for config object. /// Releases memory allocated for config object.

View file

@ -78,22 +78,25 @@ void main() {
}); });
}); });
test('deletes variable', () { group('deleteEntry()', () {
config.deleteVariable('core.bare'); test('successfully deletes entry', () {
config.deleteEntry('core.bare');
final entries = config.getEntries(); final entries = config.getEntries();
expect(entries['core.bare'], isNull); expect(entries['core.bare'], isNull);
}); });
test('throws on deleting non existing variable', () { test('throws on deleting non existing variable', () {
expect( expect(
() => config.deleteVariable('not.there'), () => config.deleteEntry('not.there'),
throwsA(isA<LibGit2Error>()), throwsA(isA<LibGit2Error>()),
); );
}); });
});
group('getMultivarValue()', () {
test('returns values of multivar', () { test('returns values of multivar', () {
expect( expect(
config.getMultivar('core.gitproxy'), config.getMultivarValue('core.gitproxy'),
[ [
'proxy-command for kernel.org', 'proxy-command for kernel.org',
'default-proxy', 'default-proxy',
@ -101,28 +104,35 @@ void main() {
); );
}); });
test('returns values of multivar with regexp', () { test('returns values of multivar for provided regexp', () {
expect( expect(
config.getMultivar('core.gitproxy', regexp: 'for kernel.org\$'), config.getMultivarValue('core.gitproxy', regexp: 'for kernel.org\$'),
['proxy-command for kernel.org'], ['proxy-command for kernel.org'],
); );
}); });
test('returns empty list if multivar not found', () {
expect(config.getMultivarValue('not.there'), equals([]));
});
});
group('setMultivarValue()', () {
test('sets value of multivar', () { test('sets value of multivar', () {
config.setMultivar('core.gitproxy', 'default', 'updated'); config.setMultivarValue('core.gitproxy', 'default', 'updated');
final multivarValues = config.getMultivar('core.gitproxy'); final multivarValues = config.getMultivarValue('core.gitproxy');
expect(multivarValues, isNot(contains('default-proxy'))); expect(multivarValues, isNot(contains('default-proxy')));
expect(multivarValues, contains('updated')); expect(multivarValues, contains('updated'));
}); });
test('sets value for all multivar values when regexp is empty', () { test('sets value for all multivar values when regexp is empty', () {
config.setMultivar('core.gitproxy', '', 'updated'); config.setMultivarValue('core.gitproxy', '', 'updated');
final multivarValues = config.getMultivar('core.gitproxy'); final multivarValues = config.getMultivarValue('core.gitproxy');
expect(multivarValues, isNot(contains('default-proxy'))); expect(multivarValues, isNot(contains('default-proxy')));
expect(multivarValues, isNot(contains('proxy-command for kernel.org'))); expect(multivarValues, isNot(contains('proxy-command for kernel.org')));
expect(multivarValues, contains('updated')); expect(multivarValues, contains('updated'));
expect(multivarValues.length, equals(2)); expect(multivarValues.length, equals(2));
}); });
}); });
});
; ;
} }