Skip to content

Commit 765d215

Browse files
committed
Add unit tests
1 parent fb3f9a0 commit 765d215

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

coverage/lcov.info

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ end_of_record
1414
SF:lib/src/bool.dart
1515
DA:12,2
1616
DA:24,1
17-
DA:37,0
18-
DA:38,0
19-
DA:50,0
20-
DA:51,0
17+
DA:37,1
18+
DA:38,2
19+
DA:50,1
20+
DA:51,2
2121
LF:6
22-
LH:2
22+
LH:6
2323
end_of_record
2424
SF:lib/src/condition.dart
2525
DA:26,1

test/bool_test.dart

+48
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,54 @@ void main() {
3838
expect(list.notNullOrFalse, [true, false, true]);
3939
});
4040
});
41+
42+
group('NullableBoolExtension ifTrue and ifFalse tests', () {
43+
test('ifTrue executes action when boolean is true', () {
44+
bool actionExecuted = false;
45+
// ignore: unnecessary_nullable_for_final_variable_declarations
46+
const bool? nullableBool = true;
47+
nullableBool.ifTrue(() => actionExecuted = true);
48+
expect(actionExecuted, isTrue);
49+
});
50+
51+
test('ifTrue does not execute action when boolean is false', () {
52+
bool actionExecuted = false;
53+
// ignore: unnecessary_nullable_for_final_variable_declarations
54+
const bool? nullableBool = false;
55+
nullableBool.ifTrue(() => actionExecuted = true);
56+
expect(actionExecuted, isFalse);
57+
});
58+
59+
test('ifTrue does not execute action when boolean is null', () {
60+
bool actionExecuted = false;
61+
const bool? nullableBool = null;
62+
nullableBool.ifTrue(() => actionExecuted = true);
63+
expect(actionExecuted, isFalse);
64+
});
65+
66+
test('ifFalse executes action when boolean is false', () {
67+
bool actionExecuted = false;
68+
// ignore: unnecessary_nullable_for_final_variable_declarations
69+
const bool? nullableBool = false;
70+
nullableBool.ifFalse(() => actionExecuted = true);
71+
expect(actionExecuted, isTrue);
72+
});
73+
74+
test('ifFalse does not execute action when boolean is true', () {
75+
bool actionExecuted = false;
76+
// ignore: unnecessary_nullable_for_final_variable_declarations
77+
const bool? nullableBool = true;
78+
nullableBool.ifFalse(() => actionExecuted = true);
79+
expect(actionExecuted, isFalse);
80+
});
81+
82+
test('ifFalse does not execute action when boolean is null', () {
83+
bool actionExecuted = false;
84+
const bool? nullableBool = null;
85+
nullableBool.ifFalse(() => actionExecuted = true);
86+
expect(actionExecuted, isFalse);
87+
});
88+
});
4189
}
4290

4391
/// Client code example

0 commit comments

Comments
 (0)