Jonny Borges
Committed by GitHub

Merge pull request #612 from unacorbatanegra/master

PrintExtensions
  1 +import '../../../utils.dart';
1 import '../regex/get_utils.dart'; 2 import '../regex/get_utils.dart';
2 3
3 extension GetDynamicUtils on dynamic { 4 extension GetDynamicUtils on dynamic {
4 bool get isNull => GetUtils.isNull(this); 5 bool get isNull => GetUtils.isNull(this);
5 6
6 bool get isNullOrBlank => GetUtils.isNullOrBlank(this); 7 bool get isNullOrBlank => GetUtils.isNullOrBlank(this);
  8 +
  9 + void printError(
  10 + {String info = '', Function logFunction = GetUtils.printFunction}) =>
  11 + logFunction('Error: ${this.runtimeType}', this, info, isError: true);
  12 +
  13 + void printInfo(
  14 + {String info = '',
  15 + Function printFunction = GetUtils.printFunction}) =>
  16 + printFunction('Info: ${this.runtimeType}', this, info);
7 } 17 }
  1 +import '../../../get.dart';
  2 +
1 class GetUtils { 3 class GetUtils {
2 /// Checks if data is null. 4 /// Checks if data is null.
3 static bool isNull(dynamic s) => s == null; 5 static bool isNull(dynamic s) => s == null;
@@ -492,4 +494,8 @@ class GetUtils { @@ -492,4 +494,8 @@ class GetUtils {
492 static bool hasMatch(String value, String pattern) { 494 static bool hasMatch(String value, String pattern) {
493 return (value == null) ? false : RegExp(pattern).hasMatch(value); 495 return (value == null) ? false : RegExp(pattern).hasMatch(value);
494 } 496 }
  497 +
  498 + static void printFunction(String prefix, dynamic value, String info,
  499 + {bool isError = false}) =>
  500 + GetConfig.log('$prefix $value $info'.trim(), isError: isError);
495 } 501 }
@@ -64,4 +64,39 @@ void main() { @@ -64,4 +64,39 @@ void main() {
64 expect(EmptyClass().isNullOrBlank, equals(false)); 64 expect(EmptyClass().isNullOrBlank, equals(false));
65 }); 65 });
66 }); 66 });
  67 +
  68 + test('String test', () {
  69 + var value = 'string';
  70 + var expected = '';
  71 + void logFunction(String prefix, dynamic value, String info,
  72 + {bool isError = false}) {
  73 + print('algo');
  74 + expected = '$prefix $value $info'.trim();
  75 + }
  76 +
  77 + value.printError(logFunction: logFunction);
  78 + expect(expected, 'Error: String string');
  79 + });
  80 + test('Int test', () {
  81 + var value = 1;
  82 + var expected = '';
  83 + void logFunction(String prefix, dynamic value, String info,
  84 + {bool isError = false}) {
  85 + expected = '$prefix $value $info'.trim();
  86 + }
  87 +
  88 + value.printError(logFunction: logFunction);
  89 + expect(expected, 'Error: int 1');
  90 + });
  91 + test('Double test', () {
  92 + var value = 1.0;
  93 + var expected = '';
  94 + void logFunction(String prefix, dynamic value, String info,
  95 + {bool isError = false}) {
  96 + expected = '$prefix $value $info'.trim();
  97 + }
  98 +
  99 + value.printError(logFunction: logFunction);
  100 + expect(expected, 'Error: double 1.0');
  101 + });
67 } 102 }