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
|
import 'package:flutter_test/flutter_test.dart';
import 'package:uvok_epaper_badge/extensions/list_ext.dart';
void main() {
group('ListExt.addOrReplaceWhere', () {
test('adds element when predicate returns false for all', () {
final list = [1, 2, 3];
list.addOrReplaceWhere(4, (x) => x == 5);
expect(list, equals([1, 2, 3, 4]));
});
test('replaces element when predicate matches and no replaceCondition', () {
final list = [1, 2, 3];
list.addOrReplaceWhere(99, (x) => x == 2);
expect(list, equals([1, 99, 3]));
});
test('does not replace if replaceCondition returns false', () {
final list = [1, 2, 3];
list.addOrReplaceWhere(99, (x) => x == 2, replaceCondition: (x) => false);
expect(list, equals([1, 2, 3]));
});
test('replaces if replaceCondition returns true', () {
final list = [1, 2, 3];
list.addOrReplaceWhere(99, (x) => x == 2, replaceCondition: (x) => true);
expect(list, equals([1, 99, 3]));
});
test('only replaces the first matching element', () {
final list = [2, 2, 3];
list.addOrReplaceWhere(99, (x) => x == 2);
expect(list, equals([99, 2, 3]));
});
});
}
|