From 37b38e60a11e8f30e1643b3c1e407385c38bef1e Mon Sep 17 00:00:00 2001 From: Minyewoo Date: Wed, 11 Oct 2023 13:12:26 +0300 Subject: [PATCH 1/9] Increased Dart SDK version constraints --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index d7b82b5..0d3359a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 0.0.5 homepage: https://github.com/a-givertzman/hmi_core environment: - sdk: '>=2.18.2 <3.0.0' + sdk: '>=3.0.0 <4.0.0' flutter: ">=1.17.0" dependencies: From 9020fd3ecd0c560350a6d96d7b32f455a8463736 Mon Sep 17 00:00:00 2001 From: Minyewoo Date: Wed, 11 Oct 2023 13:38:57 +0300 Subject: [PATCH 2/9] Github workflows | Raised Flutter version --- .github/workflows/analyze.yml | 2 +- .github/workflows/coverage.yaml | 2 +- .github/workflows/release.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/analyze.yml b/.github/workflows/analyze.yml index be37ae7..ef82b17 100644 --- a/.github/workflows/analyze.yml +++ b/.github/workflows/analyze.yml @@ -20,7 +20,7 @@ jobs: # - uses: subosito/flutter-action@v2 with: channel: 'stable' - version: 3.3.10 + version: 3.13.6 # - run: | # sudo apt-get update -y # sudo apt-get install -y ninja-build libgtk-3-dev diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 3927510..fa5a446 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -24,7 +24,7 @@ jobs: # - uses: subosito/flutter-action@v2 with: channel: 'stable' - version: 3.3.10 + version: 3.13.6 # - run: | # sudo apt-get update -y # sudo apt-get install -y ninja-build libgtk-3-dev diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9b2722d..966ba60 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,7 @@ jobs: uses: flutter-actions/setup-flutter@v2 with: channel: 'stable' - version: 3.3.10 + version: 3.13.6 - name: Clearing project run: flutter clean From e74774c811956b1b215cca05db2f05dfb1ec02e8 Mon Sep 17 00:00:00 2001 From: Minyewoo Date: Wed, 11 Oct 2023 15:18:35 +0300 Subject: [PATCH 3/9] Deprecated old Result implementation --- lib/src/core/result/result.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/src/core/result/result.dart b/lib/src/core/result/result.dart index 27d8713..8ddc167 100644 --- a/lib/src/core/result/result.dart +++ b/lib/src/core/result/result.dart @@ -3,6 +3,11 @@ import 'package:hmi_core/src/core/error/failure.dart'; /// /// Result contains or data of type T or error +@Deprecated( + 'Use implementation from hmi_core_result_new. ' + 'The current implementation will be removed as soon as ' + 'the new one if fully integrated with other libraries and projects.', +) class Result { final T? _data; final Failure? _error; From 241976fba7d86f13d1ef8fa902ad57b662aaca58 Mon Sep 17 00:00:00 2001 From: Minyewoo Date: Wed, 11 Oct 2023 15:20:15 +0300 Subject: [PATCH 4/9] Ignored deprecation warning for old Result tests --- test/unit/core/result/result_constructor_test.dart | 2 ++ test/unit/core/result/result_data_test.dart | 2 ++ test/unit/core/result/result_error_test.dart | 2 ++ test/unit/core/result/result_fold_test.dart | 2 ++ test/unit/core/result/result_has_data_test.dart | 2 ++ test/unit/core/result/result_has_error_test.dart | 2 ++ 6 files changed, 12 insertions(+) diff --git a/test/unit/core/result/result_constructor_test.dart b/test/unit/core/result/result_constructor_test.dart index b198962..19fcf4c 100644 --- a/test/unit/core/result/result_constructor_test.dart +++ b/test/unit/core/result/result_constructor_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: deprecated_member_use_from_same_package + import 'package:flutter_test/flutter_test.dart'; import 'package:hmi_core/hmi_core_failure.dart'; import 'package:hmi_core/hmi_core_result.dart'; diff --git a/test/unit/core/result/result_data_test.dart b/test/unit/core/result/result_data_test.dart index 38a6ab3..cf8e0dc 100644 --- a/test/unit/core/result/result_data_test.dart +++ b/test/unit/core/result/result_data_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: deprecated_member_use_from_same_package + import 'package:flutter_test/flutter_test.dart'; import 'package:hmi_core/hmi_core_failure.dart'; import 'package:hmi_core/hmi_core_result.dart'; diff --git a/test/unit/core/result/result_error_test.dart b/test/unit/core/result/result_error_test.dart index 4fc6c68..9443634 100644 --- a/test/unit/core/result/result_error_test.dart +++ b/test/unit/core/result/result_error_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: deprecated_member_use_from_same_package + import 'package:flutter_test/flutter_test.dart'; import 'package:hmi_core/hmi_core_failure.dart'; import 'package:hmi_core/hmi_core_result.dart'; diff --git a/test/unit/core/result/result_fold_test.dart b/test/unit/core/result/result_fold_test.dart index 232b6df..08092a2 100644 --- a/test/unit/core/result/result_fold_test.dart +++ b/test/unit/core/result/result_fold_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: deprecated_member_use_from_same_package + import 'package:flutter_test/flutter_test.dart'; import 'package:hmi_core/hmi_core_failure.dart'; import 'package:hmi_core/hmi_core_result.dart'; diff --git a/test/unit/core/result/result_has_data_test.dart b/test/unit/core/result/result_has_data_test.dart index 9b57c83..8b0d289 100644 --- a/test/unit/core/result/result_has_data_test.dart +++ b/test/unit/core/result/result_has_data_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: deprecated_member_use_from_same_package + import 'package:flutter_test/flutter_test.dart'; import 'package:hmi_core/hmi_core_failure.dart'; import 'package:hmi_core/hmi_core_result.dart'; diff --git a/test/unit/core/result/result_has_error_test.dart b/test/unit/core/result/result_has_error_test.dart index a7b3a6f..b4f689e 100644 --- a/test/unit/core/result/result_has_error_test.dart +++ b/test/unit/core/result/result_has_error_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: deprecated_member_use_from_same_package + import 'package:flutter_test/flutter_test.dart'; import 'package:hmi_core/hmi_core_failure.dart'; import 'package:hmi_core/hmi_core_result.dart'; From b67ee66b55e5e89a6fbcdeab1ab2f0b910572264 Mon Sep 17 00:00:00 2001 From: Minyewoo Date: Wed, 11 Oct 2023 17:44:52 +0300 Subject: [PATCH 5/9] Implemented new Result with tests --- lib/hmi_core_result_new.dart | 3 ++ lib/src/core/result_new/result.dart | 21 +++++++++++++ .../new_result_constructor_test.dart | 19 ++++++++++++ .../core/result_new/new_result_fold_test.dart | 30 +++++++++++++++++++ .../core/result_new/new_result_is_test.dart | 26 ++++++++++++++++ 5 files changed, 99 insertions(+) create mode 100644 lib/hmi_core_result_new.dart create mode 100644 lib/src/core/result_new/result.dart create mode 100644 test/unit/core/result_new/new_result_constructor_test.dart create mode 100644 test/unit/core/result_new/new_result_fold_test.dart create mode 100644 test/unit/core/result_new/new_result_is_test.dart diff --git a/lib/hmi_core_result_new.dart b/lib/hmi_core_result_new.dart new file mode 100644 index 0000000..df3a928 --- /dev/null +++ b/lib/hmi_core_result_new.dart @@ -0,0 +1,3 @@ +library hmi_core_result_new; + +export 'src/core/result_new/result.dart'; \ No newline at end of file diff --git a/lib/src/core/result_new/result.dart b/lib/src/core/result_new/result.dart new file mode 100644 index 0000000..aeb6fc4 --- /dev/null +++ b/lib/src/core/result_new/result.dart @@ -0,0 +1,21 @@ +import 'package:hmi_core/src/core/error/failure.dart'; +/// +/// Containing either value of type [V] or error of type [E] +sealed class Result {} +/// +/// Containing either value of type [V] or [Failure] +typedef FailableResult = Result; +/// +/// Successful [Result] with [value]. +final class Ok implements Result { + final V value; + /// Successful [Result] with [value]. + const Ok(this.value); +} +/// +/// Unsuccessful [Result] with [error]. +final class Err implements Result { + final E error; + /// Unsuccessful [Result] with [error]. + const Err(this.error); +} \ No newline at end of file diff --git a/test/unit/core/result_new/new_result_constructor_test.dart b/test/unit/core/result_new/new_result_constructor_test.dart new file mode 100644 index 0000000..6c6ed8c --- /dev/null +++ b/test/unit/core/result_new/new_result_constructor_test.dart @@ -0,0 +1,19 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:hmi_core/hmi_core_failure.dart'; +import 'package:hmi_core/hmi_core_result_new.dart'; + +void main() { + group('Result constructor of', () { + test('Ok completes if data is provided', () { + expect(() => const Ok('test'), returnsNormally); + }); + test('Err completes if error is provided', () { + expect( + () => Err( + Failure(message: '', stackTrace: StackTrace.current), + ), + returnsNormally, + ); + }); + }); +} \ No newline at end of file diff --git a/test/unit/core/result_new/new_result_fold_test.dart b/test/unit/core/result_new/new_result_fold_test.dart new file mode 100644 index 0000000..84aa19f --- /dev/null +++ b/test/unit/core/result_new/new_result_fold_test.dart @@ -0,0 +1,30 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:hmi_core/hmi_core_failure.dart'; +import 'package:hmi_core/hmi_core_result_new.dart'; + +void main() { + group('Result fold', () { + const Result resultWithData = Ok('test'); + final Result resultWithError = Err( + Failure(message: '', stackTrace: StackTrace.current), + ); + const valueIfData = 1; + const valueIfError = 0; + int onData(T data) => valueIfData; + int onError(Failure error) => valueIfError; + test('calls onData if data is provided', () { + final foldResult = switch(resultWithData) { + Ok(:final value) => onData(value), + Err(:final error) => onError(error), + }; + expect(foldResult, valueIfData); + }); + test('calls onError if no data', () { + final foldResult = switch(resultWithError) { + Ok(:final value) => onData(value), + Err(:final error) => onError(error), + }; + expect(foldResult, valueIfError); + }); + }); +} \ No newline at end of file diff --git a/test/unit/core/result_new/new_result_is_test.dart b/test/unit/core/result_new/new_result_is_test.dart new file mode 100644 index 0000000..d9bd827 --- /dev/null +++ b/test/unit/core/result_new/new_result_is_test.dart @@ -0,0 +1,26 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:hmi_core/hmi_core_failure.dart'; +import 'package:hmi_core/hmi_core_result_new.dart'; + +void main() { + group('Result is', () { + const Result resultWithData = Ok('test'); + final Result resultWithError = Err( + Failure(message: '', stackTrace: StackTrace.current), + ); + test('Ok returns true if data is provided', () { + expect(resultWithData is Ok, isTrue); + + }); + test('Err returns false if data is provided', () { + expect(resultWithData is Err, isFalse); + + }); + test('Ok returns false if error is provided', () { + expect(resultWithError is Ok, isFalse); + }); + test('Err returns true if error is provided', () { + expect(resultWithError is Err, isTrue); + }); + }); +} \ No newline at end of file From ceb58d21e6746f64171a443a061958f9d2d9766f Mon Sep 17 00:00:00 2001 From: Minyewoo Date: Wed, 11 Oct 2023 18:02:08 +0300 Subject: [PATCH 6/9] Added tests for new Result --- .../core/result_new/new_result_fold_test.dart | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/unit/core/result_new/new_result_fold_test.dart b/test/unit/core/result_new/new_result_fold_test.dart index 84aa19f..523738b 100644 --- a/test/unit/core/result_new/new_result_fold_test.dart +++ b/test/unit/core/result_new/new_result_fold_test.dart @@ -11,7 +11,7 @@ void main() { const valueIfData = 1; const valueIfError = 0; int onData(T data) => valueIfData; - int onError(Failure error) => valueIfError; + int onError(T error) => valueIfError; test('calls onData if data is provided', () { final foldResult = switch(resultWithData) { Ok(:final value) => onData(value), @@ -26,5 +26,21 @@ void main() { }; expect(foldResult, valueIfError); }); + test('works perfectly even if data is void', () { + const Result result = Ok(null); + final foldResult = switch(result) { + Ok(:final value) => onData(value), + Err(:final error) => onError(error), + }; + expect(foldResult, valueIfData); + }); + test('works perfectly even if error is void', () { + const Result result = Err(null); + final foldResult = switch(result) { + Ok(:final value) => onData(value), + Err(:final error) => onError(error), + }; + expect(foldResult, valueIfError); + }); }); } \ No newline at end of file From ce4b97cfd56e653b230942be9daaf5675d574912 Mon Sep 17 00:00:00 2001 From: Konstantin Trushov Date: Mon, 30 Oct 2023 20:00:40 +0300 Subject: [PATCH 7/9] Renamed FailingResult to ResultF --- lib/src/core/result_new/result.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/core/result_new/result.dart b/lib/src/core/result_new/result.dart index aeb6fc4..f22c0ca 100644 --- a/lib/src/core/result_new/result.dart +++ b/lib/src/core/result_new/result.dart @@ -4,7 +4,7 @@ import 'package:hmi_core/src/core/error/failure.dart'; sealed class Result {} /// /// Containing either value of type [V] or [Failure] -typedef FailableResult = Result; +typedef ResultF = Result; /// /// Successful [Result] with [value]. final class Ok implements Result { @@ -18,4 +18,4 @@ final class Err implements Result { final E error; /// Unsuccessful [Result] with [error]. const Err(this.error); -} \ No newline at end of file +} From e0372a4f78654858807575a4d790fc60079d6094 Mon Sep 17 00:00:00 2001 From: Minyewoo Date: Tue, 21 Nov 2023 19:40:43 +0300 Subject: [PATCH 8/9] Added more test data for new Result --- .../new_result_constructor_test.dart | 20 +++-- .../core/result_new/new_result_fold_test.dart | 77 +++++++++++-------- test/unit/core/result_new/test_data.dart | 27 +++++++ 3 files changed, 85 insertions(+), 39 deletions(-) create mode 100644 test/unit/core/result_new/test_data.dart diff --git a/test/unit/core/result_new/new_result_constructor_test.dart b/test/unit/core/result_new/new_result_constructor_test.dart index 6c6ed8c..be33ae7 100644 --- a/test/unit/core/result_new/new_result_constructor_test.dart +++ b/test/unit/core/result_new/new_result_constructor_test.dart @@ -2,18 +2,24 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:hmi_core/hmi_core_failure.dart'; import 'package:hmi_core/hmi_core_result_new.dart'; +import 'test_data.dart'; + void main() { group('Result constructor of', () { test('Ok completes if data is provided', () { - expect(() => const Ok('test'), returnsNormally); + for(final value in testData) { + expect(() => Ok(value), returnsNormally); + } }); test('Err completes if error is provided', () { - expect( - () => Err( - Failure(message: '', stackTrace: StackTrace.current), - ), - returnsNormally, - ); + for(final value in testData) { + expect( + () => Err( + Failure(message: value, stackTrace: StackTrace.current), + ), + returnsNormally, + ); + } }); }); } \ No newline at end of file diff --git a/test/unit/core/result_new/new_result_fold_test.dart b/test/unit/core/result_new/new_result_fold_test.dart index 523738b..16d1b0a 100644 --- a/test/unit/core/result_new/new_result_fold_test.dart +++ b/test/unit/core/result_new/new_result_fold_test.dart @@ -1,46 +1,59 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:hmi_core/hmi_core_failure.dart'; import 'package:hmi_core/hmi_core_result_new.dart'; +import 'test_data.dart'; void main() { group('Result fold', () { - const Result resultWithData = Ok('test'); - final Result resultWithError = Err( - Failure(message: '', stackTrace: StackTrace.current), - ); - const valueIfData = 1; - const valueIfError = 0; - int onData(T data) => valueIfData; - int onError(T error) => valueIfError; - test('calls onData if data is provided', () { - final foldResult = switch(resultWithData) { - Ok(:final value) => onData(value), - Err(:final error) => onError(error), - }; - expect(foldResult, valueIfData); + test('matches Ok if data is provided', () { + for (final value in testData) { + final Result result = Ok(value); + final foldResult = switch(result) { + Ok(:final value) => value, + Err(:final error) => error, + }; + expect(foldResult, value); + } }); - test('calls onError if no data', () { - final foldResult = switch(resultWithError) { - Ok(:final value) => onData(value), - Err(:final error) => onError(error), - }; - expect(foldResult, valueIfError); + test('matches Err if no data', () { + for (final error in testData) { + final Result result = Err(error); + final foldResult = switch(result) { + Ok(:final value) => value, + Err(:final error) => error, + }; + expect(foldResult, error); + } }); test('works perfectly even if data is void', () { - const Result result = Ok(null); - final foldResult = switch(result) { - Ok(:final value) => onData(value), - Err(:final error) => onError(error), - }; - expect(foldResult, valueIfData); + for (final value in testData) { + // ignore: void_checks + final Result result = Ok(value); + expect( + () { + return switch(result) { + Ok(:final value) => value, + Err(:final error) => error, + }; + }, + returnsNormally, + ); + } }); test('works perfectly even if error is void', () { - const Result result = Err(null); - final foldResult = switch(result) { - Ok(:final value) => onData(value), - Err(:final error) => onError(error), - }; - expect(foldResult, valueIfError); + for (final error in testData) { + // ignore: void_checks + final Result result = Err(error); + expect( + () { + return switch(result) { + Ok(:final value) => value, + Err(:final error) => error, + }; + }, + returnsNormally, + ); + } }); }); } \ No newline at end of file diff --git a/test/unit/core/result_new/test_data.dart b/test/unit/core/result_new/test_data.dart new file mode 100644 index 0000000..3819bbd --- /dev/null +++ b/test/unit/core/result_new/test_data.dart @@ -0,0 +1,27 @@ +final class ForTestOptionOnly { + final String value; + const ForTestOptionOnly(this.value); +} +const _maxInt64 = 0x7FFFFFFFFFFFFFFF; +const _minInt64 = -0x8000000000000000; +const testData = [ + _maxInt64, + _minInt64, + 0, + 353465, + 45, + -3456, + ForTestOptionOnly('value'), + ForTestOptionOnly(''), + ForTestOptionOnly('123'), + true, + false, + double.maxFinite, + double.minPositive + -double.maxFinite, + 0.0, + 1.234, + 234.4, + -0.45676, + -346.786, +]; \ No newline at end of file From b00c837b8b204572c859902e236d234426ea57f2 Mon Sep 17 00:00:00 2001 From: Minyewoo Date: Tue, 21 Nov 2023 19:41:27 +0300 Subject: [PATCH 9/9] Removed silly test for new Result --- .../core/result_new/new_result_is_test.dart | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 test/unit/core/result_new/new_result_is_test.dart diff --git a/test/unit/core/result_new/new_result_is_test.dart b/test/unit/core/result_new/new_result_is_test.dart deleted file mode 100644 index d9bd827..0000000 --- a/test/unit/core/result_new/new_result_is_test.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; -import 'package:hmi_core/hmi_core_failure.dart'; -import 'package:hmi_core/hmi_core_result_new.dart'; - -void main() { - group('Result is', () { - const Result resultWithData = Ok('test'); - final Result resultWithError = Err( - Failure(message: '', stackTrace: StackTrace.current), - ); - test('Ok returns true if data is provided', () { - expect(resultWithData is Ok, isTrue); - - }); - test('Err returns false if data is provided', () { - expect(resultWithData is Err, isFalse); - - }); - test('Ok returns false if error is provided', () { - expect(resultWithError is Ok, isFalse); - }); - test('Err returns true if error is provided', () { - expect(resultWithError is Err, isTrue); - }); - }); -} \ No newline at end of file