Jonny Borges
Committed by GitHub

Merge pull request #612 from unacorbatanegra/master

PrintExtensions
import '../../../utils.dart';
import '../regex/get_utils.dart';
extension GetDynamicUtils on dynamic {
bool get isNull => GetUtils.isNull(this);
bool get isNullOrBlank => GetUtils.isNullOrBlank(this);
void printError(
{String info = '', Function logFunction = GetUtils.printFunction}) =>
logFunction('Error: ${this.runtimeType}', this, info, isError: true);
void printInfo(
{String info = '',
Function printFunction = GetUtils.printFunction}) =>
printFunction('Info: ${this.runtimeType}', this, info);
}
... ...
import '../../../get.dart';
class GetUtils {
/// Checks if data is null.
static bool isNull(dynamic s) => s == null;
... ... @@ -492,4 +494,8 @@ class GetUtils {
static bool hasMatch(String value, String pattern) {
return (value == null) ? false : RegExp(pattern).hasMatch(value);
}
static void printFunction(String prefix, dynamic value, String info,
{bool isError = false}) =>
GetConfig.log('$prefix $value $info'.trim(), isError: isError);
}
... ...
... ... @@ -64,4 +64,39 @@ void main() {
expect(EmptyClass().isNullOrBlank, equals(false));
});
});
test('String test', () {
var value = 'string';
var expected = '';
void logFunction(String prefix, dynamic value, String info,
{bool isError = false}) {
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,
{bool isError = false}) {
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,
{bool isError = false}) {
expected = '$prefix $value $info'.trim();
}
value.printError(logFunction: logFunction);
expect(expected, 'Error: double 1.0');
});
}
... ...