Nicolas Lopez

printInfo&&Error extension && Test

@@ -9,9 +9,12 @@ extension GetDynamicUtils on dynamic { @@ -9,9 +9,12 @@ extension GetDynamicUtils on dynamic {
9 9
10 bool get isNullOrBlank => GetUtils.isNullOrBlank(this); 10 bool get isNullOrBlank => GetUtils.isNullOrBlank(this);
11 11
12 - void logError({String info = ''}) =>  
13 - GetUtils.log('Error: ${this.runtimeType}', this, info); 12 + void printError(
  13 + {String info = '', Function logFunction = GetUtils.printFunction}) =>
  14 + logFunction('Error: ${this.runtimeType}', this, info);
14 15
15 - void logInfo({String info = ''}) =>  
16 - GetUtils.log('Info: ${this.runtimeType}', this, info); 16 + void printInfo(
  17 + {String info = '',
  18 + Function printFunction = GetUtils.printFunction}) =>
  19 + printFunction('Info: ${this.runtimeType}', this, info);
17 } 20 }
@@ -485,6 +485,6 @@ class GetUtils { @@ -485,6 +485,6 @@ class GetUtils {
485 return (value == null) ? false : RegExp(pattern).hasMatch(value); 485 return (value == null) ? false : RegExp(pattern).hasMatch(value);
486 } 486 }
487 487
488 - static void log(String prefix, dynamic value, String info) =>  
489 - print('$prefix $value $info'); 488 + static void printFunction(String prefix, dynamic value, String info) =>
  489 + print('$prefix $value $info'.trim());
490 } 490 }
1 import 'package:flutter_test/flutter_test.dart'; 1 import 'package:flutter_test/flutter_test.dart';
  2 +import 'package:get/utils.dart';
2 3
3 void main() { 4 void main() {
4 - test('', () {}); 5 + group('Log Extension', () {
  6 + test('String test', () {
  7 + var value = 'string';
  8 + var expected = '';
  9 + void logFunction(String prefix, dynamic value, String info) {
  10 + print('algo');
  11 + expected = '$prefix $value $info'.trim();
  12 + }
  13 +
  14 + value.printError(logFunction: logFunction);
  15 + expect(expected, 'Error: String string');
  16 + });
  17 + test('Int test', () {
  18 + var value = 1;
  19 + var expected = '';
  20 + void logFunction(String prefix, dynamic value, String info) {
  21 + expected = '$prefix $value $info'.trim();
  22 + }
  23 +
  24 + value.printError(logFunction: logFunction);
  25 + expect(expected, 'Error: int 1');
  26 + });
  27 + test('Double test', () {
  28 + var value = 1.0;
  29 + var expected = '';
  30 + void logFunction(String prefix, dynamic value, String info) {
  31 + expected = '$prefix $value $info'.trim();
  32 + }
  33 +
  34 + value.printError(logFunction: logFunction);
  35 + expect(expected, 'Error: double 1.0');
  36 + });
  37 + });
5 } 38 }