From c947e80352b8c3fbc9faf6196e9d2d50a54e638c Mon Sep 17 00:00:00 2001 From: mcmah309 Date: Mon, 29 Jan 2024 08:02:58 +0000 Subject: [PATCH] test: Add boundary test --- test/result/future_result_test.dart | 37 ++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/test/result/future_result_test.dart b/test/result/future_result_test.dart index 9ccd7f8..8c04cb6 100644 --- a/test/result/future_result_test.dart +++ b/test/result/future_result_test.dart @@ -5,28 +5,24 @@ import 'package:test/test.dart'; void main() { group('andThen', () { test('async ', () async { - final result = - await Future.value(const Ok(1)).andThen((ok) async => Ok(ok * 2)); + final result = await Future.value(const Ok(1)).andThen((ok) async => Ok(ok * 2)); expect(result.unwrapOrNull(), 2); }); test('sink', () async { - final result = - await Future.value(const Ok(1)).andThen((ok) => Ok(ok * 2)); + final result = await Future.value(const Ok(1)).andThen((ok) => Ok(ok * 2)); expect(result.unwrapOrNull(), 2); }); }); group('andThenError', () { test('async ', () async { - final result = await Future.value(Err(2)) - .andThenErr((error) async => Err(error * 2)); + final result = await Future.value(Err(2)).andThenErr((error) async => Err(error * 2)); expect(result.unwrapErrOrNull(), 4); }); test('sink', () async { - final result = - await Future.value(Err(2)).andThenErr((error) => Err(error * 2)); + final result = await Future.value(Err(2)).andThenErr((error) => Err(error * 2)); expect(result.unwrapErrOrNull(), 4); }); }); @@ -265,5 +261,30 @@ void main() { }); expect(await testDoNotation().unwrapErr(), ""); }); + + test("Async-Sync does not cross boundaries", () async { + FutureResult testAsyncSync() => Result.async(($) { + final Result x = Result(($2) { + return Ok(Err("1")[$]); + }); + expect(x.unwrapErr(), "1"); + return Future.value(Ok(1)); + }); + expect(await testAsyncSync().unwrap(), 1); + + late Result inner; + Result testSyncAsync() => Result(($) { + final FutureResult _ = Result.async(($2) { + return Future.value(Ok(Err("1")[$])); + }).then((value) { + inner = value; + return value; + }); + return Ok(1); + }); + expect(testSyncAsync().unwrap(), 1); + await Future.delayed(Duration(milliseconds: 200)); + expect(inner.unwrapErr(), "1"); + }); }); }