Skip to content

Commit 59616f9

Browse files
author
Jens Becker
committed
test: add list_extensions_test & string_extensions_test
1 parent e26dced commit 59616f9

File tree

2 files changed

+226
-0
lines changed

2 files changed

+226
-0
lines changed

test/list_extensions_test.dart

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import 'package:fleasy/fleasy.dart';
2+
import 'package:test/test.dart';
3+
4+
void main() {
5+
group('isNotBlank', () {
6+
test('returns true on filled list.', () {
7+
final list = [1, 2, 3];
8+
9+
expect(list.isNotBlank, equals(true));
10+
});
11+
12+
test('returns false on empty list.', () {
13+
final list = <int>[];
14+
15+
expect(list.isNotBlank, equals(false));
16+
});
17+
18+
test('returns false on null list.', () {
19+
const List? list = null;
20+
21+
expect(list.isNotBlank, equals(false));
22+
});
23+
});
24+
25+
group('isBlank', () {
26+
test('returns false on filled list.', () {
27+
final list = [1, 2, 3];
28+
29+
expect(list.isBlank, equals(false));
30+
});
31+
32+
test('returns true on empty list.', () {
33+
final list = <int>[];
34+
35+
expect(list.isBlank, equals(true));
36+
});
37+
38+
test('returns true on null list.', () {
39+
const List? list = null;
40+
41+
expect(list.isBlank, equals(true));
42+
});
43+
});
44+
45+
group('find', () {
46+
test('returns the element if it satisfies the test.', () {
47+
final list = [2, 4, 6];
48+
49+
expect(list.find((element) => element == 4), equals(4));
50+
});
51+
52+
test('returns null if no element satisfies the test.', () {
53+
final list = [2, 4, 6];
54+
55+
expect(list.find((element) => element == 3), equals(null));
56+
});
57+
58+
test('returns null if list is empty.', () {
59+
final list = <int>[];
60+
61+
expect(list.find((element) => element == 3), equals(null));
62+
});
63+
});
64+
}

test/string_extensions_test.dart

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import 'package:fleasy/fleasy.dart';
2+
import 'package:test/test.dart';
3+
4+
void main() {
5+
group('isNotBlank', () {
6+
test('returns true on not blank string.', () {
7+
const string = 'x';
8+
9+
expect(string.isNotBlank, equals(true));
10+
});
11+
12+
test('returns false on empty string.', () {
13+
const string = '';
14+
15+
expect(string.isNotBlank, equals(false));
16+
});
17+
18+
test('returns false on only whitespace string.', () {
19+
const string = ' ';
20+
21+
expect(string.isNotBlank, equals(false));
22+
});
23+
24+
test('returns false on null.', () {
25+
const String? string = null;
26+
27+
expect(string.isNotBlank, equals(false));
28+
});
29+
});
30+
31+
group('isBlank', () {
32+
test('returns false on not blank string.', () {
33+
const string = 'x';
34+
35+
expect(string.isBlank, equals(false));
36+
});
37+
38+
test('returns true on empty string.', () {
39+
const string = '';
40+
41+
expect(string.isBlank, equals(true));
42+
});
43+
44+
test('returns true on only whitespace string.', () {
45+
const string = ' ';
46+
47+
expect(string.isBlank, equals(true));
48+
});
49+
50+
test('returns true on null.', () {
51+
const String? string = null;
52+
53+
expect(string.isBlank, equals(true));
54+
});
55+
});
56+
57+
group('isEmail', () {
58+
test('returns true on valid Email.', () {
59+
const email = 'info@jensbecker.dev';
60+
61+
expect(email.isEmail, equals(true));
62+
});
63+
64+
test('returns false on invalid Email.', () {
65+
const email = 'info@jensbeckerdev';
66+
67+
expect(email.isEmail, equals(false));
68+
});
69+
70+
test('returns false on null.', () {
71+
const String? email = null;
72+
73+
expect(email.isEmail, equals(false));
74+
});
75+
});
76+
77+
group('isUrl', () {
78+
test('returns true on valid URL.', () {
79+
const url = 'https://www.jensbecker.dev';
80+
81+
expect(url.isUrl, equals(true));
82+
});
83+
84+
test('returns false on invalid URLS.', () {
85+
const url = 'https://www.jensbeckerdev';
86+
87+
expect(url.isUrl, equals(false));
88+
});
89+
90+
test('returns false on null', () {
91+
const String? url = null;
92+
93+
expect(url.isUrl, equals(false));
94+
});
95+
});
96+
97+
group('isEasyPassword', () {
98+
test('returns true when all requirements are met.', () {
99+
const password = 'a1b2c3d4';
100+
101+
expect(password.isEasyPassword, equals(true));
102+
});
103+
104+
test('returns false when at least one requirement is not met.', () {
105+
const password1 = 'a1b2c3d';
106+
const password2 = ' ';
107+
108+
expect(
109+
password1.isEasyPassword && password2.isEasyPassword, equals(false));
110+
});
111+
112+
test('returns false on null', () {
113+
const String? password = null;
114+
115+
expect(password.isEasyPassword, equals(false));
116+
});
117+
});
118+
119+
group('isMediumPassword', () {
120+
test('returns true when all requirements are met.', () {
121+
const password = 'A1b2c3d4';
122+
123+
expect(password.isMediumPassword, equals(true));
124+
});
125+
126+
test('returns false when at least one requirement is not met.', () {
127+
const password1 = 'a1b2c3d4';
128+
const password2 = ' ';
129+
130+
expect(password1.isMediumPassword && password2.isMediumPassword,
131+
equals(false));
132+
});
133+
134+
test('returns false on null', () {
135+
const String? password = null;
136+
137+
expect(password.isMediumPassword, equals(false));
138+
});
139+
});
140+
141+
group('isStrongPassword', () {
142+
test('returns true when all requirements are met.', () {
143+
const password = 'A1b2c3d4!';
144+
145+
expect(password.isStrongPassword, equals(true));
146+
});
147+
148+
test('returns false when at least one requirement is not met.', () {
149+
const password1 = 'a1b2c3d4';
150+
const password2 = ' ';
151+
152+
expect(password1.isStrongPassword && password2.isStrongPassword,
153+
equals(false));
154+
});
155+
156+
test('returns false on null', () {
157+
const String? password = null;
158+
159+
expect(password.isStrongPassword, equals(false));
160+
});
161+
});
162+
}

0 commit comments

Comments
 (0)