From 82032edbe30bbba7247a559aa4d23d49a9b2f89e Mon Sep 17 00:00:00 2001 From: Petrus Nguyen Thai Hoc Date: Thu, 12 Oct 2023 18:46:27 +0700 Subject: [PATCH] deon --- example/lib/dialog.dart | 4 +-- example/lib/snippet.dart | 2 +- test/streams_test.dart | 70 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/example/lib/dialog.dart b/example/lib/dialog.dart index 319131d..b60e8a9 100644 --- a/example/lib/dialog.dart +++ b/example/lib/dialog.dart @@ -36,7 +36,7 @@ extension DialogExtensions on BuildContext { } try { - await rxPrefs.executeUpdateStringList(key, (currentList) { + await rxPrefs.updateStringList(key, (currentList) { final list = currentList ?? const []; if (list.contains(string)) { throw StateError('Duplicated $string!'); @@ -77,7 +77,7 @@ extension DialogExtensions on BuildContext { } try { - await rxPrefs.executeUpdateStringList( + await rxPrefs.updateStringList( key, (currentList) => [ for (final s in (currentList ?? const [])) diff --git a/example/lib/snippet.dart b/example/lib/snippet.dart index 83e4655..cef26e2 100644 --- a/example/lib/snippet.dart +++ b/example/lib/snippet.dart @@ -49,6 +49,6 @@ void main() async { ); // Or read-modify-write style. - await rxPrefs.executeUpdateStringList( + await rxPrefs.updateStringList( idsKey, (currentIds) => [...?currentIds, 'new id']); } diff --git a/test/streams_test.dart b/test/streams_test.dart index a8c9496..89745dd 100644 --- a/test/streams_test.dart +++ b/test/streams_test.dart @@ -398,10 +398,24 @@ void main() { emitsInOrder([anything, expected]), ); expect(await rxPrefs.getBool('bool'), initial); + // ignore: deprecated_member_use_from_same_package await rxPrefs.executeUpdateBool('bool', (s) => !s!); expect(await rxPrefs.getBool('bool'), expected); }); + test('updateBool', () async { + final initial = kTestValues['flutter.bool'] as bool; + final expected = !initial; + + expect( + rxPrefs.getBoolStream('bool'), + emitsInOrder([anything, expected]), + ); + expect(await rxPrefs.getBool('bool'), initial); + await rxPrefs.updateBool('bool', (s) => !s!); + expect(await rxPrefs.getBool('bool'), expected); + }); + test('executeUpdateDouble', () async { final initial = kTestValues['flutter.double'] as double; final expected = initial + 1; @@ -411,10 +425,24 @@ void main() { emitsInOrder([anything, expected]), ); expect(await rxPrefs.getDouble('double'), initial); + // ignore: deprecated_member_use_from_same_package await rxPrefs.executeUpdateDouble('double', (s) => s! + 1); expect(await rxPrefs.getDouble('double'), expected); }); + test('updateDouble', () async { + final initial = kTestValues['flutter.double'] as double; + final expected = initial + 1; + + expect( + rxPrefs.getDoubleStream('double'), + emitsInOrder([anything, expected]), + ); + expect(await rxPrefs.getDouble('double'), initial); + await rxPrefs.updateDouble('double', (s) => s! + 1); + expect(await rxPrefs.getDouble('double'), expected); + }); + test('executeUpdateInt', () async { final initial = kTestValues['flutter.int'] as int; final expected = initial + 1; @@ -424,10 +452,24 @@ void main() { emitsInOrder([anything, expected]), ); expect(await rxPrefs.getInt('int'), initial); + // ignore: deprecated_member_use_from_same_package await rxPrefs.executeUpdateInt('int', (s) => s! + 1); expect(await rxPrefs.getInt('int'), expected); }); + test('updateInt', () async { + final initial = kTestValues['flutter.int'] as int; + final expected = initial + 1; + + expect( + rxPrefs.getIntStream('int'), + emitsInOrder([anything, expected]), + ); + expect(await rxPrefs.getInt('int'), initial); + await rxPrefs.updateInt('int', (s) => s! + 1); + expect(await rxPrefs.getInt('int'), expected); + }); + test('executeUpdateString', () async { final initial = kTestValues['flutter.String'] as String; final expected = initial + '1'; @@ -437,10 +479,24 @@ void main() { emitsInOrder([anything, expected]), ); expect(await rxPrefs.getString('String'), initial); + // ignore: deprecated_member_use_from_same_package await rxPrefs.executeUpdateString('String', (s) => s! + '1'); expect(await rxPrefs.getString('String'), expected); }); + test('updateString', () async { + final initial = kTestValues['flutter.String'] as String; + final expected = initial + '1'; + + expect( + rxPrefs.getStringStream('String'), + emitsInOrder([anything, expected]), + ); + expect(await rxPrefs.getString('String'), initial); + await rxPrefs.updateString('String', (s) => s! + '1'); + expect(await rxPrefs.getString('String'), expected); + }); + test('executeUpdateStringList', () async { final initial = kTestValues['flutter.List'] as List; final expected = [...initial, '1']; @@ -450,8 +506,22 @@ void main() { emitsInOrder([anything, expected]), ); expect(await rxPrefs.getStringList('List'), initial); + // ignore: deprecated_member_use_from_same_package await rxPrefs.executeUpdateStringList('List', (s) => [...s!, '1']); expect(await rxPrefs.getStringList('List'), expected); }); + + test('updateStringList', () async { + final initial = kTestValues['flutter.List'] as List; + final expected = [...initial, '1']; + + expect( + rxPrefs.getStringListStream('List'), + emitsInOrder([anything, expected]), + ); + expect(await rxPrefs.getStringList('List'), initial); + await rxPrefs.updateStringList('List', (s) => [...s!, '1']); + expect(await rxPrefs.getStringList('List'), expected); + }); }); }