dynamic_extensions_test.dart
3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import 'package:flutter_test/flutter_test.dart';
import 'package:get/utils.dart';
class TestClass {
final name = "John";
}
class EmptyClass {}
void main() {
group('isNullOrBlank on dynamic', () {
// Identity util to convert to iterables
dynamic _id(dynamic e) => e;
test('null isNullOrBlank should be true for null', () {
expect((null).isNullOrBlank, true);
});
test('isNullOrBlank should be false for unsupported types', () {
expect(5.isNullOrBlank, false);
expect(0.isNullOrBlank, false);
expect(5.0.isNullOrBlank, equals(false));
expect(0.0.isNullOrBlank, equals(false));
TestClass testClass;
expect(testClass.isNullOrBlank, equals(true));
expect(TestClass().isNullOrBlank, equals(false));
expect(EmptyClass().isNullOrBlank, equals(false));
});
test('isNullOrBlank should validate strings', () {
expect("".isNullOrBlank, true);
expect(" ".isNullOrBlank, true);
expect("foo".isNullOrBlank, false);
expect(" foo ".isNullOrBlank, false);
expect("null".isNullOrBlank, false);
});
test('isNullOrBlank should validate iterables', () {
expect([].map(_id).isNullOrBlank, true);
expect([1].map(_id).isNullOrBlank, false);
});
test('isNullOrBlank should validate lists', () {
expect([].isNullOrBlank, true);
expect(['oi', 'foo'].isNullOrBlank, false);
expect([{}, {}].isNullOrBlank, false);
expect(['foo'][0].isNullOrBlank, false);
});
test('isNullOrBlank should validate sets', () {
expect((<dynamic>{}).isNullOrBlank, true);
expect(({1}).isNullOrBlank, false);
expect({'fluorine', 'chlorine', 'bromine'}.isNullOrBlank, false);
});
test('isNullOrBlank should validate maps', () {
expect(({}).isNullOrBlank, true);
expect(({1: 1}).isNullOrBlank, false);
expect({"other": "thing"}.isNullOrBlank, false);
final map = {"foo": 'bar', "one": "um"};
expect(map["foo"].isNullOrBlank, false);
expect(map["other"].isNullOrBlank, true);
});
});
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');
});
}