diff options
author | uvok | 2025-08-02 13:55:48 +0200 |
---|---|---|
committer | uvok | 2025-08-02 13:55:48 +0200 |
commit | 9d18247793203275f0118b13f8e10d12acfdaf67 (patch) | |
tree | 2e85f69869d414a250f1c61f5ac5afb877f5adc6 /test/list_ext_test.dart | |
parent | 282884ee86dc3d1d68e9636e3739cbedf639edef (diff) |
Add tests for extension
Diffstat (limited to 'test/list_ext_test.dart')
-rw-r--r-- | test/list_ext_test.dart | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/list_ext_test.dart b/test/list_ext_test.dart new file mode 100644 index 0000000..cb6e68c --- /dev/null +++ b/test/list_ext_test.dart @@ -0,0 +1,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])); + }); + }); +} |