Nicolas Lopez

printInfo&&Error extension && Test

... ... @@ -9,9 +9,12 @@ extension GetDynamicUtils on dynamic {
bool get isNullOrBlank => GetUtils.isNullOrBlank(this);
void logError({String info = ''}) =>
GetUtils.log('Error: ${this.runtimeType}', this, info);
void printError(
{String info = '', Function logFunction = GetUtils.printFunction}) =>
logFunction('Error: ${this.runtimeType}', this, info);
void logInfo({String info = ''}) =>
GetUtils.log('Info: ${this.runtimeType}', this, info);
void printInfo(
{String info = '',
Function printFunction = GetUtils.printFunction}) =>
printFunction('Info: ${this.runtimeType}', this, info);
}
... ...
... ... @@ -485,6 +485,6 @@ class GetUtils {
return (value == null) ? false : RegExp(pattern).hasMatch(value);
}
static void log(String prefix, dynamic value, String info) =>
print('$prefix $value $info');
static void printFunction(String prefix, dynamic value, String info) =>
print('$prefix $value $info'.trim());
}
... ...
import 'package:flutter_test/flutter_test.dart';
import 'package:get/utils.dart';
void main() {
test('', () {});
group('Log Extension', () {
test('String test', () {
var value = 'string';
var expected = '';
void logFunction(String prefix, dynamic value, String info) {
print('algo');
expected = '$prefix $value $info'.trim();
}
value.printError(logFunction: logFunction);
expect(expected, 'Error: String string');
});
test('Int test', () {
var value = 1;
var expected = '';
void logFunction(String prefix, dynamic value, String info) {
expected = '$prefix $value $info'.trim();
}
value.printError(logFunction: logFunction);
expect(expected, 'Error: int 1');
});
test('Double test', () {
var value = 1.0;
var expected = '';
void logFunction(String prefix, dynamic value, String info) {
expected = '$prefix $value $info'.trim();
}
value.printError(logFunction: logFunction);
expect(expected, 'Error: double 1.0');
});
});
}
... ...