Chromium Code Reviews| Index: pkg/scheduled_test/lib/src/utils.dart |
| diff --git a/pkg/scheduled_test/lib/src/utils.dart b/pkg/scheduled_test/lib/src/utils.dart |
| index 9cba0447190a1b440d4f9af8dd721abad11f1229..cdecefb3ec8771b2f5c0a4bf131a4b638131c7d3 100644 |
| --- a/pkg/scheduled_test/lib/src/utils.dart |
| +++ b/pkg/scheduled_test/lib/src/utils.dart |
| @@ -25,6 +25,52 @@ class Pair<E, F> { |
| int get hashCode => first.hashCode ^ last.hashCode; |
| } |
| +/// A class that represents one and only one of two types of values. |
| +class Either<E, F> { |
| + /// Whether this is a value of type `E`. |
| + final bool isFirst; |
| + |
| + /// Whether this is a value of type `F`. |
| + bool get isSecond => !isFirst; |
| + |
| + /// The value, either of type `E` or `F`. |
| + final _value; |
| + |
| + /// The value of type `E`. |
| + /// |
| + /// It's an error to access this is this is of type `F`. |
|
Bob Nystrom
2013/12/21 00:11:34
"this is this" -> "this if the value"
nweiz
2014/01/07 03:16:39
N/A
|
| + E get first { |
| + assert(isFirst); |
| + return _value; |
| + } |
| + |
| + /// The value of type `F`. |
| + /// |
| + /// It's an error to access this is this is of type `E`. |
|
Bob Nystrom
2013/12/21 00:11:34
Ditto.
nweiz
2014/01/07 03:16:39
N/A
|
| + F get second { |
| + assert(isSecond); |
| + return _value; |
| + } |
| + |
| + /// Creates an [Either] with type `E`. |
| + Either.withFirst(this._value) |
|
Bob Nystrom
2013/12/21 00:11:34
Maybe just Either.first()?
nweiz
2014/01/07 03:16:39
N/A
|
| + : isFirst = true; |
| + |
| + /// Creates an [Either] with type `F`. |
| + Either.withSecond(this._value) |
| + : isFirst = false; |
| + |
| + /// Runs [whenFirst] or [whenSecond] depending on the type of [this]. |
| + /// |
| + /// Returns the result of whichvever function was run. |
| + match(whenFirst(E value), whenSecond(F value)) { |
| + if (isFirst) return whenFirst(first); |
| + return whenSecond(second); |
| + } |
| + |
| + String toString() => "$_value (${isFirst? 'first' : 'second'})"; |
| +} |
| + |
| /// Configures [future] so that its result (success or exception) is passed on |
| /// to [completer]. |
| void chainToCompleter(Future future, Completer completer) { |
| @@ -231,12 +277,5 @@ bool fullMatch(String string, Pattern pattern) { |
| /// Returns a string representation of [trace] that has the core and test frames |
| /// folded together. |
| String terseTraceString(StackTrace trace) { |
| - return new Chain(new Chain.forTrace(trace).traces.map((trace) { |
| - return trace.foldFrames((frame) { |
| - return frame.package == 'scheduled_test' || |
| - frame.package == 'unittest' || |
| - frame.package == 'stack_trace' || |
| - frame.isCore; |
| - }); |
| - })).terse.toString().trim(); |
| + return new Chain.forTrace(trace).terse.toString().trim(); |
| } |