Jonatas

deprecated isNull extension and improve tests

1 ## [3.23.1] 1 ## [3.23.1]
  2 +- Fix allowSelfSigned
  3 +
  4 +## [3.23.1]
2 - Fix allowSelfSigned on Flutter web 5 - Fix allowSelfSigned on Flutter web
3 6
4 ## [3.23.0] 7 ## [3.23.0]
@@ -113,8 +113,7 @@ class GetHttpClient { @@ -113,8 +113,7 @@ class GetHttpClient {
113 //TODO check this implementation 113 //TODO check this implementation
114 if (contentType != null) { 114 if (contentType != null) {
115 if (contentType.toLowerCase() == 'application/x-www-form-urlencoded') { 115 if (contentType.toLowerCase() == 'application/x-www-form-urlencoded') {
116 - var paramName = 'param';  
117 - jsonString = '$paramName=${Uri.encodeQueryComponent(jsonString)}'; 116 + jsonString = Uri.encodeQueryComponent(jsonString);
118 } 117 }
119 } 118 }
120 } else if (body is String) { 119 } else if (body is String) {
1 import '../get_utils/get_utils.dart'; 1 import '../get_utils/get_utils.dart';
2 2
3 extension GetDynamicUtils on dynamic { 3 extension GetDynamicUtils on dynamic {
  4 + @Deprecated('isNull is deprecated and cannot be used, use "==" operator')
4 bool get isNull => GetUtils.isNull(this); 5 bool get isNull => GetUtils.isNull(this);
5 6
  7 + bool get isBlank => GetUtils.isBlank(this);
  8 +
  9 + @Deprecated(
  10 + 'isNullOrBlank is deprecated and cannot be used, use "isBlank" instead')
6 bool get isNullOrBlank => GetUtils.isNullOrBlank(this); 11 bool get isNullOrBlank => GetUtils.isNullOrBlank(this);
7 12
8 void printError( 13 void printError(
@@ -5,8 +5,14 @@ import '../../../get_core/get_core.dart'; @@ -5,8 +5,14 @@ import '../../../get_core/get_core.dart';
5 /// standard dart types that contains it. 5 /// standard dart types that contains it.
6 /// 6 ///
7 /// This is here to for the 'DRY' 7 /// This is here to for the 'DRY'
8 -bool _hasIsEmpty(dynamic value) {  
9 - return value is Iterable || value is String || value is Map; 8 +bool _isEmpty(dynamic value) {
  9 + if (value is String) {
  10 + return value.toString().trim().isEmpty;
  11 + }
  12 + if (value is Iterable || value is Map) {
  13 + return value.isEmpty as bool;
  14 + }
  15 + return false;
10 } 16 }
11 17
12 /// Returns whether a dynamic value PROBABLY 18 /// Returns whether a dynamic value PROBABLY
@@ -70,13 +76,14 @@ class GetUtils { @@ -70,13 +76,14 @@ class GetUtils {
70 return true; 76 return true;
71 } 77 }
72 78
73 - if (value is String) {  
74 - return value.toString().trim().isEmpty;  
75 - }  
76 -  
77 // Pretty sure that isNullOrBlank should't be validating 79 // Pretty sure that isNullOrBlank should't be validating
78 // iterables... but I'm going to keep this for compatibility. 80 // iterables... but I'm going to keep this for compatibility.
79 - return _hasIsEmpty(value) ? value.isEmpty as bool : false; 81 + return _isEmpty(value);
  82 + }
  83 +
  84 + /// Checks if data is null or blank (empty or only contains whitespace).
  85 + static bool isBlank(dynamic value) {
  86 + return _isEmpty(value);
80 } 87 }
81 88
82 /// Checks if string is int or double. 89 /// Checks if string is int or double.
@@ -584,3 +591,10 @@ class GetUtils { @@ -584,3 +591,10 @@ class GetUtils {
584 Get.log('$prefix $value $info'.trim(), isError: isError); 591 Get.log('$prefix $value $info'.trim(), isError: isError);
585 } 592 }
586 } 593 }
  594 +
  595 +typedef PrintFunctionCallback = void Function(
  596 + String prefix,
  597 + dynamic value,
  598 + String info, {
  599 + bool isError,
  600 +});
1 import 'package:flutter_test/flutter_test.dart'; 1 import 'package:flutter_test/flutter_test.dart';
2 import 'package:get/utils.dart'; 2 import 'package:get/utils.dart';
3 3
4 -class TestClass {  
5 - final name = "John";  
6 -}  
7 -  
8 -class EmptyClass {}  
9 -  
10 void main() { 4 void main() {
11 - group('isNullOrBlank on dynamic', () {  
12 - // Identity util to convert to iterables  
13 - dynamic _id(dynamic e) => e;  
14 -  
15 - test('null isNullOrBlank should be true for null', () {  
16 - expect((null).isNullOrBlank, true);  
17 - });  
18 -  
19 - test('isNullOrBlank should be false for unsupported types', () {  
20 - expect(5.isNullOrBlank, false);  
21 - expect(0.isNullOrBlank, false);  
22 -  
23 - expect(5.0.isNullOrBlank, equals(false));  
24 - expect(0.0.isNullOrBlank, equals(false));  
25 -  
26 - TestClass testClass;  
27 - expect(testClass.isNullOrBlank, equals(true));  
28 - expect(TestClass().isNullOrBlank, equals(false));  
29 - expect(EmptyClass().isNullOrBlank, equals(false));  
30 - });  
31 -  
32 - test('isNullOrBlank should validate strings', () {  
33 - expect("".isNullOrBlank, true);  
34 - expect(" ".isNullOrBlank, true);  
35 -  
36 - expect("foo".isNullOrBlank, false);  
37 - expect(" foo ".isNullOrBlank, false);  
38 -  
39 - expect("null".isNullOrBlank, false);  
40 - });  
41 -  
42 - test('isNullOrBlank should validate iterables', () {  
43 - expect([].map(_id).isNullOrBlank, true);  
44 - expect([1].map(_id).isNullOrBlank, false);  
45 - });  
46 -  
47 - test('isNullOrBlank should validate lists', () {  
48 - expect([].isNullOrBlank, true);  
49 - expect(['oi', 'foo'].isNullOrBlank, false);  
50 - expect([{}, {}].isNullOrBlank, false);  
51 - expect(['foo'][0].isNullOrBlank, false);  
52 - });  
53 -  
54 - test('isNullOrBlank should validate sets', () {  
55 - expect((<dynamic>{}).isNullOrBlank, true);  
56 - expect(({1}).isNullOrBlank, false);  
57 - expect({'fluorine', 'chlorine', 'bromine'}.isNullOrBlank, false);  
58 - });  
59 -  
60 - test('isNullOrBlank should validate maps', () {  
61 - expect(({}).isNullOrBlank, true);  
62 - expect(({1: 1}).isNullOrBlank, false);  
63 - expect({"other": "thing"}.isNullOrBlank, false);  
64 -  
65 - final map = {"foo": 'bar', "one": "um"};  
66 - expect(map["foo"].isNullOrBlank, false);  
67 - expect(map["other"].isNullOrBlank, true);  
68 - });  
69 - });  
70 -  
71 test('String test', () { 5 test('String test', () {
72 var value = 'string'; 6 var value = 'string';
73 var expected = ''; 7 var expected = '';
@@ -9,7 +9,7 @@ void main() { @@ -9,7 +9,7 @@ void main() {
9 final alphaNumeric = "123asd"; 9 final alphaNumeric = "123asd";
10 final numbers = "123"; 10 final numbers = "123";
11 final letters = "foo"; 11 final letters = "foo";
12 - String notInitializedVar; 12 + // String notInitializedVar;
13 13
14 test('var.isNum', () { 14 test('var.isNum', () {
15 expect(digit.isNum, true); 15 expect(digit.isNum, true);
@@ -31,7 +31,7 @@ void main() { @@ -31,7 +31,7 @@ void main() {
31 31
32 test('var.isBool', () { 32 test('var.isBool', () {
33 final trueString = 'true'; 33 final trueString = 'true';
34 - expect(notInitializedVar.isBool, false); 34 + // expect(notInitializedVar.isBool, false);
35 expect(letters.isBool, false); 35 expect(letters.isBool, false);
36 expect(trueString.isBool, true); 36 expect(trueString.isBool, true);
37 }); 37 });
@@ -5,7 +5,7 @@ import 'package:get/utils.dart'; @@ -5,7 +5,7 @@ import 'package:get/utils.dart';
5 void main() { 5 void main() {
6 group('Group test for PaddingX Extension', () { 6 group('Group test for PaddingX Extension', () {
7 testWidgets('Test of paddingAll', (tester) async { 7 testWidgets('Test of paddingAll', (tester) async {
8 - Widget containerTest; 8 + Widget containerTest = Container();
9 9
10 expect(find.byType(Padding), findsNothing); 10 expect(find.byType(Padding), findsNothing);
11 11
@@ -15,7 +15,7 @@ void main() { @@ -15,7 +15,7 @@ void main() {
15 }); 15 });
16 16
17 testWidgets('Test of paddingOnly', (tester) async { 17 testWidgets('Test of paddingOnly', (tester) async {
18 - Widget containerTest; 18 + Widget containerTest = Container();
19 19
20 expect(find.byType(Padding), findsNothing); 20 expect(find.byType(Padding), findsNothing);
21 21
@@ -25,7 +25,7 @@ void main() { @@ -25,7 +25,7 @@ void main() {
25 }); 25 });
26 26
27 testWidgets('Test of paddingSymmetric', (tester) async { 27 testWidgets('Test of paddingSymmetric', (tester) async {
28 - Widget containerTest; 28 + Widget containerTest = Container();
29 29
30 expect(find.byType(Padding), findsNothing); 30 expect(find.byType(Padding), findsNothing);
31 31
@@ -35,7 +35,7 @@ void main() { @@ -35,7 +35,7 @@ void main() {
35 }); 35 });
36 36
37 testWidgets('Test of paddingZero', (tester) async { 37 testWidgets('Test of paddingZero', (tester) async {
38 - Widget containerTest; 38 + Widget containerTest = Container();
39 39
40 expect(find.byType(Padding), findsNothing); 40 expect(find.byType(Padding), findsNothing);
41 41
@@ -47,7 +47,7 @@ void main() { @@ -47,7 +47,7 @@ void main() {
47 47
48 group('Group test for MarginX Extension', () { 48 group('Group test for MarginX Extension', () {
49 testWidgets('Test of marginAll', (tester) async { 49 testWidgets('Test of marginAll', (tester) async {
50 - Widget containerTest; 50 + Widget containerTest = Container();
51 51
52 await tester.pumpWidget(containerTest.marginAll(16)); 52 await tester.pumpWidget(containerTest.marginAll(16));
53 53
@@ -55,7 +55,7 @@ void main() { @@ -55,7 +55,7 @@ void main() {
55 }); 55 });
56 56
57 testWidgets('Test of marginOnly', (tester) async { 57 testWidgets('Test of marginOnly', (tester) async {
58 - Widget containerTest; 58 + Widget containerTest = Container();
59 59
60 await tester.pumpWidget(containerTest.marginOnly(top: 16)); 60 await tester.pumpWidget(containerTest.marginOnly(top: 16));
61 61
@@ -63,7 +63,7 @@ void main() { @@ -63,7 +63,7 @@ void main() {
63 }); 63 });
64 64
65 testWidgets('Test of marginSymmetric', (tester) async { 65 testWidgets('Test of marginSymmetric', (tester) async {
66 - Widget containerTest; 66 + Widget containerTest = Container();
67 67
68 await tester.pumpWidget(containerTest.marginSymmetric(vertical: 16)); 68 await tester.pumpWidget(containerTest.marginSymmetric(vertical: 16));
69 69
@@ -71,7 +71,7 @@ void main() { @@ -71,7 +71,7 @@ void main() {
71 }); 71 });
72 72
73 testWidgets('Test of marginZero', (tester) async { 73 testWidgets('Test of marginZero', (tester) async {
74 - Widget containerTest; 74 + Widget containerTest = Container();
75 75
76 await tester.pumpWidget(containerTest.marginZero); 76 await tester.pumpWidget(containerTest.marginZero);
77 77
1 import 'package:flutter_test/flutter_test.dart'; 1 import 'package:flutter_test/flutter_test.dart';
2 import 'package:get/get.dart'; 2 import 'package:get/get.dart';
3 3
4 -// Identity util to convert to iterables  
5 -dynamic _id(dynamic e) => e; 4 +class TestClass {
  5 + final name = "John";
  6 +}
  7 +
  8 +class EmptyClass {}
6 9
7 void main() { 10 void main() {
8 - // Tests for GetUtils.isNullOrBlank are located at dynamic extensions 11 + dynamic _id(dynamic e) => e;
  12 +
  13 + Null _test;
  14 +
  15 + test('null isNullOrBlank should be true for null', () {
  16 + expect(GetUtils.isNullOrBlank(_test), true);
  17 + });
  18 +
  19 + test('isNullOrBlank should be false for unsupported types', () {
  20 + expect(GetUtils.isNullOrBlank(5), false);
  21 + expect(GetUtils.isNullOrBlank(0), false);
  22 +
  23 + expect(GetUtils.isNullOrBlank(5.0), equals(false));
  24 + expect(GetUtils.isNullOrBlank(0.0), equals(false));
  25 +
  26 + TestClass testClass;
  27 + expect(GetUtils.isNullOrBlank(testClass), equals(true));
  28 + expect(GetUtils.isNullOrBlank(TestClass()), equals(false));
  29 + expect(GetUtils.isNullOrBlank(EmptyClass()), equals(false));
  30 + });
  31 +
  32 + test('isNullOrBlank should validate strings', () {
  33 + expect(GetUtils.isNullOrBlank(""), true);
  34 + expect(GetUtils.isNullOrBlank(" "), true);
  35 +
  36 + expect(GetUtils.isNullOrBlank("foo"), false);
  37 + expect(GetUtils.isNullOrBlank(" foo "), false);
  38 +
  39 + expect(GetUtils.isNullOrBlank("null"), false);
  40 + });
  41 +
  42 + test('isNullOrBlank should validate iterables', () {
  43 + expect(GetUtils.isNullOrBlank([].map(_id)), true);
  44 + expect(GetUtils.isNullOrBlank([1].map(_id)), false);
  45 + });
  46 +
  47 + test('isNullOrBlank should validate lists', () {
  48 + expect(GetUtils.isNullOrBlank(const []), true);
  49 + expect(GetUtils.isNullOrBlank(['oi', 'foo']), false);
  50 + expect(GetUtils.isNullOrBlank([{}, {}]), false);
  51 + expect(GetUtils.isNullOrBlank(['foo'][0]), false);
  52 + });
  53 +
  54 + test('isNullOrBlank should validate sets', () {
  55 + expect(GetUtils.isNullOrBlank(<dynamic>{}), true);
  56 + expect(GetUtils.isNullOrBlank({1}), false);
  57 + expect(GetUtils.isNullOrBlank({'fluorine', 'chlorine', 'bromine'}), false);
  58 + });
  59 +
  60 + test('isNullOrBlank should validate maps', () {
  61 + expect(GetUtils.isNullOrBlank({}), true);
  62 + expect(GetUtils.isNullOrBlank({1: 1}), false);
  63 + expect(GetUtils.isNullOrBlank({"other": "thing"}), false);
  64 +
  65 + final map = {"foo": 'bar', "one": "um"};
  66 + expect(GetUtils.isNullOrBlank(map["foo"]), false);
  67 + expect(GetUtils.isNullOrBlank(map["other"]), true);
  68 + });
9 group('GetUtils.isLength* functions', () { 69 group('GetUtils.isLength* functions', () {
10 test('isLengthEqualTo should validate iterable lengths', () { 70 test('isLengthEqualTo should validate iterable lengths', () {
11 // iterables should cover list and set 71 // iterables should cover list and set