From 268a156ef586ba87e4704dd6472eb5ec3535f41b Mon Sep 17 00:00:00 2001 From: Francesco Iapicca Date: Wed, 17 Apr 2024 16:19:28 +0300 Subject: [PATCH 1/7] remove yak_result borrowing from 'extension_type_unions' --- packages/yak_result/lib/src/all.dart | 3 - packages/yak_result/lib/src/classes/all.dart | 3 - .../lib/src/classes/exceptions.dart | 7 + .../yak_result/lib/src/classes/failure.dart | 35 +- .../yak_result/lib/src/classes/result.dart | 71 ++- .../yak_result/lib/src/classes/success.dart | 52 -- .../lib/src/classes/void_result.dart | 58 ++ .../yak_result/lib/src/extensions/all.dart | 7 +- .../lib/src/extensions/as_failure.dart | 11 - .../lib/src/extensions/as_success.dart | 20 - .../lib/src/extensions/as_void.dart | 7 - .../lib/src/extensions/failure_recast.dart | 6 - .../yak_result/lib/src/extensions/is_x.dart | 11 - .../lib/src/extensions/iterable_combine.dart | 107 +++- .../extensions/iterable_combine_unary.dart | 41 -- .../yak_result/lib/src/extensions/recast.dart | 25 + packages/yak_result/lib/src/typedef/all.dart | 2 +- .../lib/src/typedef/future_result.dart | 10 +- .../lib/src/typedef/nullary_function.dart | 14 +- .../lib/src/typedef/unary_function.dart | 13 +- packages/yak_result/lib/yak_result.dart | 6 +- .../yak_result/test/classes/failure_test.dart | 16 +- .../yak_result/test/classes/result_test.dart | 188 +++--- .../yak_result/test/classes/success_test.dart | 251 -------- .../test/classes/void_result_test.dart | 129 +++++ .../test/extensions/as_failure_test.dart | 116 ---- .../test/extensions/as_success_test.dart | 115 ---- .../test/extensions/as_void_test.dart | 43 -- .../test/extensions/failure_recast_test.dart | 40 -- .../yak_result/test/extensions/is_x_test.dart | 150 ----- .../extensions/iterable_combine_test.dart | 543 ++++++++++++++++-- .../iterable_combine_unary_test.dart | 266 --------- .../test/extensions/recast_test.dart | 123 ++++ 33 files changed, 1089 insertions(+), 1400 deletions(-) delete mode 100644 packages/yak_result/lib/src/all.dart delete mode 100644 packages/yak_result/lib/src/classes/all.dart create mode 100644 packages/yak_result/lib/src/classes/exceptions.dart delete mode 100644 packages/yak_result/lib/src/classes/success.dart create mode 100644 packages/yak_result/lib/src/classes/void_result.dart delete mode 100644 packages/yak_result/lib/src/extensions/as_failure.dart delete mode 100644 packages/yak_result/lib/src/extensions/as_success.dart delete mode 100644 packages/yak_result/lib/src/extensions/as_void.dart delete mode 100644 packages/yak_result/lib/src/extensions/failure_recast.dart delete mode 100644 packages/yak_result/lib/src/extensions/is_x.dart delete mode 100644 packages/yak_result/lib/src/extensions/iterable_combine_unary.dart create mode 100644 packages/yak_result/lib/src/extensions/recast.dart delete mode 100644 packages/yak_result/test/classes/success_test.dart create mode 100644 packages/yak_result/test/classes/void_result_test.dart delete mode 100644 packages/yak_result/test/extensions/as_failure_test.dart delete mode 100644 packages/yak_result/test/extensions/as_success_test.dart delete mode 100644 packages/yak_result/test/extensions/as_void_test.dart delete mode 100644 packages/yak_result/test/extensions/failure_recast_test.dart delete mode 100644 packages/yak_result/test/extensions/is_x_test.dart delete mode 100644 packages/yak_result/test/extensions/iterable_combine_unary_test.dart create mode 100644 packages/yak_result/test/extensions/recast_test.dart diff --git a/packages/yak_result/lib/src/all.dart b/packages/yak_result/lib/src/all.dart deleted file mode 100644 index fe2bc6c6..00000000 --- a/packages/yak_result/lib/src/all.dart +++ /dev/null @@ -1,3 +0,0 @@ -export 'classes/all.dart'; -export 'extensions/all.dart'; -export 'typedef/all.dart'; diff --git a/packages/yak_result/lib/src/classes/all.dart b/packages/yak_result/lib/src/classes/all.dart deleted file mode 100644 index 850a488a..00000000 --- a/packages/yak_result/lib/src/classes/all.dart +++ /dev/null @@ -1,3 +0,0 @@ -export 'failure.dart'; -export 'result.dart'; -export 'success.dart'; diff --git a/packages/yak_result/lib/src/classes/exceptions.dart b/packages/yak_result/lib/src/classes/exceptions.dart new file mode 100644 index 00000000..66877d5f --- /dev/null +++ b/packages/yak_result/lib/src/classes/exceptions.dart @@ -0,0 +1,7 @@ +import 'package:meta/meta.dart'; + +@internal +sealed class ResultExceptions { + static final notFailureException = Exception('Result is a Success'); + static final notSuccessException = Exception('Result is a Failure'); +} diff --git a/packages/yak_result/lib/src/classes/failure.dart b/packages/yak_result/lib/src/classes/failure.dart index 8e35666b..deb91915 100644 --- a/packages/yak_result/lib/src/classes/failure.dart +++ b/packages/yak_result/lib/src/classes/failure.dart @@ -1,36 +1,29 @@ import 'package:meta/meta.dart'; -import 'package:yak_utils/yak_utils.dart'; - -import '../all.dart'; /// represent a failure of a function -class Failure extends Result implements ValueResult, VoidResult { +class Failure { final Object reason; final StackTrace stackTrace; - const Failure([ - this.reason = const Object(), - this.stackTrace = StackTrace.empty, - ]); - - factory Failure.fromError(Error error) => Failure( - error, - error.stackTrace ?? StackTrace.empty, - ); + const Failure(this.reason, this.stackTrace); + const factory Failure.empty() = _EmptyFailure; @override @nonVirtual - bool operator ==(Object other) => hashCode == other.hashCode; + bool operator ==(Object other) => + other is Failure && hashCode == other.hashCode; @override @nonVirtual - int get hashCode => Object.hashAll([runtimeType, reason, stackTrace]); + int get hashCode => Object.hash(reason, stackTrace); +} + +final class _EmptyFailure implements Failure { + const _EmptyFailure(); @override - @nonVirtual - Json toJson() => { - 'Result': 'Failure', - 'reason': '${reason.runtimeType}', - 'stackTrace': '$stackTrace', - }; + final reason = const Object(); + + @override + final stackTrace = StackTrace.empty; } diff --git a/packages/yak_result/lib/src/classes/result.dart b/packages/yak_result/lib/src/classes/result.dart index 041e78fb..cfc45951 100644 --- a/packages/yak_result/lib/src/classes/result.dart +++ b/packages/yak_result/lib/src/classes/result.dart @@ -1,25 +1,58 @@ -import 'package:meta/meta.dart'; -import 'package:yak_utils/yak_utils.dart'; +import 'exceptions.dart'; +import 'failure.dart'; -/// represent the outcome of a function -abstract class Result { - /// allows a const constructor - const Result(); +extension type Result._(Object result) { + bool get isSuccess => result is T; + bool get isFailure => result is Failure; + const Result.success(T this.result); + Result._failure(Failure this.result); - @override - @nonVirtual - String toString() => '${toJson()}'; + factory Result.failure([ + Object reason = const Object(), + StackTrace stackTrace = StackTrace.empty, + ]) => + Result._failure(Failure(reason, stackTrace)); - /// allow compatibility with [dart:convert] - Json toJson(); -} + Failure get asFailure => isFailure + ? result as Failure + : throw ResultExceptions.notFailureException; -/// a result returning value -abstract class ValueResult extends Result { - const ValueResult(); + T get asSuccess => + isSuccess ? result as T : throw ResultExceptions.notSuccessException; } -/// a result without returning value -abstract class VoidResult extends Result { - const VoidResult(); -} +/// inspired by [https://github.com/eernstg/extension_type_unions] +// extension UnionInjectExtension on X { +// Union2 get u21 => Union2.in1(this); +// Union2 get u22 => Union2.in2(this); +// } + +// /// Emulate the union of the types [X1] and [X2]. +// extension type Union2._(Object? value) { +// /// Create a [Union2] value from the first type argument. +// Union2.in1(X1 this.value); + +// /// Create a [Union2] value from the second type argument. +// Union2.in2(X2 this.value); + +// /// Return true iff this [Union2] has type [X1] or [X2]. +// bool get isValid => value is X1 || value is X2; + +// /// Return the [value] if it has type [X1], otherwise null. +// X1? get as1OrNull => value is X1 ? value as X1 : null; + +// /// Return the [value] if it has type [X2], otherwise null. +// X2? get as2OrNull => value is X2 ? value as X2 : null; + +// /// Return the [value] if it has type [X1], otherwise throw. +// X1 get as1 => value as X1; + +// /// Return the [value] if it has type [X2], otherwise throw. +// X2 get as2 => value as X2; + +// /// Return type iff the [value] has type [X1]. +// bool get is1 => value is X1; + +// /// Return type iff the [value] has type [X2]. +// bool get is2 => value is X2; +// } diff --git a/packages/yak_result/lib/src/classes/success.dart b/packages/yak_result/lib/src/classes/success.dart deleted file mode 100644 index 7930afb2..00000000 --- a/packages/yak_result/lib/src/classes/success.dart +++ /dev/null @@ -1,52 +0,0 @@ -import 'package:meta/meta.dart'; -import 'package:yak_utils/yak_utils.dart'; - -import '../all.dart'; - -/// represent a success of a function -abstract class Success implements Result { - const Success(); - static ValueSuccess value(S value) => ValueSuccess(value); - static VoidSuccess get empty => const VoidSuccess(); -} - -/// represent a success of a function -class ValueSuccess extends Success implements ValueResult { - /// has a const constructor - const ValueSuccess(this.value); - - /// hold the value from a function - final T value; - - @override - @nonVirtual - bool operator ==(Object other) => hashCode == other.hashCode; - - @override - @nonVirtual - int get hashCode => Object.hash(runtimeType, value); - - @override - @nonVirtual - Json toJson() => { - 'Result': 'Success', - 'value': '$value', - }; -} - -/// a result without returning value -class VoidSuccess extends Success implements VoidResult { - const VoidSuccess(); - - @override - @nonVirtual - bool operator ==(Object other) => hashCode == other.hashCode; - - @override - @nonVirtual - int get hashCode => runtimeType.hashCode; - - @override - @nonVirtual - Json toJson() => const {'Result': 'Success'}; -} diff --git a/packages/yak_result/lib/src/classes/void_result.dart b/packages/yak_result/lib/src/classes/void_result.dart new file mode 100644 index 00000000..b9d0bfc6 --- /dev/null +++ b/packages/yak_result/lib/src/classes/void_result.dart @@ -0,0 +1,58 @@ +import 'package:meta/meta.dart'; + +import 'exceptions.dart'; +import 'failure.dart'; + +@immutable +abstract class VoidResult { + const VoidResult(); + + bool get isSuccess; + + @nonVirtual + bool get isFailure => !isSuccess; + + Failure get asFailure; + + const factory VoidResult.success() = VoidSuccess; + const factory VoidResult.failure([Object reason, StackTrace stackTrace]) = + VoidFailure; + + @override + @nonVirtual + bool operator ==(Object other) => + other is VoidResult && hashCode == other.hashCode; + + @override + @nonVirtual + int get hashCode => Object.hash(isSuccess, asFailure); +} + +@immutable +final class VoidSuccess extends VoidResult { + const VoidSuccess(); + + @override + final isSuccess = true; + + @override + Failure get asFailure => throw ResultExceptions.notFailureException; +} + +@immutable +final class VoidFailure extends VoidResult implements Failure { + const VoidFailure([ + this.reason = const Object(), + this.stackTrace = StackTrace.empty, + ]); + @override + final Object reason; + @override + final StackTrace stackTrace; + + @override + final isSuccess = false; + + @override + Failure get asFailure => this; +} diff --git a/packages/yak_result/lib/src/extensions/all.dart b/packages/yak_result/lib/src/extensions/all.dart index 002b51de..69262b0d 100644 --- a/packages/yak_result/lib/src/extensions/all.dart +++ b/packages/yak_result/lib/src/extensions/all.dart @@ -1,7 +1,2 @@ -export 'is_x.dart'; -export 'as_failure.dart'; -export 'failure_recast.dart'; -export 'as_void.dart'; -export 'as_success.dart'; +export 'recast.dart'; export 'iterable_combine.dart'; -export 'iterable_combine_unary.dart'; diff --git a/packages/yak_result/lib/src/extensions/as_failure.dart b/packages/yak_result/lib/src/extensions/as_failure.dart deleted file mode 100644 index f35cf81b..00000000 --- a/packages/yak_result/lib/src/extensions/as_failure.dart +++ /dev/null @@ -1,11 +0,0 @@ -import '../all.dart'; - -/// syntactic sugar to easily access the data of a failed [Result] -extension ResultAsFailureX on Result { - /// the user takes responsability on the result being a Failure - Failure get failure => - isFailure ? this as Failure : throw Exception('Result is a Success'); - - /// the user takes responsability on the result being a Success - Failure? get failureOrNull => isFailure ? this as Failure : null; -} diff --git a/packages/yak_result/lib/src/extensions/as_success.dart b/packages/yak_result/lib/src/extensions/as_success.dart deleted file mode 100644 index 99baa93d..00000000 --- a/packages/yak_result/lib/src/extensions/as_success.dart +++ /dev/null @@ -1,20 +0,0 @@ -import '../all.dart'; - -/// syntactic sugar to easily access the data of a sucessful [ValueResult] -extension ValueResultAsSuccess on ValueResult { - ValueSuccess get success => isSuccess - ? this as ValueSuccess - : throw Exception('Result is a Failure'); - - ValueSuccess? get successOrNull => - isSuccess ? this as ValueSuccess : null; -} - -/// syntactic sugar to easily access the data of a sucessful [VoidResult] -extension VoidResultAsSuccess on VoidResult { - VoidSuccess get success => - isSuccess ? this as VoidSuccess : throw Exception('Result is a Failure'); - - VoidSuccess? get successOrNull => - isSuccess ? this as VoidSuccess : null; -} diff --git a/packages/yak_result/lib/src/extensions/as_void.dart b/packages/yak_result/lib/src/extensions/as_void.dart deleted file mode 100644 index 1ecb6305..00000000 --- a/packages/yak_result/lib/src/extensions/as_void.dart +++ /dev/null @@ -1,7 +0,0 @@ -import '../all.dart'; - -/// syntactic sugar to cast a [Result] to [VoidResult] -extension ValueResultAsVoidX on Result { - VoidResult get asVoid => - isFailure ? failure.recast() : const VoidSuccess(); -} diff --git a/packages/yak_result/lib/src/extensions/failure_recast.dart b/packages/yak_result/lib/src/extensions/failure_recast.dart deleted file mode 100644 index a2ed3b30..00000000 --- a/packages/yak_result/lib/src/extensions/failure_recast.dart +++ /dev/null @@ -1,6 +0,0 @@ -import '../all.dart'; - -/// recast a [Failure] with to the desired [Type] -extension RecastFailureX on Failure { - Failure recast() => Failure(reason, stackTrace); -} diff --git a/packages/yak_result/lib/src/extensions/is_x.dart b/packages/yak_result/lib/src/extensions/is_x.dart deleted file mode 100644 index 506fbd10..00000000 --- a/packages/yak_result/lib/src/extensions/is_x.dart +++ /dev/null @@ -1,11 +0,0 @@ -import '../all.dart'; - -/// an utility extension that returns boolean for [Result] is [Success] -extension IsSuccessX on Result { - bool get isSuccess => this is Success; -} - -/// an utility extension that returns boolean for [Result] is [Failure] -extension IsFailureX on Result { - bool get isFailure => this is Failure; -} diff --git a/packages/yak_result/lib/src/extensions/iterable_combine.dart b/packages/yak_result/lib/src/extensions/iterable_combine.dart index 19e25798..02605a5e 100644 --- a/packages/yak_result/lib/src/extensions/iterable_combine.dart +++ b/packages/yak_result/lib/src/extensions/iterable_combine.dart @@ -1,40 +1,85 @@ -import 'package:yak_result/yak_result.dart'; +import '../classes/void_result.dart' show VoidResult; +import '../classes/result.dart' show Result; +import '../typedef/unary_function.dart'; +import '../typedef/nullary_function.dart'; +import 'recast.dart'; -extension IterableNullaryCombineValueResultX on Iterable> { +extension IterableUnaryCombineValueResultX + on Iterable> { /// returns the result of a list of functions - ResultNullary> get combine => () { - final results = []; - for (final function in this) { - final result = function(); - if (result.isFailure) { - return result.failure.recast(); - } - results.add(result.success.value); - } - return Success.value(results); - }; + Result> combine(S value) { + final results = []; + for (final function in this) { + final result = function(value); + if (result.isFailure) { + return result.asFailure.recast(); + } + results.add(result.asSuccess); + } + return Result.success(results); + } /// returns the result of a list of functions - VoidResultNullary get combineVoid => () { - for (final function in this) { - final result = function(); - if (result.isFailure) { - return result.failure.recast(); - } - } - return const VoidSuccess(); - }; + VoidResult combineVoid(S value) { + for (final function in this) { + final result = function(value); + if (result.isFailure) { + return result.asFailure.asVoid(); + } + } + return const VoidResult.success(); + } +} + +extension IterableUnaryCombineVoidResultX on Iterable> { + /// returns the result of a list of functions + VoidResult combine(T value) { + for (final function in this) { + final result = function(value); + if (result.isFailure) { + return result; + } + } + return const VoidResult.success(); + } +} + +extension IterableNullaryCombineValueResultX + on Iterable> { + /// returns the result of a list of functions + Result> combine() { + final results = []; + for (final function in this) { + final result = function(); + if (result.isFailure) { + return result.asFailure.recast(); + } + results.add(result.asSuccess); + } + return Result.success(results); + } + + /// returns the result of a list of functions + VoidResult combineVoid() { + for (final function in this) { + final result = function(); + if (result.isFailure) { + return result.asFailure.asVoid(); + } + } + return const VoidResult.success(); + } } extension IterableNullaryCombineVoidResultX on Iterable { /// returns the result of a list of functions - VoidResultNullary get combine => () { - for (final function in this) { - final result = function(); - if (result.isFailure) { - return result; - } - } - return const VoidSuccess(); - }; + VoidResult combine() { + for (final function in this) { + final result = function(); + if (result.isFailure) { + return result; + } + } + return const VoidResult.success(); + } } diff --git a/packages/yak_result/lib/src/extensions/iterable_combine_unary.dart b/packages/yak_result/lib/src/extensions/iterable_combine_unary.dart deleted file mode 100644 index 5b9d5d98..00000000 --- a/packages/yak_result/lib/src/extensions/iterable_combine_unary.dart +++ /dev/null @@ -1,41 +0,0 @@ -import 'package:yak_result/yak_result.dart'; - -extension IterableUnaryCombineValueResultX - on Iterable> { - /// returns the result of a list of functions - ResultUnary, S> get combine => (S value) { - final results = []; - for (final function in this) { - final result = function(value); - if (result.isFailure) { - return result.failure.recast(); - } - results.add(result.success.value); - } - return Success.value(results); - }; - - /// returns the result of a list of functions - VoidResultUnary get combineVoid => (S value) { - for (final function in this) { - final result = function(value); - if (result.isFailure) { - return result.failure.recast(); - } - } - return const VoidSuccess(); - }; -} - -extension IterableUnaryCombineVoidResultX on Iterable> { - /// returns the result of a list of functions - VoidResultUnary get combine => (T value) { - for (final function in this) { - final result = function(value); - if (result.isFailure) { - return result; - } - } - return const VoidSuccess(); - }; -} diff --git a/packages/yak_result/lib/src/extensions/recast.dart b/packages/yak_result/lib/src/extensions/recast.dart new file mode 100644 index 00000000..648869cd --- /dev/null +++ b/packages/yak_result/lib/src/extensions/recast.dart @@ -0,0 +1,25 @@ +import '../classes/failure.dart'; +import '../classes/result.dart' show Result; +import '../classes/void_result.dart' show VoidResult; + +/// recast a [Failure] with to the desired [Type] +extension RecastFailureX on Failure { + Result recast() => Result.failure( + reason, + stackTrace, + ); + VoidResult asVoid() => VoidResult.failure( + reason, + stackTrace, + ); +} + +/// recast a [Result] with to the desired [Type] +extension RecastSuccessX on Result { + VoidResult asVoid() => isSuccess + ? const VoidResult.success() + : () { + final failure = result as Failure; + return VoidResult.failure(failure.reason, failure.stackTrace); + }(); +} diff --git a/packages/yak_result/lib/src/typedef/all.dart b/packages/yak_result/lib/src/typedef/all.dart index 93b715c9..b2c732b3 100644 --- a/packages/yak_result/lib/src/typedef/all.dart +++ b/packages/yak_result/lib/src/typedef/all.dart @@ -1,3 +1,3 @@ +export 'future_result.dart'; export 'nullary_function.dart'; export 'unary_function.dart'; -export 'future_result.dart'; diff --git a/packages/yak_result/lib/src/typedef/future_result.dart b/packages/yak_result/lib/src/typedef/future_result.dart index 46d29a47..1d0ebbd3 100644 --- a/packages/yak_result/lib/src/typedef/future_result.dart +++ b/packages/yak_result/lib/src/typedef/future_result.dart @@ -1,12 +1,10 @@ import 'dart:async'; -import '../all.dart'; +import '../classes/result.dart' show Result; +import '../classes/void_result.dart' show VoidResult; /// a [FutureOr] [Result] -typedef FutureResult = FutureOr>; - -/// a [FutureOr] [ValueResult] -typedef FutureValueResult = FutureOr>; +typedef FutureResult = FutureOr>; /// a [FutureOr] [VoidResult] -typedef FutureVoidResult = FutureOr>; +typedef FutureVoidResult = FutureOr; diff --git a/packages/yak_result/lib/src/typedef/nullary_function.dart b/packages/yak_result/lib/src/typedef/nullary_function.dart index 274b80d1..97b96256 100644 --- a/packages/yak_result/lib/src/typedef/nullary_function.dart +++ b/packages/yak_result/lib/src/typedef/nullary_function.dart @@ -1,16 +1,16 @@ -import 'dart:async'; import 'package:yak_utils/yak_utils.dart' show Nullary; - -import '../all.dart'; +import '../classes/result.dart' show Result; +import '../classes/void_result.dart' show VoidResult; +import 'future_result.dart'; /// an [Nullary] [Function] that returns a [Result] -typedef ResultNullary = Nullary>; +typedef ResultNullary = Nullary>; /// an [Nullary] [async] [Function] that returns a [Result] -typedef ResultNullaryAsync = Nullary>>; +typedef ResultNullaryAsync = Nullary>; /// an [Nullary] function that returns a [VoidResult] -typedef VoidResultNullary = Nullary>; +typedef VoidResultNullary = Nullary; /// an [Nullary] [async] [Function] that returns a [VoidResult] -typedef VoidResultNullaryAsync = Nullary>>; +typedef VoidResultNullaryAsync = Nullary; diff --git a/packages/yak_result/lib/src/typedef/unary_function.dart b/packages/yak_result/lib/src/typedef/unary_function.dart index 639a78e9..204adb94 100644 --- a/packages/yak_result/lib/src/typedef/unary_function.dart +++ b/packages/yak_result/lib/src/typedef/unary_function.dart @@ -1,18 +1,19 @@ import 'dart:async'; import 'package:yak_utils/yak_utils.dart' show Unary; - -import '../all.dart'; +import '../classes/result.dart' show Result; +import '../classes/void_result.dart' show VoidResult; +import 'future_result.dart'; /// an unary function that returns a Result -typedef ResultUnary = Unary, S>; +typedef ResultUnary = Unary, S>; /// an unary async function that returns a Result ///! differs from [UnaryAsync] ad it returns [FutureOr] instead of [Future] -typedef ResultUnaryAsync = Unary>, S>; +typedef ResultUnaryAsync = Unary, S>; /// an [Nullary] function that returns a [VoidResult] -typedef VoidResultUnary = Unary, T>; +typedef VoidResultUnary = Unary; /// an [Nullary] [async] [Function] that returns a [VoidResult] -typedef VoidResultUnaryAsync = Unary>, T>; +typedef VoidResultUnaryAsync = Unary; diff --git a/packages/yak_result/lib/yak_result.dart b/packages/yak_result/lib/yak_result.dart index 8671020e..85e50c0f 100644 --- a/packages/yak_result/lib/yak_result.dart +++ b/packages/yak_result/lib/yak_result.dart @@ -1,3 +1,7 @@ library yak_result; -export 'src/all.dart'; +export 'src/extensions/all.dart'; +export 'src/typedef/all.dart'; +export 'src/classes/void_result.dart' show VoidResult; +export 'src/classes/result.dart' show Result; +export 'src/classes/failure.dart'; diff --git a/packages/yak_result/test/classes/failure_test.dart b/packages/yak_result/test/classes/failure_test.dart index 377590f0..9393d734 100644 --- a/packages/yak_result/test/classes/failure_test.dart +++ b/packages/yak_result/test/classes/failure_test.dart @@ -3,7 +3,7 @@ import 'package:test/test.dart'; import 'package:yak_result/yak_result.dart'; void main() { - group('Failure', () { + group('Failure Test', () { group('Failure Type maching', () { final tester = Stub.nullary>(); final negative = Stub.nullary>(); @@ -17,7 +17,7 @@ void main() { 'GIVEN Failure ' 'WHEN this is Failure ' 'THEN return true', () { - tester.stub = () => Failure(); + tester.stub = () => const Failure.empty(); expect( tester(), @@ -30,7 +30,7 @@ void main() { 'GIVEN Failure ' 'WHEN this is Failure ' 'THEN return false', () { - negative.stub = () => Failure(); + negative.stub = () => const Failure.empty(); expect( negative(), @@ -42,7 +42,7 @@ void main() { 'GIVEN Failure ' 'WHEN this is Result ' 'THEN return true', () { - tester.stub = () => Failure(); + tester.stub = () => const Failure.empty(); expect( tester(), @@ -66,8 +66,8 @@ void main() { 'GIVEN Failure ' 'WHEN matched against different Failure ' 'THEN return false', () { - tester.stub = () => Failure(reason); - negative.stub = () => Failure(); + tester.stub = () => Result.failure(reason); + negative.stub = () => Result.failure(); expect( tester(), @@ -80,8 +80,8 @@ void main() { 'GIVEN Failure' 'WHEN matched against identical Failure ' 'THEN return false', () { - tester.stub = () => Failure(reason); - negative.stub = () => Failure(reason); + tester.stub = () => Result.failure(reason); + negative.stub = () => Result.failure(reason); expect( tester(), diff --git a/packages/yak_result/test/classes/result_test.dart b/packages/yak_result/test/classes/result_test.dart index c4e4abaa..d2d390bf 100644 --- a/packages/yak_result/test/classes/result_test.dart +++ b/packages/yak_result/test/classes/result_test.dart @@ -3,7 +3,7 @@ import 'package:test/test.dart'; import 'package:yak_result/yak_result.dart'; void main() { - group('Result', () { + group('Result Test', () { group('Success Type maching', () { final tester = Stub.nullary>(); final negative = Stub.nullary>(); @@ -14,10 +14,10 @@ void main() { }); test( - 'GIVEN Success ' + 'GIVEN Result ' 'WHEN this is Result ' 'THEN return true', () { - tester.stub = () => Success.value(false); + tester.stub = () => const Result.success(false); expect( tester(), @@ -27,37 +27,33 @@ void main() { }); test( - 'GIVEN Success ' + 'GIVEN Result ' 'WHEN this is Result ' 'THEN return false', () { - negative.stub = () => Success.value(0); + tester.stub = () => const Result.success(false); + negative.stub = () => const Result.success(1); expect( - negative(), - isNot(isA>()), + tester(), + isNot(equals(negative())), reason: 'type should be predictable', ); }); test( - 'GIVEN Success and Success ' - 'WHEN this is Result ' - 'THEN return true', () { - tester.stub = () => Success.value(false); - negative.stub = () => Success.value(0); + 'GIVEN Results and Results ' + 'WHEN results are equals' + 'THEN equality return true', () { + tester.stub = () => const Result.success(false); expect( tester(), - isA(), - reason: 'type should be predictable', - ); - expect( - negative(), - isA(), + equals(const Result.success(false)), reason: 'type should be predictable', ); }); }); + group('Failure Type maching', () { final tester = Stub.nullary>(); final negative = Stub.nullary>(); @@ -68,10 +64,10 @@ void main() { }); test( - 'GIVEN Failure ' - 'WHEN this is Result ' + 'GIVEN Result.failure ' + 'WHEN this is Result.failure ' 'THEN return true', () { - tester.stub = () => Failure(); + tester.stub = () => Result.failure(); expect( tester(), @@ -84,135 +80,125 @@ void main() { 'GIVEN Success ' 'WHEN this is Result ' 'THEN return false', () { - negative.stub = () => Failure(); + tester.stub = () => Result.failure(); + negative.stub = () => Result.failure(); expect( - negative(), - isNot(isA>()), + tester(), + isNot(equals(negative())), reason: 'type should be predictable', ); }); + }); + group('Result isSuccess/isFailure test', () { + final tester = Stub.nullary>(); + + setUp(tester.reset); + test( - 'GIVEN Success and Success ' - 'WHEN this is Result ' + 'GIVEN Result.success ' + 'WHEN isSuccess ' 'THEN return true', () { - tester.stub = () => Failure(); - negative.stub = () => Failure(); + tester.stub = () => const Result.success(false); expect( - tester(), - isA(), - reason: 'type should be predictable', - ); - expect( - negative(), - isA(), - reason: 'type should be predictable', + tester().isSuccess, + isTrue, + reason: 'result should be predictable', ); }); - }); - }); - group('ValueResult', () { - group('ValueResult Type maching', () { - final tester = Stub.nullary(); - final negative = Stub.nullary(); - final strict = Stub.nullary(); - - setUp(() { - tester.reset(); - negative.reset(); - strict.reset(); - }); test( - 'GIVEN Result() ' - 'WHEN this is ValueResult ' - 'THEN return true', () { - tester.stub = () => Success.value(0); + 'GIVEN Result.success ' + 'WHEN isFailure ' + 'THEN return false', () { + tester.stub = () => const Result.success(false); expect( - tester(), - isA(), - reason: 'type should be predictable', + tester().isFailure, + isFalse, + reason: 'result should be predictable', ); }); - test( - 'GIVEN VoidSuccess ' - 'WHEN this is ValueResult ' + 'GIVEN Result.failure ' + 'WHEN isSuccess ' 'THEN return false', () { - negative.stub = () => Success.empty; + tester.stub = () => Result.failure(); expect( - negative(), - isNot(isA()), - reason: 'type should be predictable', + tester().isSuccess, + isFalse, + reason: 'result should be predictable', ); }); test( - 'GIVEN ValueSuccess ' - 'WHEN this is Result ' + 'GIVEN Result.failure ' + 'WHEN isFailure ' 'THEN return true', () { - strict.stub = () => Success.value(0); + tester.stub = () => Result.failure(); expect( - strict(), - isA(), - reason: 'type should be predictable', + tester().isFailure, + isTrue, + reason: 'result should be predictable', ); }); }); - }); + group('Result asSuccess/asFailure test', () { + final tester = Stub.nullary>(); - group('VoidResult', () { - group('VoidResult Type maching', () { - final tester = Stub.nullary(); - final negative = Stub.nullary(); - final strict = Stub.nullary(); + setUp(tester.reset); - setUp(() { - tester.reset(); - negative.reset(); - strict.reset(); + test( + 'GIVEN Result.success ' + 'WHEN asSuccess ' + 'THEN return T', () { + tester.stub = () => const Result.success(false); + + expect( + tester().asSuccess, + isA(), + reason: 'result should be predictable', + ); }); test( - 'GIVEN Success.empty ' - 'WHEN this is VoidResult ' - 'THEN return true', () { - tester.stub = () => Success.empty; + 'GIVEN Result.success ' + 'WHEN isFailure ' + 'THEN throws Exception', () { + tester.stub = () => const Result.success(false); expect( - tester(), - isA(), - reason: 'type should be predictable', + () => tester().asFailure, + throwsException, + reason: 'result should be predictable', ); }); - test( - 'GIVEN ValueSuccess ' - 'WHEN this is VoidResult ' - 'THEN return false', () { - negative.stub = () => Success.value(0); + 'GIVEN Result.failure ' + 'WHEN asSuccess ' + 'THEN throws Exception', () { + tester.stub = () => Result.failure(); expect( - negative(), - isNot(isA()), - reason: 'type should be predictable', + () => tester().asSuccess, + throwsException, + reason: 'result should be predictable', ); }); test( - 'GIVEN VoidResult ' - 'WHEN this is Result ' - 'THEN return false', () { - strict.stub = () => Success.empty; + 'GIVEN Result.failure ' + 'WHEN isFailure ' + 'THEN return true', () { + tester.stub = () => Result.failure(); expect( - strict(), - isA(), - reason: 'type should be predictable', + tester().asFailure, + isA(), + reason: 'result should be predictable', ); }); }); diff --git a/packages/yak_result/test/classes/success_test.dart b/packages/yak_result/test/classes/success_test.dart deleted file mode 100644 index 57fde0d1..00000000 --- a/packages/yak_result/test/classes/success_test.dart +++ /dev/null @@ -1,251 +0,0 @@ -import 'package:stub/stub.dart'; -import 'package:test/test.dart'; -import 'package:yak_result/yak_result.dart'; - -void main() { - group('Success', () { - group('Success Type maching', () { - final tester = Stub.nullary>(); - final negative = Stub.nullary>(); - - setUp(() { - tester.reset(); - negative.reset(); - }); - - test( - 'GIVEN Success ' - 'WHEN this is Success ' - 'THEN return true', () { - tester.stub = () => Success.value(false); - - expect( - tester(), - isA>(), - reason: 'type should be predictable', - ); - }); - - test( - 'GIVEN Success ' - 'WHEN this is Success ' - 'THEN return false', () { - negative.stub = () => Success.value(0); - - expect( - negative(), - isNot(isA>()), - reason: 'type should be predictable', - ); - }); - - test( - 'GIVEN Success and Success ' - 'WHEN this is Success ' - 'THEN return true', () { - tester.stub = () => Success.value(false); - negative.stub = () => Success.value(0); - - expect( - tester(), - isA(), - reason: 'type should be predictable', - ); - expect( - negative(), - isA(), - reason: 'type should be predictable', - ); - }); - }); - group('equality VS different Type', () { - final tester = Stub.nullary>(); - final negative = Stub.nullary>(); - - setUp(() { - tester.reset(); - negative.reset(); - }); - - test( - 'GIVEN Success of Type `T`' - 'WHEN this == Success ' - 'THEN return true', () { - tester.stub = () => Success.value(true); - negative.stub = () => Success.value(0); - - expect( - tester(), - isNot(equals(negative())), - reason: 'type should be predictable', - ); - }); - }); - group('equality VS different value', () { - final tester = Stub.nullary>(); - final negative = Stub.nullary>(); - - setUp(() { - tester.reset(); - negative.reset(); - }); - - test( - 'GIVEN Success of Type `T`' - 'WHEN this == Success & holds the same data ' - 'THEN return true', () { - tester.stub = () => Success.value(true); - negative.stub = () => Success.value(true); - - expect( - tester(), - equals(negative()), - reason: 'equality should return true', - ); - }); - - test( - 'GIVEN Success of Type `T`' - 'WHEN this == Success & holds different data ' - 'THEN return true', () { - tester.stub = () => Success.value(true); - negative.stub = () => Success.value(false); - - expect( - tester(), - isNot(equals(negative())), - reason: 'equality should return true', - ); - }); - }); - }); - group('ValueSuccess', () { - group('ValueSuccess Type maching', () { - final tester = Stub.nullary(); - final negative = Stub.nullary(); - final strict = Stub.nullary(); - - setUp(() { - tester.reset(); - negative.reset(); - strict.reset(); - }); - - test( - 'GIVEN Success() ' - 'WHEN this is ValueSuccess ' - 'THEN return true', () { - tester.stub = () => Success.value(0); - - expect( - tester(), - isA(), - reason: 'type should be predictable', - ); - }); - - test( - 'GIVEN VoidSuccess ' - 'WHEN this is ValueSuccess ' - 'THEN return false', () { - negative.stub = () => Success.empty; - - expect( - negative(), - isNot(isA()), - reason: 'type should be predictable', - ); - }); - - test( - 'GIVEN ValueSuccess ' - 'WHEN this is Success ' - 'THEN return true', () { - strict.stub = () => Success.value(null); - - expect( - strict(), - isA(), - reason: 'type should be predictable', - ); - }); - test( - 'GIVEN ValueSuccess ' - 'WHEN this is Result ' - 'THEN return true', () { - strict.stub = () => Success.value(null); - - expect( - strict(), - isA(), - reason: 'type should be predictable', - ); - }); - }); - - group('VoidSuccess', () { - group('VoidSuccess Type maching', () { - final tester = Stub.nullary(); - final negative = Stub.nullary(); - final strict = Stub.nullary(); - - setUp(() { - tester.reset(); - negative.reset(); - strict.reset(); - }); - - test( - 'GIVEN VoidSuccess() ' - 'WHEN this is VoidSuccess ' - 'THEN return true', () { - tester.stub = () => Success.empty; - - expect( - tester(), - isA(), - reason: 'type should be predictable', - ); - }); - - test( - 'GIVEN ValueSuccess ' - 'WHEN this is VoidSuccess ' - 'THEN return false', () { - negative.stub = () => Success.value(0); - - expect( - negative(), - isNot(isA()), - reason: 'type should be predictable', - ); - }); - - test( - 'GIVEN ValueSuccess ' - 'WHEN this is Success ' - 'THEN return false', () { - strict.stub = () => Success.empty; - - expect( - strict(), - isA(), - reason: 'type should be predictable', - ); - }); - test( - 'GIVEN ValueSuccess ' - 'WHEN this is Result ' - 'THEN return false', () { - strict.stub = () => Success.empty; - - expect( - strict(), - isA(), - reason: 'type should be predictable', - ); - }); - }); - }); - }); -} diff --git a/packages/yak_result/test/classes/void_result_test.dart b/packages/yak_result/test/classes/void_result_test.dart new file mode 100644 index 00000000..65008182 --- /dev/null +++ b/packages/yak_result/test/classes/void_result_test.dart @@ -0,0 +1,129 @@ +import 'package:stub/stub.dart'; +import 'package:test/test.dart'; +import 'package:yak_result/yak_result.dart'; + +void main() { + group('VoidResult Test', () { + group('Type maching', () { + final tester = Stub.nullary(); + + setUp(() { + tester.reset(); + }); + + test( + 'GIVEN VoidResult.success ' + 'WHEN this is VoidResult ' + 'THEN return true', () { + tester.stub = () => const VoidResult.success(); + + expect( + tester(), + isA(), + reason: 'type should be predictable', + ); + }); + + test( + 'GIVEN VoidResult.failure ' + 'WHEN this is VoidResult ' + 'THEN return true', () { + tester.stub = () => const VoidResult.failure(); + + expect( + tester(), + isA(), + reason: 'type should be predictable', + ); + }); + }); + + group('Result isSuccess/isFailure test', () { + final tester = Stub.nullary(); + + setUp(tester.reset); + + test( + 'GIVEN Result.success ' + 'WHEN isSuccess ' + 'THEN return true', () { + tester.stub = () => const VoidResult.success(); + + expect( + tester().isSuccess, + isTrue, + reason: 'result should be predictable', + ); + }); + + test( + 'GIVEN Result.success ' + 'WHEN isFailure ' + 'THEN return false', () { + tester.stub = () => const VoidResult.success(); + + expect( + tester().isFailure, + isFalse, + reason: 'result should be predictable', + ); + }); + test( + 'GIVEN Result.failure ' + 'WHEN isSuccess ' + 'THEN return false', () { + tester.stub = () => const VoidResult.failure(); + + expect( + tester().isSuccess, + isFalse, + reason: 'result should be predictable', + ); + }); + + test( + 'GIVEN Result.failure ' + 'WHEN isFailure ' + 'THEN return true', () { + tester.stub = () => const VoidResult.failure(); + + expect( + tester().isFailure, + isTrue, + reason: 'result should be predictable', + ); + }); + }); + group('Result asSuccess/asFailure test', () { + final tester = Stub.nullary(); + + setUp(tester.reset); + + test( + 'GIVEN Result.success ' + 'WHEN isFailure ' + 'THEN throws Exception', () { + tester.stub = () => const VoidResult.success(); + + expect( + () => tester().asFailure, + throwsException, + reason: 'result should be predictable', + ); + }); + + test( + 'GIVEN Result.failure ' + 'WHEN isFailure ' + 'THEN return true', () { + tester.stub = () => const VoidResult.failure(); + + expect( + tester().asFailure, + isA(), + reason: 'result should be predictable', + ); + }); + }); + }); +} diff --git a/packages/yak_result/test/extensions/as_failure_test.dart b/packages/yak_result/test/extensions/as_failure_test.dart deleted file mode 100644 index a0ca14b5..00000000 --- a/packages/yak_result/test/extensions/as_failure_test.dart +++ /dev/null @@ -1,116 +0,0 @@ -import 'package:test/test.dart'; -import 'package:yak_result/yak_result.dart'; -import 'package:stub/stub.dart'; - -void main() { - group('ResultAsFailureX', () { - group('"failure"', () { - final tester = Stub.nullary(); - - setUp(tester.reset); - test('GIVEN Result is a Failure ' 'WHEN failure ' 'THEN return a Failure', - () { - tester.stub = () => Failure(); - - expect( - tester().failure, - isA(), - reason: 'should be a failure', - ); - }); - test('GIVEN Result is a Success ' 'WHEN failure ' 'THEN should throw', - () { - tester.stub = () => Success.empty; - - expect( - () => tester().failure, - throwsA(isA()), - reason: 'should throw', - ); - }); - }); - group('"failureOrNull"', () { - group('"Result" - "Success" - "Failure"', () { - final tester = Stub.nullary(); - - setUp(tester.reset); - test( - 'GIVEN Result is a Failure ' - 'WHEN failure ' - 'THEN return a Failure', () { - tester.stub = () => Failure(); - - expect( - tester().failureOrNull, - isA(), - reason: 'should be a failure', - ); - }); - test('GIVEN Result is a Success ' 'WHEN failure ' 'THEN should be null', - () { - tester.stub = () => Success.empty; - - expect( - tester().failureOrNull, - isNull, - reason: 'should be null', - ); - }); - }); - group('Void', () { - final tester = Stub.nullary(); - - setUp(tester.reset); - test( - 'GIVEN Result is a Failure ' - 'WHEN failure ' - 'THEN return a Failure', () { - tester.stub = () => Failure(); - - expect( - tester().failureOrNull, - isA(), - reason: 'should be a failure', - ); - }); - test('GIVEN Result is a Success ' 'WHEN failure ' 'THEN should be null', - () { - tester.stub = () => Success.empty; - - expect( - tester().failureOrNull, - isNull, - reason: 'should be null', - ); - }); - }); - group('Value', () { - final tester = Stub.nullary(); - - setUp(tester.reset); - test( - 'GIVEN Result is a Failure ' - 'WHEN failure ' - 'THEN return a Failure', () { - tester.stub = () => Failure(); - - expect( - tester().failureOrNull, - isA(), - reason: 'should be a failure', - ); - }); - test('GIVEN Result is a Success ' 'WHEN failure ' 'THEN should be null', - () { - tester.stub = () => Success.value(0); - - expect( - tester().failureOrNull, - isNull, - reason: 'should be null', - ); - }); - }); - }); - }); -} diff --git a/packages/yak_result/test/extensions/as_success_test.dart b/packages/yak_result/test/extensions/as_success_test.dart deleted file mode 100644 index 99d878a1..00000000 --- a/packages/yak_result/test/extensions/as_success_test.dart +++ /dev/null @@ -1,115 +0,0 @@ -import 'package:test/test.dart'; -import 'package:yak_result/yak_result.dart'; -import 'package:stub/stub.dart'; - -void main() { - group('ValueResultAsSuccess', () { - group('"success"', () { - final tester = Stub.nullary(); - - setUp(tester.reset); - test('GIVEN Result is a Failure ' 'WHEN failure ' 'THEN should throw', - () { - tester.stub = () => Failure(); - - expect( - () => tester().success, - throwsA(isA()), - reason: 'should throw', - ); - }); - test('GIVEN Result is a Success ' 'WHEN failure ' 'THEN should throw', - () { - tester.stub = () => Success.value(0); - - expect( - tester().success, - isA(), - reason: 'should be a Success', - ); - }); - }); - group('"successOrNull"', () { - final tester = Stub.nullary(); - - setUp(tester.reset); - test( - 'GIVEN Result is a Failure ' - 'WHEN failure ' - 'THEN return a Failure', () { - tester.stub = () => Failure(); - - expect( - tester().successOrNull, - isNull, - reason: 'should be null', - ); - }); - test('GIVEN Result is a Success ' 'WHEN failure ' 'THEN should be null', - () { - tester.stub = () => Success.value(0); - - expect( - tester().successOrNull, - isA(), - reason: 'should be a Success', - ); - }); - }); - }); - - group('VoidResultAsSuccess', () { - group('"success"', () { - final tester = Stub.nullary(); - - setUp(tester.reset); - test('GIVEN Result is a Failure ' 'WHEN failure ' 'THEN should throw', - () { - tester.stub = () => Failure(); - - expect( - () => tester().success, - throwsA(isA()), - reason: 'should throw', - ); - }); - test('GIVEN Result is a Success ' 'WHEN failure ' 'THEN should throw', - () { - tester.stub = () => VoidSuccess(); - - expect( - tester().success, - isA(), - reason: 'should be a Success', - ); - }); - }); - group('"successOrNull"', () { - final tester = Stub.nullary(); - - setUp(tester.reset); - test( - 'GIVEN Result is a Failure ' - 'WHEN failure ' - 'THEN return a Failure', () { - tester.stub = () => Failure(); - - expect( - tester().successOrNull, - isNull, - reason: 'should be null', - ); - }); - test('GIVEN Result is a Success ' 'WHEN failure ' 'THEN should be null', - () { - tester.stub = () => VoidSuccess(); - - expect( - tester().successOrNull, - isA(), - reason: 'should be a Success', - ); - }); - }); - }); -} diff --git a/packages/yak_result/test/extensions/as_void_test.dart b/packages/yak_result/test/extensions/as_void_test.dart deleted file mode 100644 index ca866e63..00000000 --- a/packages/yak_result/test/extensions/as_void_test.dart +++ /dev/null @@ -1,43 +0,0 @@ -import 'package:stub/stub.dart'; -import 'package:test/test.dart'; -import 'package:yak_result/yak_result.dart'; - -void main() { - group('ValueResultAsVoidX', () { - final tester = Stub.nullary(); - - setUp(tester.reset); - - test('GIVEN tester is a Failure ' 'WHEN "asVoid" ' 'THEN return a Failure', - () { - tester.stub = () => Failure(); - expect( - tester().asVoid, - isA(), - reason: 'should be a failure', - ); - - expect( - tester().asVoid, - isA(), - reason: 'should be a VoidResult', - ); - }); - - test('GIVEN tester is a Failure ' 'WHEN "asVoid" ' 'THEN return a Failure', - () { - tester.stub = () => ValueSuccess(0); - - expect( - tester().asVoid, - isA(), - reason: 'should be a Success', - ); - expect( - tester().asVoid, - isA(), - reason: 'should be a VoidResult', - ); - }); - }); -} diff --git a/packages/yak_result/test/extensions/failure_recast_test.dart b/packages/yak_result/test/extensions/failure_recast_test.dart deleted file mode 100644 index 6f5eb710..00000000 --- a/packages/yak_result/test/extensions/failure_recast_test.dart +++ /dev/null @@ -1,40 +0,0 @@ -import 'package:test/test.dart'; -import 'package:yak_result/yak_result.dart'; - -void main() { - group('ResultAsFailureX', () { - const reason = 0; - final stackTrace = StackTrace.fromString('stackTraceString'); - final failure = Failure(reason, stackTrace); - test( - 'GIVEN Failure ' - 'WHEN recast() ' - 'THEN return a Failure', () { - expect( - failure.recast(), - isA>(), - reason: 'should be a Failure of the exact type', - ); - }); - test( - 'GIVEN Failure ' - 'WHEN recast() ' - 'THEN return a Failure with same reason', () { - expect( - failure.recast().reason, - equals(reason), - reason: 'reason should match', - ); - }); - test( - 'GIVEN Failure ' - 'WHEN recast() ' - 'THEN return a Failure with same stacktrace', () { - expect( - failure.recast().stackTrace, - equals(stackTrace), - reason: 'stackTrace should match', - ); - }); - }); -} diff --git a/packages/yak_result/test/extensions/is_x_test.dart b/packages/yak_result/test/extensions/is_x_test.dart deleted file mode 100644 index 10859f8f..00000000 --- a/packages/yak_result/test/extensions/is_x_test.dart +++ /dev/null @@ -1,150 +0,0 @@ -import 'package:stub/stub.dart'; -import 'package:test/test.dart'; -import 'package:yak_result/yak_result.dart'; - -void main() { - group('Result', () { - group('IsValueSuccessX', () { - final tester = Stub.nullary(); - - setUp(tester.reset); - test('GIVEN Result is Success ' 'WHEN .isSuccess ' 'THEN returns true', - () { - tester.stub = () => Success.value(true); - expect( - tester().isSuccess, - isTrue, - reason: 'should return true', - ); - }); - test('GIVEN Result is Failure ' 'WHEN .isSuccess ' 'THEN returns false', - () { - tester.stub = () => Failure(); - expect( - tester().isSuccess, - isFalse, - reason: 'should return false', - ); - }); - }); - - group('IsVoidSuccessX', () { - final tester = Stub.nullary(); - - setUp(tester.reset); - test('GIVEN Result is Success ' 'WHEN .isSuccess ' 'THEN returns true', - () { - tester.stub = () => Success.value(true); - expect( - tester().isSuccess, - isTrue, - reason: 'should return true', - ); - }); - test('GIVEN Result is Failure ' 'WHEN .isSuccess ' 'THEN returns false', - () { - tester.stub = () => Failure(); - expect( - tester().isSuccess, - isFalse, - reason: 'should return false', - ); - }); - }); - group('IsFailureX', () { - final tester = Stub.nullary(); - - setUp(tester.reset); - test('GIVEN Result is Success ' 'WHEN .isFailure ' 'THEN returns false', - () { - tester.stub = () => Success.value(true); - expect( - tester().isFailure, - isFalse, - reason: 'should return false', - ); - }); - test('GIVEN Result is Failure ' 'WHEN .isfailure ' 'THEN returns true', - () { - tester.stub = () => Failure(); - expect( - tester().isFailure, - isTrue, - reason: 'should return true', - ); - }); - }); - }); - group('VoidResult', () { - group('IsValueSuccessX', () { - final tester = Stub.nullary(); - - setUp(tester.reset); - test('GIVEN Result is Success ' 'WHEN .isSuccess ' 'THEN returns true', - () { - tester.stub = () => VoidSuccess(); - expect( - tester().isSuccess, - isTrue, - reason: 'should return true', - ); - }); - test('GIVEN Result is Failure ' 'WHEN .isSuccess ' 'THEN returns false', - () { - tester.stub = () => Failure(); - expect( - tester().isSuccess, - isFalse, - reason: 'should return false', - ); - }); - }); - - group('IsVoidSuccessX', () { - final tester = Stub.nullary(); - - setUp(tester.reset); - test('GIVEN Result is Success ' 'WHEN .isSuccess ' 'THEN returns true', - () { - tester.stub = () => VoidSuccess(); - expect( - tester().isSuccess, - isTrue, - reason: 'should return true', - ); - }); - test('GIVEN Result is Failure ' 'WHEN .isSuccess ' 'THEN returns false', - () { - tester.stub = () => Failure(); - expect( - tester().isSuccess, - isFalse, - reason: 'should return false', - ); - }); - }); - group('IsFailureX', () { - final tester = Stub.nullary(); - - setUp(tester.reset); - test('GIVEN Result is Success ' 'WHEN .isFailure ' 'THEN returns false', - () { - tester.stub = () => VoidSuccess(); - expect( - tester().isFailure, - isFalse, - reason: 'should return false', - ); - }); - test('GIVEN Result is Failure ' 'WHEN .isfailure ' 'THEN returns true', - () { - tester.stub = () => Failure(); - expect( - tester().isFailure, - isTrue, - reason: 'should return true', - ); - }); - }); - }); -} diff --git a/packages/yak_result/test/extensions/iterable_combine_test.dart b/packages/yak_result/test/extensions/iterable_combine_test.dart index 0be331eb..9f2a6d1d 100644 --- a/packages/yak_result/test/extensions/iterable_combine_test.dart +++ b/packages/yak_result/test/extensions/iterable_combine_test.dart @@ -4,15 +4,15 @@ import 'package:stub/stub.dart'; import 'package:yak_result/yak_result.dart'; void main() { - group('IterableNullaryCombineValueResultX', () { - group('combine', () { - final failure = Stub.nullary>() - ..stub = () => const Failure(); + group('Nullary', () { + group('combine Test', () { + final failure = Stub.nullary>() + ..stub = () => Result.failure(); - final success = Stub.nullary>() - ..stub = () => Success.value(0); + final success = Stub.nullary>() + ..stub = () => Result.success(true); - final tester = Stub.nullary>>(); + final tester = Stub.nullary>>(); setUp(() { tester.reset(); @@ -21,14 +21,14 @@ void main() { }); test( - 'GIVEN tester is a Iterable> ' + 'GIVEN tester is a Iterable> ' 'WHEN tester().combine ' - 'THEN success a ValueResult>', () { + 'THEN returns a ResultNullary>', () { tester.stub = () => []; expect( tester().combine, - isA>>(), + isA>>(), reason: 'Type should be predictable', ); }); @@ -36,7 +36,7 @@ void main() { test( 'GIVEN tester contains "failure" nullary ' 'WHEN tester().combine() ' - 'THEN success Failure', () { + 'THEN returns a Failure', () { tester.stub = () => [failure.call, success.call]; expect( @@ -53,9 +53,9 @@ void main() { }); test( - 'GIVEN tester contains "failure" nullary ' + 'GIVEN tester contains "failure" before "success" ' 'WHEN tester().combine() ' - 'THEN functions after "failure" are not called', () { + 'THEN success is never called', () { tester.stub = () => [failure.call, success.call]; expect( @@ -67,37 +67,51 @@ void main() { expect( failure.count, equals(1), - reason: '"failure" should be called once', + reason: 'should be called once', ); expect( success.count, equals(0), - reason: '"success" should not be called', + reason: 'should not be called', ); }); + test( - 'GIVEN tester contains only "success"s nullary ' + 'GIVEN tester contains only "success" ' 'WHEN tester().combine() ' - 'THEN success Success', () { + 'THEN result is a Success', () { tester.stub = () => [success.call, success.call]; expect( - tester().combine(), - isA(), - reason: 'should return a Success', + tester().combine().isSuccess, + isTrue, + reason: 'should return a success', + ); + }); + + test( + 'GIVEN tester contains 2 "success" ' + 'WHEN tester().combine() ' + 'THEN success is called twice', () { + tester.stub = () => [success.call, success.call]; + tester().combine(); + expect( + success.count, + equals(2), + reason: 'should be called twice', ); }); }); - group('combineVoid', () { - final failure = Stub.nullary>() - ..stub = () => const Failure(); + group(' combineVoid Test', () { + final failure = Stub.nullary>() + ..stub = () => Result.failure(); - final success = Stub.nullary>() - ..stub = () => Success.value(0); + final success = Stub.nullary>() + ..stub = () => Result.success(true); - final tester = Stub.nullary>>(); + final tester = Stub.nullary>>(); setUp(() { tester.reset(); @@ -106,9 +120,9 @@ void main() { }); test( - 'GIVEN tester is a Iterable> ' + 'GIVEN tester is a Iterable> ' 'WHEN tester().combineVoid ' - 'THEN success a ValueResult>', () { + 'THEN returns a VoidResultNullary', () { tester.stub = () => []; expect( @@ -121,7 +135,7 @@ void main() { test( 'GIVEN tester contains "failure" nullary ' 'WHEN tester().combineVoid() ' - 'THEN success Failure', () { + 'THEN returns a Failure', () { tester.stub = () => [failure.call, success.call]; expect( @@ -140,7 +154,25 @@ void main() { test( 'GIVEN tester contains "failure" nullary ' 'WHEN tester().combineVoid() ' - 'THEN functions after "failure" are not called', () { + 'THEN returns a VoidResult', () { + tester.stub = () => [failure.call, success.call]; + expect( + tester().combineVoid(), + isA(), + reason: 'should return a Failure', + ); + + expect( + failure.count, + equals(1), + reason: 'should be called once', + ); + }); + + test( + 'GIVEN tester contains "failure" before "success" ' + 'WHEN tester().combine() ' + 'THEN success is never called', () { tester.stub = () => [failure.call, success.call]; expect( @@ -152,36 +184,54 @@ void main() { expect( failure.count, equals(1), - reason: '"failure" should be called once', + reason: 'should be called once', ); expect( success.count, equals(0), - reason: '"success" should not be called', + reason: 'should not be called', ); }); + test( - 'GIVEN tester contains only "success"s nullary ' - 'WHEN tester().combineVoid() ' - 'THEN success Success', () { + 'GIVEN tester contains only "success" ' + 'WHEN tester().combine() ' + 'THEN result is a Success', () { tester.stub = () => [success.call, success.call]; expect( - tester().combineVoid(), - isA(), - reason: 'should return a Success', + tester().combineVoid().isSuccess, + isTrue, + reason: 'should return a success', + ); + }); + + test( + 'GIVEN tester contains 2 "success" ' + 'WHEN tester().combine() ' + 'THEN success is called twice', () { + tester.stub = () => [success.call, success.call]; + tester().combineVoid(); + expect( + success.count, + equals(2), + reason: 'should be called twice', ); }); }); }); - group('IterableNullaryCombineVoidResultX', () { - group('combine', () { - final failure = Stub.nullary()..stub = () => const Failure(); - final success = Stub.nullary()..stub = () => Success.empty; + group('Unary', () { + const seed = 0; + group('combine Test', () { + final failure = Stub.unary, int>() + ..stub = (i) => Result.failure(); - final tester = Stub.nullary>(); + final success = Stub.unary, int>() + ..stub = (i) => Result.success(true); + + final tester = Stub.nullary>>(); setUp(() { tester.reset(); @@ -190,14 +240,14 @@ void main() { }); test( - 'GIVEN tester is a Iterable ' + 'GIVEN tester is a Iterable> ' 'WHEN tester().combine ' - 'THEN success a ValueResult>', () { + 'THEN returns a ResultNullary>', () { tester.stub = () => []; expect( tester().combine, - isA(), + isA, int>>(), reason: 'Type should be predictable', ); }); @@ -205,11 +255,11 @@ void main() { test( 'GIVEN tester contains "failure" nullary ' 'WHEN tester().combine() ' - 'THEN success Failure', () { + 'THEN returns a Failure', () { tester.stub = () => [failure.call, success.call]; expect( - tester().combine(), + tester().combine(seed), isA(), reason: 'should return a Failure', ); @@ -222,13 +272,13 @@ void main() { }); test( - 'GIVEN tester contains "failure" nullary ' + 'GIVEN tester contains "failure" before "success" ' 'WHEN tester().combine() ' - 'THEN functions after "failure" are not called', () { + 'THEN success is never called', () { tester.stub = () => [failure.call, success.call]; expect( - tester().combine(), + tester().combine(seed), isA(), reason: 'should return a Failure', ); @@ -236,27 +286,404 @@ void main() { expect( failure.count, equals(1), - reason: '"failure" should be called once', + reason: 'should be called once', ); expect( success.count, equals(0), - reason: '"success" should not be called', + reason: 'should not be called', ); }); + test( - 'GIVEN tester contains only "success"s nullary ' + 'GIVEN tester contains only "success" ' 'WHEN tester().combine() ' - 'THEN success Success', () { + 'THEN result is a Success', () { tester.stub = () => [success.call, success.call]; expect( - tester().combine(), - isA(), - reason: 'should return a Success', + tester().combine(seed).isSuccess, + isTrue, + reason: 'should return a success', + ); + }); + + test( + 'GIVEN tester contains 2 "success" ' + 'WHEN tester().combine() ' + 'THEN success is called twice', () { + tester.stub = () => [success.call, success.call]; + tester().combine(seed); + expect( + success.count, + equals(2), + reason: 'should be called twice', ); }); }); + + group(' combineVoid Test', () { + group('combine Test', () { + final failure = Stub.unary, int>() + ..stub = (i) => Result.failure(); + + final success = Stub.unary, int>() + ..stub = (i) => Result.success(true); + + final tester = Stub.nullary>>(); + + setUp(() { + tester.reset(); + failure.reset(); + success.reset(); + }); + + test( + 'GIVEN tester is a Iterable> ' + 'WHEN tester().combineVoid ' + 'THEN returns a VoidResultUnary', () { + tester.stub = () => []; + + expect( + tester().combineVoid, + isA>(), + reason: 'Type should be predictable', + ); + }); + + test( + 'GIVEN tester contains "failure" ' + 'WHEN tester().combineVoid() ' + 'THEN returns a Failure', () { + tester.stub = () => [failure.call, success.call]; + + expect( + tester().combineVoid(seed), + isA(), + reason: 'should return a Failure', + ); + + expect( + failure.count, + equals(1), + reason: 'should be called once', + ); + }); + + test( + 'GIVEN tester contains "failure" ' + 'WHEN tester().combineVoid() ' + 'THEN returns a VoidResult', () { + tester.stub = () => [failure.call, success.call]; + + expect( + tester().combineVoid(seed), + isA(), + reason: 'should return a Failure', + ); + + expect( + failure.count, + equals(1), + reason: 'should be called once', + ); + }); + + test( + 'GIVEN tester contains "failure" before "success" ' + 'WHEN tester().combine() ' + 'THEN success is never called', () { + tester.stub = () => [failure.call, success.call]; + + expect( + tester().combineVoid(seed), + isA(), + reason: 'should return a Failure', + ); + + expect( + failure.count, + equals(1), + reason: 'should be called once', + ); + + expect( + success.count, + equals(0), + reason: 'should not be called', + ); + }); + + test( + 'GIVEN tester contains only "success" ' + 'WHEN tester().combine() ' + 'THEN result is a Success', () { + tester.stub = () => [success.call, success.call]; + + expect( + tester().combineVoid(seed).isSuccess, + isTrue, + reason: 'should return a success', + ); + }); + + test( + 'GIVEN tester contains 2 "success" ' + 'WHEN tester().combine() ' + 'THEN success is called twice', () { + tester.stub = () => [success.call, success.call]; + tester().combineVoid(seed); + expect( + success.count, + equals(2), + reason: 'should be called twice', + ); + }); + }); + }); }); } + // group('combine', () { + // final failure = Stub.nullary>() + // ..stub = () => const Failure(); + + // final success = Stub.nullary>() + // ..stub = () => Success.value(0); + + // final tester = Stub.nullary>>(); + + // setUp(() { + // tester.reset(); + // failure.reset(); + // success.reset(); + // }); + + + // test( + // 'GIVEN tester contains "failure" nullary ' + // 'WHEN tester().combine() ' + // 'THEN success Failure', () { + // tester.stub = () => [failure.call, success.call]; + + // expect( + // tester().combine(), + // isA(), + // reason: 'should return a Failure', + // ); + + // expect( + // failure.count, + // equals(1), + // reason: 'should be called once', + // ); + // }); + + // test( + // 'GIVEN tester contains "failure" nullary ' + // 'WHEN tester().combine() ' + // 'THEN functions after "failure" are not called', () { + // tester.stub = () => [failure.call, success.call]; + + // expect( + // tester().combine(), + // isA(), + // reason: 'should return a Failure', + // ); + + // expect( + // failure.count, + // equals(1), + // reason: '"failure" should be called once', + // ); + + // expect( + // success.count, + // equals(0), + // reason: '"success" should not be called', + // ); + // }); + // test( + // 'GIVEN tester contains only "success"s nullary ' + // 'WHEN tester().combine() ' + // 'THEN success Success', () { + // tester.stub = () => [success.call, success.call]; + + // expect( + // tester().combine(), + // isA(), + // reason: 'should return a Success', + // ); + // }); + // }); + + // group('combineVoid', () { + // final failure = Stub.nullary>() + // ..stub = () => const Failure(); + + // final success = Stub.nullary>() + // ..stub = () => Success.value(0); + + // final tester = Stub.nullary>>(); + + // setUp(() { + // tester.reset(); + // failure.reset(); + // success.reset(); + // }); + + // test( + // 'GIVEN tester is a Iterable> ' + // 'WHEN tester().combineVoid ' + // 'THEN success a ValueResult>', () { + // tester.stub = () => []; + + // expect( + // tester().combineVoid, + // isA(), + // reason: 'Type should be predictable', + // ); + // }); + + // test( + // 'GIVEN tester contains "failure" nullary ' + // 'WHEN tester().combineVoid() ' + // 'THEN success Failure', () { + // tester.stub = () => [failure.call, success.call]; + + // expect( + // tester().combineVoid(), + // isA(), + // reason: 'should return a Failure', + // ); + + // expect( + // failure.count, + // equals(1), + // reason: 'should be called once', + // ); + // }); + + // test( + // 'GIVEN tester contains "failure" nullary ' + // 'WHEN tester().combineVoid() ' + // 'THEN functions after "failure" are not called', () { + // tester.stub = () => [failure.call, success.call]; + + // expect( + // tester().combineVoid(), + // isA(), + // reason: 'should return a Failure', + // ); + + // expect( + // failure.count, + // equals(1), + // reason: '"failure" should be called once', + // ); + + // expect( + // success.count, + // equals(0), + // reason: '"success" should not be called', + // ); + // }); + // test( + // 'GIVEN tester contains only "success"s nullary ' + // 'WHEN tester().combineVoid() ' + // 'THEN success Success', () { + // tester.stub = () => [success.call, success.call]; + + // expect( + // tester().combineVoid(), + // isA(), + // reason: 'should return a Success', + // ); + // }); + // }); + // }); + // group('IterableNullaryCombineVoidResultX', () { + // group('combine', () { + // final failure = Stub.nullary()..stub = () => const Failure(); + + // final success = Stub.nullary()..stub = () => Success.empty; + + // final tester = Stub.nullary>(); + + // setUp(() { + // tester.reset(); + // failure.reset(); + // success.reset(); + // }); + + // test( + // 'GIVEN tester is a Iterable ' + // 'WHEN tester().combine ' + // 'THEN success a ValueResult>', () { + // tester.stub = () => []; + + // expect( + // tester().combine, + // isA(), + // reason: 'Type should be predictable', + // ); + // }); + + // test( + // 'GIVEN tester contains "failure" nullary ' + // 'WHEN tester().combine() ' + // 'THEN success Failure', () { + // tester.stub = () => [failure.call, success.call]; + + // expect( + // tester().combine(), + // isA(), + // reason: 'should return a Failure', + // ); + + // expect( + // failure.count, + // equals(1), + // reason: 'should be called once', + // ); + // }); + + // test( + // 'GIVEN tester contains "failure" nullary ' + // 'WHEN tester().combine() ' + // 'THEN functions after "failure" are not called', () { + // tester.stub = () => [failure.call, success.call]; + + // expect( + // tester().combine(), + // isA(), + // reason: 'should return a Failure', + // ); + + // expect( + // failure.count, + // equals(1), + // reason: '"failure" should be called once', + // ); + + // expect( + // success.count, + // equals(0), + // reason: '"success" should not be called', + // ); + // }); + // test( + // 'GIVEN tester contains only "success"s nullary ' + // 'WHEN tester().combine() ' + // 'THEN success Success', () { + // tester.stub = () => [success.call, success.call]; + + // expect( + // tester().combine(), + // isA(), + // reason: 'should return a Success', + // ); + // }); + // }); + // }); +// } diff --git a/packages/yak_result/test/extensions/iterable_combine_unary_test.dart b/packages/yak_result/test/extensions/iterable_combine_unary_test.dart deleted file mode 100644 index 2fadd622..00000000 --- a/packages/yak_result/test/extensions/iterable_combine_unary_test.dart +++ /dev/null @@ -1,266 +0,0 @@ -import 'package:test/test.dart'; -import 'package:stub/stub.dart'; - -import 'package:yak_result/yak_result.dart'; - -void main() { - const seed = 0; - - group('IterableUnaryCombineValueResultX', () { - group('combine', () { - final failure = Stub.unary, int>() - ..stub = (i) => const Failure(); - - final success = Stub.unary, int>() - ..stub = (i) => Success.value(i); - - final tester = Stub.nullary>>(); - - setUp(() { - tester.reset(); - failure.reset(); - success.reset(); - }); - - test( - 'GIVEN tester is a Iterable> ' - 'WHEN tester().combine ' - 'THEN success a ValueResult>', () { - tester.stub = () => []; - - expect( - tester().combine, - isA, int>>(), - reason: 'Type should be predictable', - ); - }); - - test( - 'GIVEN tester contains "failure" nullary ' - 'WHEN tester().combine() ' - 'THEN success Failure', () { - tester.stub = () => [failure.call, success.call]; - - expect( - tester().combine(seed), - isA(), - reason: 'should return a Failure', - ); - - expect( - failure.count, - equals(1), - reason: 'should be called once', - ); - }); - - test( - 'GIVEN tester contains "failure" nullary ' - 'WHEN tester().combine() ' - 'THEN functions after "failure" are not called', () { - tester.stub = () => [failure.call, success.call]; - - expect( - tester().combine(seed), - isA(), - reason: 'should return a Failure', - ); - - expect( - failure.count, - equals(1), - reason: '"failure" should be called once', - ); - - expect( - success.count, - equals(0), - reason: '"success" should not be called', - ); - }); - test( - 'GIVEN tester contains only "success"s nullary ' - 'WHEN tester().combine() ' - 'THEN success Success', () { - tester.stub = () => [success.call, success.call]; - - expect( - tester().combine(seed), - isA(), - reason: 'should return a Success', - ); - }); - }); - - group('combineVoid', () { - final failure = Stub.unary, int>() - ..stub = (i) => const Failure(); - - final success = Stub.unary, int>() - ..stub = (i) => Success.value(i); - - final tester = Stub.nullary>>(); - - setUp(() { - tester.reset(); - failure.reset(); - success.reset(); - }); - - test( - 'GIVEN tester is a Iterable> ' - 'WHEN tester().combineVoid ' - 'THEN success a ValueResult>', () { - tester.stub = () => []; - - expect( - tester().combineVoid, - isA>(), - reason: 'Type should be predictable', - ); - }); - - test( - 'GIVEN tester contains "failure" nullary ' - 'WHEN tester().combineVoid() ' - 'THEN success Failure', () { - tester.stub = () => [failure.call, success.call]; - - expect( - tester().combineVoid(seed), - isA(), - reason: 'should return a Failure', - ); - - expect( - failure.count, - equals(1), - reason: 'should be called once', - ); - }); - - test( - 'GIVEN tester contains "failure" nullary ' - 'WHEN tester().combineVoid() ' - 'THEN functions after "failure" are not called', () { - tester.stub = () => [failure.call, success.call]; - - expect( - tester().combineVoid(seed), - isA(), - reason: 'should return a Failure', - ); - - expect( - failure.count, - equals(1), - reason: '"failure" should be called once', - ); - - expect( - success.count, - equals(0), - reason: '"success" should not be called', - ); - }); - test( - 'GIVEN tester contains only "success"s nullary ' - 'WHEN tester().combineVoid() ' - 'THEN success Success', () { - tester.stub = () => [success.call, success.call]; - - expect( - tester().combineVoid(seed), - isA(), - reason: 'should return a Success', - ); - }); - }); - }); - group('IterableUnaryCombineVoidResultX', () { - group('combine', () { - final failure = Stub.unary, int>() - ..stub = (i) => const Failure(); - - final success = Stub.unary, int>() - ..stub = (i) => Success.empty; - - final tester = Stub.nullary>>(); - - setUp(() { - tester.reset(); - failure.reset(); - success.reset(); - }); - - test( - 'GIVEN tester is a Iterable ' - 'WHEN tester().combine ' - 'THEN success a ValueResult>', () { - tester.stub = () => []; - - expect( - tester().combine, - isA>(), - reason: 'Type should be predictable', - ); - }); - - test( - 'GIVEN tester contains "failure" nullary ' - 'WHEN tester().combine() ' - 'THEN success Failure', () { - tester.stub = () => [failure.call, success.call]; - - expect( - tester().combine(seed), - isA(), - reason: 'should return a Failure', - ); - - expect( - failure.count, - equals(1), - reason: 'should be called once', - ); - }); - - test( - 'GIVEN tester contains "failure" nullary ' - 'WHEN tester().combine() ' - 'THEN functions after "failure" are not called', () { - tester.stub = () => [failure.call, success.call]; - - expect( - tester().combine(seed), - isA(), - reason: 'should return a Failure', - ); - - expect( - failure.count, - equals(1), - reason: '"failure" should be called once', - ); - - expect( - success.count, - equals(0), - reason: '"success" should not be called', - ); - }); - test( - 'GIVEN tester contains only "success"s nullary ' - 'WHEN tester().combine() ' - 'THEN success Success', () { - tester.stub = () => [success.call, success.call]; - - expect( - tester().combine(seed), - isA(), - reason: 'should return a Success', - ); - }); - }); - }); -} diff --git a/packages/yak_result/test/extensions/recast_test.dart b/packages/yak_result/test/extensions/recast_test.dart new file mode 100644 index 00000000..f4fc8516 --- /dev/null +++ b/packages/yak_result/test/extensions/recast_test.dart @@ -0,0 +1,123 @@ +import 'package:test/test.dart'; +import 'package:yak_result/yak_result.dart'; + +void main() { + const reason = 0; + final stackTrace = StackTrace.fromString('stackTraceString'); + final failure = Failure(reason, stackTrace); + group('Failure recast() Test ', () { + test( + 'GIVEN Failure ' + 'WHEN recast() ' + 'THEN return a Failure', () { + expect( + failure.recast(), + isA>(), + reason: 'should be a Failure of the exact type', + ); + }); + test( + 'GIVEN Failure ' + 'WHEN recast() ' + 'THEN return a Failure with same reason', () { + expect( + failure.recast().asFailure.reason, + equals(reason), + reason: 'reason should match', + ); + }); + test( + 'GIVEN Failure ' + 'WHEN recast() ' + 'THEN return a Failure with same stacktrace', () { + expect( + failure.recast().asFailure.stackTrace, + equals(stackTrace), + reason: 'stackTrace should match', + ); + }); + }); + + group('Failure asVoid() Test ', () { + test( + 'GIVEN Failure ' + 'WHEN asVoid() ' + 'THEN return a Failure', () { + expect( + failure.asVoid(), + isA>(), + reason: 'should be a Failure of the exact type', + ); + }); + test( + 'GIVEN Failure ' + 'WHEN asVoid() ' + 'THEN return a VoidResult', () { + expect( + failure.asVoid(), + isA(), + reason: 'should be a Failure of the exact type', + ); + }); + test( + 'GIVEN Failure ' + 'WHEN asVoid() ' + 'THEN return a Failure with same reason', () { + expect( + failure.asVoid().asFailure.reason, + equals(reason), + reason: 'reason should match', + ); + }); + test( + 'GIVEN Failure ' + 'WHEN asVoid() ' + 'THEN return a Failure with same stacktrace', () { + expect( + failure.asVoid().asFailure.stackTrace, + equals(stackTrace), + reason: 'stackTrace should match', + ); + }); + }); + + group('Result asVoid() Test ', () { + test( + 'GIVEN Result ' + 'WHEN asVoid() ' + 'THEN return a VoidResult', () { + final result = const Result.success(true); + + expect( + result.asVoid(), + isA(), + reason: 'should be a Failure of the exact type', + ); + }); + + test( + 'GIVEN Result.failure ' + 'WHEN asVoid() ' + 'THEN return a Failure with same reason', () { + final result = Result.failure(reason, stackTrace); + + expect( + result.asVoid().asFailure.reason, + equals(reason), + reason: 'reason should match', + ); + }); + test( + 'GIVEN Result.failure ' + 'WHEN recast() ' + 'THEN return a Failure with same stacktrace', () { + final result = Result.failure(reason, stackTrace); + + expect( + result.asVoid().asFailure.stackTrace, + equals(stackTrace), + reason: 'stackTrace should match', + ); + }); + }); +} From 9eb9828f42dc57410f671424caa0f7714d14041d Mon Sep 17 00:00:00 2001 From: Francesco Iapicca Date: Wed, 17 Apr 2024 17:48:06 +0300 Subject: [PATCH 2/7] adjust to yak_runner v3 --- .../lib/src/extension/iterable_run.dart | 23 +++++++++++---- .../yak_runner/lib/src/extension/let_run.dart | 22 +++++++------- .../yak_runner/lib/src/extension/run.dart | 20 ++++++++++--- .../lib/src/extension/then_run.dart | 29 +++++++++++-------- .../lib/src/runner/value/run_nullary.dart | 11 ++++--- .../src/runner/value/run_nullary_async.dart | 12 ++++---- .../lib/src/runner/value/run_unary.dart | 13 +++++---- .../lib/src/runner/value/run_unary_async.dart | 13 +++++---- .../lib/src/runner/void/run_nullary.dart | 9 +++--- .../src/runner/void/run_nullary_async.dart | 8 ++--- .../lib/src/runner/void/run_unary.dart | 9 +++--- .../lib/src/runner/void/run_unary_async.dart | 8 ++--- .../test/extensions/let_run_test.dart | 12 ++++---- .../test/extensions/then_run_test.dart | 12 ++++---- 14 files changed, 115 insertions(+), 86 deletions(-) diff --git a/packages/yak_runner/lib/src/extension/iterable_run.dart b/packages/yak_runner/lib/src/extension/iterable_run.dart index 42cd96f0..9b14e2d1 100644 --- a/packages/yak_runner/lib/src/extension/iterable_run.dart +++ b/packages/yak_runner/lib/src/extension/iterable_run.dart @@ -1,10 +1,12 @@ import 'package:yak_result/yak_result.dart'; import 'package:yak_utils/yak_utils.dart'; -import '../all.dart'; +import 'run.dart'; -extension IterableNullaryToResultNullaryX on Iterable> { +extension IterableNullaryToResultNullaryX + on Iterable> { /// returns Iterable> from Iterable> + /// TODO REWORK ITERATOR https://github.com/yakforward-ou/yak_packages/issues/238 Iterable> get run sync* { for (final function in this) { yield function.run; @@ -12,6 +14,7 @@ extension IterableNullaryToResultNullaryX on Iterable> { } /// returns Iterable from Iterable> + /// TODO REWORK ITERATOR https://github.com/yakforward-ou/yak_packages/issues/238 Iterable get runVoid sync* { for (final function in this) { yield function.runVoid; @@ -19,15 +22,20 @@ extension IterableNullaryToResultNullaryX on Iterable> { } } -extension IterableUnaryToResultUnaryX on Iterable> { +extension IterableUnaryToResultUnaryX + on Iterable> { /// returns Iterable> from Iterable> + /// TODO REWORK ITERATOR https://github.com/yakforward-ou/yak_packages/issues/238 Iterable> get run sync* { for (final function in this) { yield function.run; } } +} +extension IterableUnaryToResultUnaryVoidX on Iterable> { /// returns Iterable> from Iterable> + /// TODO REWORK ITERATOR https://github.com/yakforward-ou/yak_packages/issues/238 Iterable> get runVoid sync* { for (final function in this) { yield function.runVoid; @@ -35,9 +43,10 @@ extension IterableUnaryToResultUnaryX on Iterable> { } } -extension IterableNullaryToResultNullaryAsyncX +extension IterableNullaryToResultNullaryAsyncX on Iterable> { /// returns Iterable> from Iterable> + /// TODO REWORK ITERATOR https://github.com/yakforward-ou/yak_packages/issues/238 Iterable> get runAsync sync* { for (final function in this) { yield function.runAsync; @@ -45,6 +54,8 @@ extension IterableNullaryToResultNullaryAsyncX } /// returns Iterable from Iterable> + /// TODO REWORK ITERATOR https://github.com/yakforward-ou/yak_packages/issues/238 + Iterable get runVoidAsync sync* { for (final function in this) { yield function.runVoidAsync; @@ -52,9 +63,10 @@ extension IterableNullaryToResultNullaryAsyncX } } -extension IterableUnaryToResultUnaryAsyncX +extension IterableUnaryToResultUnaryAsyncX on Iterable> { /// returns Iterable> from Iterable> + /// TODO REWORK ITERATOR https://github.com/yakforward-ou/yak_packages/issues/238 Iterable> get runAsync sync* { for (final function in this) { yield function.runAsync; @@ -62,6 +74,7 @@ extension IterableUnaryToResultUnaryAsyncX } /// returns Iterable> from Iterable> + /// TODO REWORK ITERATOR https://github.com/yakforward-ou/yak_packages/issues/238 Iterable> get runVoidAsync sync* { for (final function in this) { yield function.runVoidAsync; diff --git a/packages/yak_runner/lib/src/extension/let_run.dart b/packages/yak_runner/lib/src/extension/let_run.dart index 4be0e395..0ec01b86 100644 --- a/packages/yak_runner/lib/src/extension/let_run.dart +++ b/packages/yak_runner/lib/src/extension/let_run.dart @@ -1,21 +1,21 @@ import 'package:yak_result/yak_result.dart'; import 'package:yak_utils/yak_utils.dart'; -import '../all.dart'; +import 'run.dart'; -/// syntactic sugar to pass a [ValueResult] to a [ResultUnary] -extension ValueResultLetRunX on ValueResult { - ValueResult letRun(Unary function) => - isSuccess ? function.run(success.value) : failure.recast(); +/// syntactic sugar to pass a [Result] to a [ResultUnary] +extension ResultLetRunX on Result { + Result letRun(Unary function) => + isSuccess ? function.run(asSuccess) : asFailure.recast(); - VoidResult letRunVoid(Unary function) => - isSuccess ? function.runVoid(success.value) : failure.recast(); + VoidResult letRunVoid(Unary function) => + isSuccess ? function.runVoid(asSuccess) : asFailure.asVoid(); } /// syntactic sugar to pass a [VoidResult] to a [ResultNullary] extension VoidResultLetRunX on VoidResult { - ValueResult letRun(Nullary function) => - isSuccess ? function.run() : failure.recast(); + Result letRun(Nullary function) => + isSuccess ? function.run() : asFailure.recast(); - VoidResult letRunVoid(Nullary function) => - isSuccess ? function.runVoid() : failure.recast(); + VoidResult letRunVoid(Nullary function) => + isSuccess ? function.runVoid() : asFailure.asVoid(); } diff --git a/packages/yak_runner/lib/src/extension/run.dart b/packages/yak_runner/lib/src/extension/run.dart index 6eee74ad..a33bd8ec 100644 --- a/packages/yak_runner/lib/src/extension/run.dart +++ b/packages/yak_runner/lib/src/extension/run.dart @@ -5,7 +5,7 @@ import '../runner/all.dart'; /// [ResultNullaryX] turns a [Nullary] function /// into a [ResultNullary] function -extension ResultNullaryX on Nullary { +extension ResultNullaryX on Nullary { /// turns a [Nullary[ function into a [ResultNullary[ function /// eg: //** @@ -22,7 +22,7 @@ extension ResultNullaryX on Nullary { /// [ResultNullaryFutureOrX] turns a [NullaryFutureOr] function /// into a [ResultNullaryAsync] function -extension ResultNullaryFutureOrX on NullaryFutureOr { +extension ResultNullaryFutureOrX on NullaryFutureOr { /// turns a [Nullary[ function into a [ResultNullary[ function /// eg: //** @@ -33,13 +33,15 @@ extension ResultNullaryFutureOrX on NullaryFutureOr { // ``` // */ ResultNullaryAsync get runAsync => nullaryRunAsync(this); +} +extension ResultNullaryFutureOrVoidX on NullaryFutureOr { VoidResultNullaryAsync get runVoidAsync => nullaryRunVoidAsync(this); } /// [ResultUnaryX] turns a [Unary function /// into a [ResultUnary] function -extension ResultUnaryX on Unary { +extension ResultUnaryX on Unary { /// turns a [Unary[ function into a [ResultUnary[ function /// eg: //** @@ -54,9 +56,15 @@ extension ResultUnaryX on Unary { VoidResultUnary get runVoid => unaryRunVoid(this); } +/// [ResultUnaryX] turns a [Unary function +/// into a [ResultUnary] function +extension ResultUnaryVoidX on Unary { + VoidResultUnary get runVoid => unaryRunVoid(this); +} + /// [ResultUnaryFutureOrX] turns a [UnaryFutureOr] function /// into a [ResultUnaryAsync] function -extension ResultUnaryFutureOrX on UnaryFutureOr { +extension ResultUnaryFutureOrX on UnaryFutureOr { /// turns a [UnaryAsync[ function into a [ResultUnaryAsync[ function /// eg: //** @@ -67,6 +75,10 @@ extension ResultUnaryFutureOrX on UnaryFutureOr { // ``` // */ ResultUnaryAsync get runAsync => unaryRunAsync(this); +} +/// [ResultUnaryFutureOrX] turns a [UnaryFutureOr] function +/// into a [ResultUnaryAsync] function +extension ResultUnaryFutureOrVoidX on UnaryFutureOr { VoidResultUnaryAsync get runVoidAsync => unaryRunVoidAsync(this); } diff --git a/packages/yak_runner/lib/src/extension/then_run.dart b/packages/yak_runner/lib/src/extension/then_run.dart index 7aabc7b4..69874b58 100644 --- a/packages/yak_runner/lib/src/extension/then_run.dart +++ b/packages/yak_runner/lib/src/extension/then_run.dart @@ -1,36 +1,41 @@ import 'dart:async'; import 'package:yak_result/yak_result.dart'; +import 'package:yak_runner/src/all.dart'; import 'package:yak_utils/yak_utils.dart'; -import '../all.dart'; -/// syntactic sugar to pass a [FutureValueResult] to a [UnaryFutureOr] -extension ThenRunUnaryX on FutureValueResult { - FutureValueResult thenRun(UnaryFutureOr function) => +/// syntactic sugar to pass a [FutureResult] to a [UnaryFutureOr] +extension ThenRunUnaryX on FutureResult { + FutureResult thenRun(UnaryFutureOr function) => Future.sync(() => this).then( (result) => result.isSuccess - ? function.runAsync(result.success.value) - : result.failure.recast(), + ? function.runAsync(result.asSuccess) + : result.asFailure.recast(), ); +} +/// syntactic sugar to pass a [FutureResult] to a [UnaryFutureOr] +extension ThenRunUnaryVoidX on FutureResult { FutureVoidResult thenRunVoid(UnaryFutureOr function) => Future.sync(() => this).then( (result) => result.isSuccess - ? function.runVoidAsync(result.success.value) - : result.failure.recast(), + ? function.runVoidAsync(result.asSuccess) + : result.asFailure.asVoid(), ); } /// syntactic sugar to pass a [FutureVoidResult] to a [NullaryFutureOr] -extension ThenRunNullaryX on FutureVoidResult { - FutureValueResult thenRun(NullaryFutureOr function) => +extension ThenRunNullaryX on FutureVoidResult { + FutureResult thenRun(NullaryFutureOr function) => Future.sync(() => this).then( (result) => - result.isSuccess ? function.runAsync() : result.failure.recast(), + result.isSuccess ? function.runAsync() : result.asFailure.recast(), ); FutureVoidResult thenRunVoid(NullaryFutureOr function) => Future.sync(() => this).then( - (result) => result.isSuccess ? function.runVoidAsync() : result.failure, + (result) => result.isSuccess + ? function.runVoidAsync() + : result.asFailure.asVoid(), ); } diff --git a/packages/yak_runner/lib/src/runner/value/run_nullary.dart b/packages/yak_runner/lib/src/runner/value/run_nullary.dart index 81dd5b9f..c1e854d8 100644 --- a/packages/yak_runner/lib/src/runner/value/run_nullary.dart +++ b/packages/yak_runner/lib/src/runner/value/run_nullary.dart @@ -1,14 +1,13 @@ -import 'package:yak_result/yak_result.dart' - show ResultNullary, ValueSuccess, Failure; +import 'package:yak_result/yak_result.dart' show ResultNullary, Result; import 'package:yak_utils/yak_utils.dart' show Nullary; /// takes as argument a [Nullary] returns a [ResultNullary] -ResultNullary nullaryRun(Nullary function) => () { +ResultNullary nullaryRun(Nullary function) => () { try { - return ValueSuccess(function()); + return Result.success(function()); } on Error catch (e) { - return Failure.fromError(e); + return Result.failure(e, e.stackTrace ?? StackTrace.empty); } on Exception catch (e, s) { - return Failure(e, s); + return Result.failure(e, s); } }; diff --git a/packages/yak_runner/lib/src/runner/value/run_nullary_async.dart b/packages/yak_runner/lib/src/runner/value/run_nullary_async.dart index 16f0c6e6..d13f1d92 100644 --- a/packages/yak_runner/lib/src/runner/value/run_nullary_async.dart +++ b/packages/yak_runner/lib/src/runner/value/run_nullary_async.dart @@ -1,15 +1,15 @@ -import 'package:yak_result/yak_result.dart' - show ResultNullaryAsync, ValueSuccess, Failure; +import 'package:yak_result/yak_result.dart' show ResultNullaryAsync, Result; import 'package:yak_utils/yak_utils.dart' show NullaryFutureOr; /// takes as argument a [NullaryFutureOr] returns a [ResultNullaryAsync] -ResultNullaryAsync nullaryRunAsync(NullaryFutureOr function) => +ResultNullaryAsync nullaryRunAsync( + NullaryFutureOr function) => () async { try { - return ValueSuccess(await function()); + return Result.success(await function()); } on Error catch (e) { - return Failure.fromError(e); + return Result.failure(e, e.stackTrace ?? StackTrace.empty); } on Exception catch (e, s) { - return Failure(e, s); + return Result.failure(e, s); } }; diff --git a/packages/yak_runner/lib/src/runner/value/run_unary.dart b/packages/yak_runner/lib/src/runner/value/run_unary.dart index 5d22d0a4..5787ad20 100644 --- a/packages/yak_runner/lib/src/runner/value/run_unary.dart +++ b/packages/yak_runner/lib/src/runner/value/run_unary.dart @@ -1,14 +1,15 @@ -import 'package:yak_result/yak_result.dart' - show ResultUnary, ValueSuccess, Failure; +import 'package:yak_result/yak_result.dart' show ResultUnary, Result; import 'package:yak_utils/yak_utils.dart' show Unary; /// takes as argument a [Unary] returns a [ResultUnary] -ResultUnary unaryRun(Unary function) => (S arg) { +ResultUnary unaryRun( + Unary function) => + (S arg) { try { - return ValueSuccess(function(arg)); + return Result.success(function(arg)); } on Error catch (e) { - return Failure.fromError(e); + return Result.failure(e, e.stackTrace ?? StackTrace.empty); } on Exception catch (e, s) { - return Failure(e, s); + return Result.failure(e, s); } }; diff --git a/packages/yak_runner/lib/src/runner/value/run_unary_async.dart b/packages/yak_runner/lib/src/runner/value/run_unary_async.dart index 1138eba5..10575190 100644 --- a/packages/yak_runner/lib/src/runner/value/run_unary_async.dart +++ b/packages/yak_runner/lib/src/runner/value/run_unary_async.dart @@ -1,15 +1,16 @@ -import 'package:yak_result/yak_result.dart' - show ResultUnaryAsync, ValueSuccess, Failure; +import 'package:yak_result/yak_result.dart' show ResultUnaryAsync, Result; + import 'package:yak_utils/yak_utils.dart' show UnaryFutureOr; /// takes as argument a [UnaryFutureOr] returns a [ResultUnaryAsync] -ResultUnaryAsync unaryRunAsync(UnaryFutureOr function) => +ResultUnaryAsync unaryRunAsync( + UnaryFutureOr function) => (S arg) async { try { - return ValueSuccess(await function(arg)); + return Result.success(await function(arg)); } on Error catch (e) { - return Failure.fromError(e); + return Result.failure(e, e.stackTrace ?? StackTrace.empty); } on Exception catch (e, s) { - return Failure(e, s); + return Result.failure(e, s); } }; diff --git a/packages/yak_runner/lib/src/runner/void/run_nullary.dart b/packages/yak_runner/lib/src/runner/void/run_nullary.dart index 59b06bb3..5d10ca2e 100644 --- a/packages/yak_runner/lib/src/runner/void/run_nullary.dart +++ b/packages/yak_runner/lib/src/runner/void/run_nullary.dart @@ -1,15 +1,14 @@ -import 'package:yak_result/yak_result.dart' - show VoidResultNullary, VoidSuccess, Failure; +import 'package:yak_result/yak_result.dart' show VoidResultNullary, VoidResult; import 'package:yak_utils/yak_utils.dart' show Nullary; /// takes as argument a [Nullary] returns a [VoidResultNullary] VoidResultNullary nullaryRunVoid(Nullary function) => () { try { function(); - return const VoidSuccess(); + return const VoidResult.success(); } on Error catch (e) { - return Failure.fromError(e); + return VoidResult.failure(e, e.stackTrace ?? StackTrace.empty); } on Exception catch (e, s) { - return Failure(e, s); + return VoidResult.failure(e, s); } }; diff --git a/packages/yak_runner/lib/src/runner/void/run_nullary_async.dart b/packages/yak_runner/lib/src/runner/void/run_nullary_async.dart index 206ceb5c..b9b1f144 100644 --- a/packages/yak_runner/lib/src/runner/void/run_nullary_async.dart +++ b/packages/yak_runner/lib/src/runner/void/run_nullary_async.dart @@ -1,5 +1,5 @@ import 'package:yak_result/yak_result.dart' - show VoidResultNullaryAsync, VoidSuccess, Failure; + show VoidResultNullaryAsync, VoidResult; import 'package:yak_utils/yak_utils.dart' show NullaryFutureOr; /// takes as argument a [NullaryAsync] returns a [VoidResultNullaryAsync] @@ -7,10 +7,10 @@ VoidResultNullaryAsync nullaryRunVoidAsync(NullaryFutureOr function) => () async { try { await function(); - return const VoidSuccess(); + return const VoidResult.success(); } on Error catch (e) { - return Failure.fromError(e); + return VoidResult.failure(e, e.stackTrace ?? StackTrace.empty); } on Exception catch (e, s) { - return Failure(e, s); + return VoidResult.failure(e, s); } }; diff --git a/packages/yak_runner/lib/src/runner/void/run_unary.dart b/packages/yak_runner/lib/src/runner/void/run_unary.dart index cd3b30df..1dde51ae 100644 --- a/packages/yak_runner/lib/src/runner/void/run_unary.dart +++ b/packages/yak_runner/lib/src/runner/void/run_unary.dart @@ -1,15 +1,14 @@ -import 'package:yak_result/yak_result.dart' - show VoidResultUnary, VoidSuccess, Failure; +import 'package:yak_result/yak_result.dart' show VoidResultUnary, VoidResult; import 'package:yak_utils/yak_utils.dart' show Unary; /// takes as argument a [Unary] returns a [VoidResultUnary] VoidResultUnary unaryRunVoid(Unary function) => (S arg) { try { function(arg); - return const VoidSuccess(); + return const VoidResult.success(); } on Error catch (e) { - return Failure.fromError(e); + return VoidResult.failure(e, e.stackTrace ?? StackTrace.empty); } on Exception catch (e, s) { - return Failure(e, s); + return VoidResult.failure(e, s); } }; diff --git a/packages/yak_runner/lib/src/runner/void/run_unary_async.dart b/packages/yak_runner/lib/src/runner/void/run_unary_async.dart index 675a1228..4e3bd1ae 100644 --- a/packages/yak_runner/lib/src/runner/void/run_unary_async.dart +++ b/packages/yak_runner/lib/src/runner/void/run_unary_async.dart @@ -1,5 +1,5 @@ import 'package:yak_result/yak_result.dart' - show VoidResultUnaryAsync, VoidSuccess, Failure; + show VoidResultUnaryAsync, VoidResult; import 'package:yak_utils/yak_utils.dart' show UnaryFutureOr; /// takes as argument a [UnaryAsync] returns a [VoidResultUnaryAsync] @@ -9,10 +9,10 @@ VoidResultUnaryAsync unaryRunVoidAsync( (S arg) async { try { await function(arg); - return const VoidSuccess(); + return const VoidResult.success(); } on Error catch (e) { - return Failure.fromError(e); + return VoidResult.failure(e, e.stackTrace ?? StackTrace.empty); } on Exception catch (e, s) { - return Failure(e, s); + return VoidResult.failure(e, s); } }; diff --git a/packages/yak_runner/test/extensions/let_run_test.dart b/packages/yak_runner/test/extensions/let_run_test.dart index 971e0c9e..42cb067f 100644 --- a/packages/yak_runner/test/extensions/let_run_test.dart +++ b/packages/yak_runner/test/extensions/let_run_test.dart @@ -3,11 +3,11 @@ import 'package:test/test.dart'; import 'package:yak_runner/yak_runner.dart'; void main() { - group('ValueResultLetRunX', () { + group('ResultLetRunX', () { group('letRun', () { group('Success', () { - final tester = Stub.nullary>() - ..stub = () => ValueSuccess(0); + final tester = Stub.nullary>() + ..stub = () => Result.success(0); final function = Stub.unary(); setUp(() { @@ -55,7 +55,7 @@ void main() { }); group('Failure', () { - final tester = Stub.nullary>()..stub = () => Failure(); + final tester = Stub.nullary>()..stub = () => Failure(); final function = Stub.unary(); setUp(() { @@ -105,8 +105,8 @@ void main() { group('thenRunVoid', () { group('Success', () { - final tester = Stub.nullary>() - ..stub = () => ValueSuccess(0); + final tester = Stub.nullary>() + ..stub = () => Result.success(0); final function = Stub.unary(); setUp(() { diff --git a/packages/yak_runner/test/extensions/then_run_test.dart b/packages/yak_runner/test/extensions/then_run_test.dart index 901a1682..21013b02 100644 --- a/packages/yak_runner/test/extensions/then_run_test.dart +++ b/packages/yak_runner/test/extensions/then_run_test.dart @@ -10,8 +10,8 @@ void main() { group('thenRun', () { group('Success', () { - final tester = Stub.nullary>() - ..stub = () => Future.value(ValueSuccess(0)); + final tester = Stub.nullary>() + ..stub = () => Future.value(Result.success(0)); setUp(() { tester.reset(); function.reset(); @@ -57,7 +57,7 @@ void main() { }); group('Failure', () { - final tester = Stub.nullary>() + final tester = Stub.nullary>() ..stub = () => Future.value(Failure()); setUp(() { @@ -107,8 +107,8 @@ void main() { group('thenRunVoid', () { group('Success', () { - final tester = Stub.nullary>() - ..stub = () => Future.value(ValueSuccess(0)); + final tester = Stub.nullary>() + ..stub = () => Future.value(Result.success(0)); setUp(() { tester.reset(); @@ -154,7 +154,7 @@ void main() { }); }); group('Failure', () { - final tester = Stub.nullary>() + final tester = Stub.nullary>() ..stub = () => Future.value(Failure()); setUp(() { From df36b24308d036f4b2d107f71f5f80c1e97ccc8b Mon Sep 17 00:00:00 2001 From: Francesco Iapicca Date: Thu, 18 Apr 2024 12:03:17 +0300 Subject: [PATCH 3/7] [yak_runner] update test for yak_result_v3 --- .../lib/src/extension/iterable_run.dart | 4 +- .../yak_runner/lib/src/extension/run.dart | 2 - .../test/extensions/let_run_test.dart | 124 +++++++++++++++--- .../test/extensions/then_run_test.dart | 123 ++++++++++------- .../runner/value/run_nullary_async_test.dart | 19 ++- .../test/runner/value/run_nullary_test.dart | 8 +- .../runner/value/run_unary_async_test.dart | 8 +- .../test/runner/value/run_unary_test.dart | 8 +- .../runner/void/run_nullary_async_test.dart | 10 +- .../test/runner/void/run_nullary_test.dart | 10 +- .../runner/void/run_unary_async_test.dart | 10 +- .../test/runner/void/run_unary_test.dart | 10 +- 12 files changed, 235 insertions(+), 101 deletions(-) diff --git a/packages/yak_runner/lib/src/extension/iterable_run.dart b/packages/yak_runner/lib/src/extension/iterable_run.dart index 9b14e2d1..80c601fb 100644 --- a/packages/yak_runner/lib/src/extension/iterable_run.dart +++ b/packages/yak_runner/lib/src/extension/iterable_run.dart @@ -22,7 +22,7 @@ extension IterableNullaryToResultNullaryX } } -extension IterableUnaryToResultUnaryX +extension IterableUnaryToResultUnaryX on Iterable> { /// returns Iterable> from Iterable> /// TODO REWORK ITERATOR https://github.com/yakforward-ou/yak_packages/issues/238 @@ -63,7 +63,7 @@ extension IterableNullaryToResultNullaryAsyncX } } -extension IterableUnaryToResultUnaryAsyncX +extension IterableUnaryToResultUnaryAsyncX on Iterable> { /// returns Iterable> from Iterable> /// TODO REWORK ITERATOR https://github.com/yakforward-ou/yak_packages/issues/238 diff --git a/packages/yak_runner/lib/src/extension/run.dart b/packages/yak_runner/lib/src/extension/run.dart index a33bd8ec..b602a0b7 100644 --- a/packages/yak_runner/lib/src/extension/run.dart +++ b/packages/yak_runner/lib/src/extension/run.dart @@ -52,8 +52,6 @@ extension ResultUnaryX on Unary { // ``` // */ ResultUnary get run => unaryRun(this); - - VoidResultUnary get runVoid => unaryRunVoid(this); } /// [ResultUnaryX] turns a [Unary function diff --git a/packages/yak_runner/test/extensions/let_run_test.dart b/packages/yak_runner/test/extensions/let_run_test.dart index 42cb067f..a03cccea 100644 --- a/packages/yak_runner/test/extensions/let_run_test.dart +++ b/packages/yak_runner/test/extensions/let_run_test.dart @@ -20,10 +20,17 @@ void main() { 'WHEN function does not throw ' 'THEN result is Success', () { function.stub = (value) => value + 1; + final result = tester().letRun(function.call); expect( - tester().letRun(function.call), - isA(), + result, + isA>(), + reason: 'should return a Success', + ); + + expect( + result.isSuccess, + isTrue, reason: 'should return a Success', ); @@ -39,13 +46,26 @@ void main() { 'WHEN function throws ' 'THEN result is Failure', () { function.stub = (_) => throw Exception(); + final result = tester().letRun(function.call); expect( - tester().letRun(function.call), + result.isFailure, + isTrue, + reason: 'should return a Failure', + ); + + expect( + result, isA(), reason: 'should return a Failure', ); + expect( + result, + isA(), + reason: 'should return a Failure', + ); + expect( function.count, equals(1), @@ -55,7 +75,8 @@ void main() { }); group('Failure', () { - final tester = Stub.nullary>()..stub = () => Failure(); + final tester = Stub.nullary>() + ..stub = () => Result.failure(); final function = Stub.unary(); setUp(() { @@ -82,18 +103,62 @@ void main() { ); }); + test( + 'GIVEN Result is Failure ' + 'WHEN function does not throw ' + 'THEN result is Result', () { + function.stub = (value) => value + 1; + + expect( + tester().letRun(function.call), + isA(), + reason: 'should return a Success', + ); + + expect( + function.count, + equals(0), + reason: 'function should be not be called', + ); + }); + + test( + 'GIVEN Result is Failure ' + 'WHEN function does not throw ' + 'THEN result is Result', () { + function.stub = (value) => value + 1; + + expect( + tester().letRun(function.call), + isA(), + reason: 'should return a Success', + ); + + expect( + function.count, + equals(0), + reason: 'function should be not be called', + ); + }); + test( 'GIVEN Result is Failure ' 'WHEN function throws ' 'THEN result is Failure', () { function.stub = (_) => throw Exception(); - + final result = tester().letRun(function.call); expect( - tester().letRun(function.call), + result, isA(), reason: 'should return a Failure', ); + expect( + result.isFailure, + isTrue, + reason: 'should return a Failure', + ); + expect( function.count, equals(0), @@ -119,10 +184,16 @@ void main() { 'WHEN function does not throw ' 'THEN result is Success', () { function.stub = (value) => value + 1; + final result = tester().letRunVoid(function.call); + expect( + result.isSuccess, + isTrue, + reason: 'should return a Success', + ); expect( - tester().letRunVoid(function.call), - isA(), + result, + isA(), reason: 'should return a Success', ); @@ -139,8 +210,15 @@ void main() { 'THEN result is Failure', () { function.stub = (_) => throw Exception(); + final result = tester().letRunVoid(function.call); + expect( + result.isFailure, + isTrue, + reason: 'should return a Failure', + ); + expect( - tester().letRunVoid(function.call), + result, isA(), reason: 'should return a Failure', ); @@ -161,7 +239,7 @@ void main() { group('thenRun', () { group('Success', () { - tester.stub = () => VoidSuccess(); + tester.stub = () => VoidResult.success(); setUp(() { tester.reset(); @@ -173,10 +251,16 @@ void main() { 'WHEN function does not throw ' 'THEN result is Success', () { function.stub = () => 0; + final result = tester().letRun(function.call); + expect( + result.isSuccess, + isTrue, + reason: 'should return a Success', + ); expect( - tester().letRun(function.call), - isA(), + result, + isA(), reason: 'should return a Success', ); @@ -210,7 +294,7 @@ void main() { group('thenRunVoid', () { group('Success', () { - tester.stub = () => VoidSuccess(); + tester.stub = () => const VoidResult.success(); setUp(() { tester.reset(); @@ -224,8 +308,8 @@ void main() { function.stub = () => 0; expect( - tester().letRunVoid(function.call), - isA(), + tester().letRunVoid(function.call).isSuccess, + isTrue, reason: 'should return a Success', ); @@ -241,13 +325,19 @@ void main() { 'WHEN function throws ' 'THEN result is Failure', () { function.stub = () => throw Exception(); - + final result = tester().letRunVoid(function.call); expect( - tester().letRunVoid(function.call), + result, isA(), reason: 'should return a Failure', ); + expect( + result.isFailure, + isTrue, + reason: 'should return a Failure', + ); + expect( function.count, equals(1), diff --git a/packages/yak_runner/test/extensions/then_run_test.dart b/packages/yak_runner/test/extensions/then_run_test.dart index 21013b02..bda55de9 100644 --- a/packages/yak_runner/test/extensions/then_run_test.dart +++ b/packages/yak_runner/test/extensions/then_run_test.dart @@ -11,7 +11,7 @@ void main() { group('thenRun', () { group('Success', () { final tester = Stub.nullary>() - ..stub = () => Future.value(Result.success(0)); + ..stub = () => Future.value(const Result.success(0)); setUp(() { tester.reset(); function.reset(); @@ -22,10 +22,11 @@ void main() { 'WHEN function does not throw ' 'THEN result is Success', () async { function.stub = (value) => value + 1; + final result = await tester().thenRun(function.call); - await expectLater( - await tester().thenRun(function.call), - isA(), + expect( + result.isSuccess, + isTrue, reason: 'should return a Success', ); @@ -42,8 +43,9 @@ void main() { 'THEN result is Failure', () async { function.stub = (_) => throw Exception(); - await expectLater( - await tester().thenRun(function.call), + final result = await tester().thenRun(function.call); + expect( + result, isA(), reason: 'should return a Failure', ); @@ -58,7 +60,7 @@ void main() { group('Failure', () { final tester = Stub.nullary>() - ..stub = () => Future.value(Failure()); + ..stub = () => Future.value(Result.failure()); setUp(() { tester.reset(); @@ -71,12 +73,18 @@ void main() { 'THEN result is Failure', () async { function.stub = (value) => value + 1; - await expectLater( - await tester().thenRun(function.call), + final result = await tester().thenRun(function.call); + expect( + result, isA(), reason: 'should return a Success', ); + expect( + result.isFailure, + isTrue, + reason: 'should return a Success', + ); expect( function.count, equals(0), @@ -90,8 +98,9 @@ void main() { 'THEN result is Failure', () async { function.stub = (_) => throw Exception(); - await expectLater( - await tester().thenRun(function.call), + final result = await tester().thenRun(function.call); + expect( + result, isA(), reason: 'should return a Failure', ); @@ -108,7 +117,7 @@ void main() { group('thenRunVoid', () { group('Success', () { final tester = Stub.nullary>() - ..stub = () => Future.value(Result.success(0)); + ..stub = () => Future.value(const Result.success(0)); setUp(() { tester.reset(); @@ -121,9 +130,11 @@ void main() { 'THEN result is Success', () async { function.stub = (value) => value + 1; - await expectLater( - await tester().thenRunVoid(function.call), - isA(), + final result = await tester().thenRunVoid(function.call); + + expect( + result.isSuccess, + isTrue, reason: 'should return a Success', ); @@ -140,8 +151,9 @@ void main() { 'THEN result is Failure', () async { function.stub = (_) => throw Exception(); - await expectLater( - await tester().thenRunVoid(function.call), + final result = await tester().thenRunVoid(function.call); + expect( + result, isA(), reason: 'should return a Failure', ); @@ -155,7 +167,7 @@ void main() { }); group('Failure', () { final tester = Stub.nullary>() - ..stub = () => Future.value(Failure()); + ..stub = () => Future.value(Result.failure()); setUp(() { tester.reset(); @@ -168,8 +180,9 @@ void main() { 'THEN result is Failure', () async { function.stub = (value) => value + 1; - await expectLater( - await tester().thenRunVoid(function.call), + final result = await tester().thenRunVoid(function.call); + expect( + result, isA(), reason: 'should return a Success', ); @@ -187,8 +200,9 @@ void main() { 'THEN result is Failure', () async { function.stub = (_) => throw Exception(); - await expectLater( - await tester().thenRunVoid(function.call), + final result = await tester().thenRunVoid(function.call); + expect( + result, isA(), reason: 'should return a Failure', ); @@ -207,7 +221,7 @@ void main() { group('thenRun', () { group('Success', () { final tester = Stub.nullary() - ..stub = () => Future.value(VoidSuccess()); + ..stub = () => Future.value(VoidResult.success()); final function = Stub.nullary(); @@ -222,9 +236,11 @@ void main() { 'THEN result is Success', () async { function.stub = () => 0; - await expectLater( - await tester().thenRun(function.call), - isA(), + final result = await tester().thenRun(function.call); + + expect( + result.isSuccess, + isTrue, reason: 'should return a Success', ); @@ -241,8 +257,9 @@ void main() { 'THEN result is Failure', () async { function.stub = () => throw Exception(); - await expectLater( - await tester().thenRun(function.call), + final result = await tester().thenRun(function.call); + expect( + result, isA(), reason: 'should return a Failure', ); @@ -257,7 +274,7 @@ void main() { group('Failure', () { final tester = Stub.nullary() - ..stub = () => Future.value(Failure()); + ..stub = () => Future.value(const VoidResult.failure()); final function = Stub.nullary(); setUp(() { @@ -271,12 +288,19 @@ void main() { 'THEN result is Failure', () async { function.stub = () => 0; - await expectLater( - await tester().thenRun(function.call), + final result = await tester().thenRun(function.call); + expect( + result, isA(), reason: 'should return a Success', ); + expect( + result.isFailure, + isTrue, + reason: 'should return a Success', + ); + expect( function.count, equals(0), @@ -290,12 +314,19 @@ void main() { 'THEN result is Failure', () async { function.stub = () => throw Exception(); - await expectLater( - await tester().thenRun(function.call), + final result = await tester().thenRun(function.call); + expect( + result, isA(), reason: 'should return a Failure', ); + expect( + result.isFailure, + isTrue, + reason: 'should return a Success', + ); + expect( function.count, equals(0), @@ -308,7 +339,7 @@ void main() { group('thenRunVoid', () { group('Success', () { final tester = Stub.nullary() - ..stub = () => Future.value(VoidSuccess()); + ..stub = () => Future.value(VoidResult.success()); final function = Stub.nullary(); @@ -322,10 +353,11 @@ void main() { 'WHEN function does not throw ' 'THEN result is Success', () async { function.stub = () => 0; + final result = await tester().thenRunVoid(function.call); - await expectLater( - await tester().thenRunVoid(function.call), - isA(), + expect( + result.isSuccess, + isTrue, reason: 'should return a Success', ); @@ -342,8 +374,9 @@ void main() { 'THEN result is Failure', () async { function.stub = () => throw Exception(); - await expectLater( - await tester().thenRunVoid(function.call), + final result = await tester().thenRunVoid(function.call); + expect( + result, isA(), reason: 'should return a Failure', ); @@ -357,7 +390,7 @@ void main() { }); group('Failure', () { final tester = Stub.nullary() - ..stub = () => Future.value(Failure()); + ..stub = () => Future.value(const VoidResult.failure()); final function = Stub.nullary(); @@ -372,8 +405,9 @@ void main() { 'THEN result is Failure', () async { function.stub = () => 0; - await expectLater( - await tester().thenRunVoid(function.call), + final result = await tester().thenRunVoid(function.call); + expect( + result, isA(), reason: 'should return a Success', ); @@ -391,8 +425,9 @@ void main() { 'THEN result is Failure', () async { function.stub = () => throw Exception(); - await expectLater( - await tester().thenRunVoid(function.call), + final result = await tester().thenRunVoid(function.call); + expect( + result, isA(), reason: 'should return a Failure', ); diff --git a/packages/yak_runner/test/runner/value/run_nullary_async_test.dart b/packages/yak_runner/test/runner/value/run_nullary_async_test.dart index 66474cf4..cc8c02b4 100644 --- a/packages/yak_runner/test/runner/value/run_nullary_async_test.dart +++ b/packages/yak_runner/test/runner/value/run_nullary_async_test.dart @@ -18,7 +18,13 @@ void main() { expect( result, - isA>(), + isA(), + reason: 'tester should not throw', + ); + + expect( + result.isSuccess, + isTrue, reason: 'tester should not throw', ); }); @@ -36,6 +42,12 @@ void main() { isA>(), reason: 'tester should throw', ); + + expect( + result.isFailure, + isTrue, + reason: 'tester should not throw', + ); }); test( @@ -52,6 +64,11 @@ void main() { isA>(), reason: 'tester should throw', ); + expect( + result.isFailure, + isTrue, + reason: 'tester should not throw', + ); }); }); } diff --git a/packages/yak_runner/test/runner/value/run_nullary_test.dart b/packages/yak_runner/test/runner/value/run_nullary_test.dart index c23c54c8..0caaf727 100644 --- a/packages/yak_runner/test/runner/value/run_nullary_test.dart +++ b/packages/yak_runner/test/runner/value/run_nullary_test.dart @@ -19,7 +19,13 @@ void main() { expect( result, - isA>(), + isA(), + reason: 'tester should not throw', + ); + + expect( + result.isSuccess, + isTrue, reason: 'tester should not throw', ); }); diff --git a/packages/yak_runner/test/runner/value/run_unary_async_test.dart b/packages/yak_runner/test/runner/value/run_unary_async_test.dart index 3d14c2b9..908abde3 100644 --- a/packages/yak_runner/test/runner/value/run_unary_async_test.dart +++ b/packages/yak_runner/test/runner/value/run_unary_async_test.dart @@ -19,7 +19,13 @@ void main() { expect( result, - isA>(), + isA(), + reason: 'tester should not throw', + ); + + expect( + result.isSuccess, + isTrue, reason: 'tester should not throw', ); }); diff --git a/packages/yak_runner/test/runner/value/run_unary_test.dart b/packages/yak_runner/test/runner/value/run_unary_test.dart index e5473fea..9c4d9c0b 100644 --- a/packages/yak_runner/test/runner/value/run_unary_test.dart +++ b/packages/yak_runner/test/runner/value/run_unary_test.dart @@ -19,7 +19,13 @@ void main() { expect( result, - isA>(), + isA(), + reason: 'tester should not throw', + ); + + expect( + result.isSuccess, + isTrue, reason: 'tester should not throw', ); }); diff --git a/packages/yak_runner/test/runner/void/run_nullary_async_test.dart b/packages/yak_runner/test/runner/void/run_nullary_async_test.dart index 6cd5c5ad..b2879e18 100644 --- a/packages/yak_runner/test/runner/void/run_nullary_async_test.dart +++ b/packages/yak_runner/test/runner/void/run_nullary_async_test.dart @@ -17,14 +17,8 @@ void main() { final result = await function(); expect( - result, - isA(), - reason: 'tester should not throw', - ); - - expect( - result, - isA(), + result.isSuccess, + isTrue, reason: 'tester should not throw', ); }); diff --git a/packages/yak_runner/test/runner/void/run_nullary_test.dart b/packages/yak_runner/test/runner/void/run_nullary_test.dart index 86526047..a9b662d6 100644 --- a/packages/yak_runner/test/runner/void/run_nullary_test.dart +++ b/packages/yak_runner/test/runner/void/run_nullary_test.dart @@ -19,14 +19,8 @@ void main() { final result = function(); expect( - result, - isA(), - reason: 'tester should not throw', - ); - - expect( - result, - isA(), + result.isSuccess, + isTrue, reason: 'tester should not throw', ); }); diff --git a/packages/yak_runner/test/runner/void/run_unary_async_test.dart b/packages/yak_runner/test/runner/void/run_unary_async_test.dart index b175f1dd..92f04fff 100644 --- a/packages/yak_runner/test/runner/void/run_unary_async_test.dart +++ b/packages/yak_runner/test/runner/void/run_unary_async_test.dart @@ -17,14 +17,8 @@ void main() { final result = await function(1); expect( - result, - isA(), - reason: 'tester should not throw', - ); - - expect( - result, - isA(), + result.isSuccess, + isTrue, reason: 'tester should not throw', ); }); diff --git a/packages/yak_runner/test/runner/void/run_unary_test.dart b/packages/yak_runner/test/runner/void/run_unary_test.dart index 1428c5ec..eb993818 100644 --- a/packages/yak_runner/test/runner/void/run_unary_test.dart +++ b/packages/yak_runner/test/runner/void/run_unary_test.dart @@ -18,14 +18,8 @@ void main() { final result = function(1); expect( - result, - isA(), - reason: 'tester should not throw', - ); - - expect( - result, - isA(), + result.isSuccess, + isTrue, reason: 'tester should not throw', ); }); From cd69066b659034f7067c4c24f37a6590d81ae8c6 Mon Sep 17 00:00:00 2001 From: Francesco Iapicca Date: Thu, 18 Apr 2024 12:07:13 +0300 Subject: [PATCH 4/7] update yak_runner and yak_result examples --- examples/yak_result/bin/yak_result_example.dart | 10 +++++----- examples/yak_runner/bin/yak_runner_example.dart | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/yak_result/bin/yak_result_example.dart b/examples/yak_result/bin/yak_result_example.dart index 5698313e..cde8b083 100644 --- a/examples/yak_result/bin/yak_result_example.dart +++ b/examples/yak_result/bin/yak_result_example.dart @@ -10,20 +10,20 @@ int meaningOfLife() { /// you can use `yak_runner` for this purpose /// [https://pub.dev/packages/yak_runner] -ValueResult safelyTry(T Function() function) { +Result safelyTry(T Function() function) { try { - return ValueSuccess(function()); + return Result.success(function()); } on Exception catch (e, s) { - return Failure(e, s); + return Result.failure(e, s); } on Error catch (e) { - return Failure.fromError(e); + return Result.failure(e, e.stackTrace ?? StackTrace.empty); } } void main() { final result = safelyTry(meaningOfLife); if (result.isSuccess) { - print('${result.success.value}'); + print('${result.asSuccess}'); return; } diff --git a/examples/yak_runner/bin/yak_runner_example.dart b/examples/yak_runner/bin/yak_runner_example.dart index ef78b6bb..f1c96a4b 100644 --- a/examples/yak_runner/bin/yak_runner_example.dart +++ b/examples/yak_runner/bin/yak_runner_example.dart @@ -13,6 +13,6 @@ void main() { final result = oneDividedBy.run(1); if (result.isSuccess) { - print(result.success.value); // print `1` + print(result.asSuccess); // print `1` } } From 36dcfd0f3db7f1ec559cca2d7120940db53a8234 Mon Sep 17 00:00:00 2001 From: Francesco Iapicca Date: Thu, 18 Apr 2024 12:23:32 +0300 Subject: [PATCH 5/7] [yak_test] update test for yak_result_v3 --- .../yak_test/lib/src/extension/yak_runner/async/nullary.dart | 4 ++-- .../yak_test/lib/src/extension/yak_runner/async/unary.dart | 4 ++-- .../yak_test/lib/src/extension/yak_runner/sync/nullary.dart | 4 ++-- .../yak_test/lib/src/extension/yak_runner/sync/unary.dart | 4 ++-- packages/yak_test/test/testers/equality_tester_test.dart | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/yak_test/lib/src/extension/yak_runner/async/nullary.dart b/packages/yak_test/lib/src/extension/yak_runner/async/nullary.dart index f54c872d..5342cb1f 100644 --- a/packages/yak_test/lib/src/extension/yak_runner/async/nullary.dart +++ b/packages/yak_test/lib/src/extension/yak_runner/async/nullary.dart @@ -10,7 +10,7 @@ typedef ResultNullaryAsyncTest = void Function({ }); /// an `extension` that generates a basic set of tests for `ResultNullaryAsync` -extension ResultNullaryAsyncTestX on ResultNullaryAsync { +extension ResultNullaryAsyncTestX on ResultNullaryAsync { /// run `test` providing a `description` and an `example` function void tester({ required String name, @@ -29,7 +29,7 @@ extension ResultNullaryAsyncTestX on ResultNullaryAsync { expectLater( tester(), - isA>(), + isA>(), reason: 'tester should not throw', ); }); diff --git a/packages/yak_test/lib/src/extension/yak_runner/async/unary.dart b/packages/yak_test/lib/src/extension/yak_runner/async/unary.dart index 9e2f96ba..e307a669 100644 --- a/packages/yak_test/lib/src/extension/yak_runner/async/unary.dart +++ b/packages/yak_test/lib/src/extension/yak_runner/async/unary.dart @@ -11,7 +11,7 @@ typedef ResultUnaryAsyncTest = void Function({ }); /// an `extension` that generates a basic set of tests for `ResultUnaryAsync` -extension ResultUnaryAsyncTestX on ResultUnaryAsync { +extension ResultUnaryAsyncTestX on ResultUnaryAsync { /// run `test` providing a `description` and an `example` function void tester({ required String name, @@ -31,7 +31,7 @@ extension ResultUnaryAsyncTestX on ResultUnaryAsync { expectLater( tester(seed()), - isA>(), + isA>(), reason: 'tester should not throw', ); }); diff --git a/packages/yak_test/lib/src/extension/yak_runner/sync/nullary.dart b/packages/yak_test/lib/src/extension/yak_runner/sync/nullary.dart index 24501d1c..3d7aa425 100644 --- a/packages/yak_test/lib/src/extension/yak_runner/sync/nullary.dart +++ b/packages/yak_test/lib/src/extension/yak_runner/sync/nullary.dart @@ -10,7 +10,7 @@ typedef ResultNullaryTest = void Function({ }); /// an `extension` that generates a basic set of tests for `ResultNullary` -extension ResultNullaryTestX on ResultNullary { +extension ResultNullaryTestX on ResultNullary { /// run `test` providing a `description` and an `example` function void tester({ required String name, @@ -31,7 +31,7 @@ extension ResultNullaryTestX on ResultNullary { expect( result, - isA>(), + isA>(), reason: 'tester should not throw', ); }); diff --git a/packages/yak_test/lib/src/extension/yak_runner/sync/unary.dart b/packages/yak_test/lib/src/extension/yak_runner/sync/unary.dart index 21a5306c..b38132e1 100644 --- a/packages/yak_test/lib/src/extension/yak_runner/sync/unary.dart +++ b/packages/yak_test/lib/src/extension/yak_runner/sync/unary.dart @@ -11,7 +11,7 @@ typedef ResultUnaryTest = void Function({ }); /// an `extension` that generates a basic set of tests for `ResultUnary` -extension ResultUnaryTestX on ResultUnary { +extension ResultUnaryTestX on ResultUnary { /// run `test` providing a `description` and an `example` function void tester({ required String name, @@ -33,7 +33,7 @@ extension ResultUnaryTestX on ResultUnary { expect( result, - isA>(), + isA>(), reason: 'tester should not throw', ); }); diff --git a/packages/yak_test/test/testers/equality_tester_test.dart b/packages/yak_test/test/testers/equality_tester_test.dart index 5b79740a..7ccedc34 100644 --- a/packages/yak_test/test/testers/equality_tester_test.dart +++ b/packages/yak_test/test/testers/equality_tester_test.dart @@ -22,8 +22,8 @@ void main() { }); group('equalityTest Success', () { - final tester = Success.value(0); - final other = Success.value(1); + final tester = Result.success(0); + final other = Result.success(1); equalityTest( () => tester, () => other, From a52e8116f7f0fe92e8a8debf6bed9ff8e8a5cf5f Mon Sep 17 00:00:00 2001 From: Francesco Iapicca Date: Thu, 18 Apr 2024 12:28:38 +0300 Subject: [PATCH 6/7] update pubspec and changelog --- examples/yak_result/pubspec.yaml | 2 +- examples/yak_runner/pubspec.yaml | 2 +- packages/yak_flutter/CHANGELOG.md | 3 +++ packages/yak_flutter/pubspec.yaml | 4 ++-- packages/yak_result/CHANGELOG.md | 4 ++++ packages/yak_result/pubspec.yaml | 2 +- packages/yak_runner/CHANGELOG.md | 3 +++ packages/yak_runner/pubspec.yaml | 4 ++-- packages/yak_test/CHANGELOG.md | 3 +++ packages/yak_test/pubspec.yaml | 4 ++-- 10 files changed, 22 insertions(+), 9 deletions(-) diff --git a/examples/yak_result/pubspec.yaml b/examples/yak_result/pubspec.yaml index 300cadbe..a6f3b387 100644 --- a/examples/yak_result/pubspec.yaml +++ b/examples/yak_result/pubspec.yaml @@ -7,7 +7,7 @@ environment: sdk: '>=3.3.3 <4.0.0' dependencies: - yak_result: ^2.1.1 + yak_result: ^3.0.0 dev_dependencies: lints: ^3.0.0 diff --git a/examples/yak_runner/pubspec.yaml b/examples/yak_runner/pubspec.yaml index fbae4124..773489f0 100644 --- a/examples/yak_runner/pubspec.yaml +++ b/examples/yak_runner/pubspec.yaml @@ -7,7 +7,7 @@ environment: sdk: '>=3.3.3 <4.0.0' dependencies: - yak_runner: ^2.1.1 + yak_result: ^3.0.0 dev_dependencies: lints: ^3.0.0 diff --git a/packages/yak_flutter/CHANGELOG.md b/packages/yak_flutter/CHANGELOG.md index 28909d55..e6427b17 100644 --- a/packages/yak_flutter/CHANGELOG.md +++ b/packages/yak_flutter/CHANGELOG.md @@ -1,3 +1,6 @@ +### 3.0.0 +- rework due to yak_result v3 + ### 2.1.1 - update dependency diff --git a/packages/yak_flutter/pubspec.yaml b/packages/yak_flutter/pubspec.yaml index 85111b0d..73a2463f 100644 --- a/packages/yak_flutter/pubspec.yaml +++ b/packages/yak_flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: yak_flutter description: A collection of tools and extensions for Flutter. -version: 2.1.1 +version: 3.0.0 homepage: https://github.com/yakforward-ou/yak_packages environment: @@ -10,7 +10,7 @@ dependencies: flutter: sdk: flutter yak_tween: ^2.0.2 - yak_runner: ^2.1.1 + yak_runner: ^3.0.0 yak_utils: ^2.1.1 dev_dependencies: diff --git a/packages/yak_result/CHANGELOG.md b/packages/yak_result/CHANGELOG.md index 263192b2..f6ed0791 100644 --- a/packages/yak_result/CHANGELOG.md +++ b/packages/yak_result/CHANGELOG.md @@ -1,3 +1,7 @@ +### 3.0.0 +- rework using "extension type" +- BREAKING CHANGES + ### 2.1.1 - update dependency diff --git a/packages/yak_result/pubspec.yaml b/packages/yak_result/pubspec.yaml index 0f39d52e..d9f5b315 100644 --- a/packages/yak_result/pubspec.yaml +++ b/packages/yak_result/pubspec.yaml @@ -1,6 +1,6 @@ name: yak_result description: a lightweight dart micro-package to help you handle functions results -version: 2.1.1 +version: 3.0.0 homepage: https://github.com/yakforward-ou/yak_packages environment: diff --git a/packages/yak_runner/CHANGELOG.md b/packages/yak_runner/CHANGELOG.md index 477bb454..ed727c7d 100644 --- a/packages/yak_runner/CHANGELOG.md +++ b/packages/yak_runner/CHANGELOG.md @@ -1,3 +1,6 @@ +### 3.0.0 +- rework due to yak_result v3 + ### 2.1.1 - update dependency diff --git a/packages/yak_runner/pubspec.yaml b/packages/yak_runner/pubspec.yaml index 15f741b9..38c4f7bd 100644 --- a/packages/yak_runner/pubspec.yaml +++ b/packages/yak_runner/pubspec.yaml @@ -1,6 +1,6 @@ name: yak_runner description: A Dart package that makes running functions safer and easier to test -version: 2.1.1 +version: 3.0.0 homepage: https://github.com/yakforward-ou/yak_packages environment: @@ -8,7 +8,7 @@ environment: dependencies: meta: ^1.11.0 - yak_result: ^2.1.1 + yak_result: ^3.0.0 yak_utils: ^2.1.1 dev_dependencies: diff --git a/packages/yak_test/CHANGELOG.md b/packages/yak_test/CHANGELOG.md index d15ba2d3..38ea265e 100644 --- a/packages/yak_test/CHANGELOG.md +++ b/packages/yak_test/CHANGELOG.md @@ -1,3 +1,6 @@ +### 3.0.0 +- rework due to yak_result v3 + ### 2.1.1 - update dependency diff --git a/packages/yak_test/pubspec.yaml b/packages/yak_test/pubspec.yaml index 7b438b89..69a284a4 100644 --- a/packages/yak_test/pubspec.yaml +++ b/packages/yak_test/pubspec.yaml @@ -1,6 +1,6 @@ name: yak_test description: a Dart package that helps to testing apps made with `yak_packages` -version: 2.1.1 +version: 3.0.0 homepage: https://github.com/yakforward-ou/yak_packages environment: @@ -8,7 +8,7 @@ environment: dependencies: meta: ^1.11.0 - yak_runner: ^2.1.1 + yak_runner: ^3.0.0 stub: ^2.1.1 test: ^1.24.9 From d70ecc07c8feccc3c1120aa4c911c2afe8c1222c Mon Sep 17 00:00:00 2001 From: Francesco Iapicca Date: Thu, 18 Apr 2024 12:44:23 +0300 Subject: [PATCH 7/7] fix example pubspec --- examples/yak_runner/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/yak_runner/pubspec.yaml b/examples/yak_runner/pubspec.yaml index 773489f0..bdaf8214 100644 --- a/examples/yak_runner/pubspec.yaml +++ b/examples/yak_runner/pubspec.yaml @@ -7,7 +7,7 @@ environment: sdk: '>=3.3.3 <4.0.0' dependencies: - yak_result: ^3.0.0 + yak_runner: ^3.0.0 dev_dependencies: lints: ^3.0.0