From ee4a488aaed135dd1eb752d9eb46306e612089c8 Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Fri, 8 Dec 2023 15:07:18 +0200 Subject: [PATCH] #2415. Change expectations for Stream.asyncMap() according to the current behavior --- .../Stream/Stream.fromFutures_all_t03.dart | 26 ---------- .../Stream/Stream.fromIterable_all_t03.dart | 18 ------- .../async/Stream/Stream.periodic_all_t03.dart | 24 ---------- LibTest/async/Stream/allTests_A01.lib.dart | 2 + LibTest/async/Stream/allTests_A03.lib.dart | 23 --------- .../asBroadcastStream_A05_t03.test.dart | 24 ---------- .../async/Stream/asyncMap_A04_t01.test.dart | 18 +++---- ...ntroller.broadcast_Stream_all_A01_t03.dart | 41 ---------------- ...ntroller.broadcast_Stream_all_A02_t03.dart | 48 ------------------- .../StreamController/stream_all_A01_t03.dart | 29 ----------- .../StreamController/stream_all_A02_t03.dart | 40 ---------------- 11 files changed, 11 insertions(+), 282 deletions(-) delete mode 100644 LibTest/async/Stream/Stream.fromFutures_all_t03.dart delete mode 100644 LibTest/async/Stream/Stream.fromIterable_all_t03.dart delete mode 100644 LibTest/async/Stream/Stream.periodic_all_t03.dart delete mode 100644 LibTest/async/Stream/allTests_A03.lib.dart delete mode 100644 LibTest/async/Stream/asBroadcastStream_A05_t03.test.dart delete mode 100644 LibTest/async/StreamController/StreamController.broadcast_Stream_all_A01_t03.dart delete mode 100644 LibTest/async/StreamController/StreamController.broadcast_Stream_all_A02_t03.dart delete mode 100644 LibTest/async/StreamController/stream_all_A01_t03.dart delete mode 100644 LibTest/async/StreamController/stream_all_A02_t03.dart diff --git a/LibTest/async/Stream/Stream.fromFutures_all_t03.dart b/LibTest/async/Stream/Stream.fromFutures_all_t03.dart deleted file mode 100644 index bd8e83ab0c..0000000000 --- a/LibTest/async/Stream/Stream.fromFutures_all_t03.dart +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// @assertion Stream.fromFutures(Iterable> futures) -/// Create a stream from a group of futures. -/// The stream reports the results of the futures on the stream in the order -/// in which the futures complete. -/// If some futures have completed before calling Stream.fromFutures, -/// their result will be output on the created stream in some unspecified order. -/// When all futures have completed, the stream is closed. -/// If no future is passed, the stream closes as soon as possible. -/// @description Checks Stream interface methods -/// @Issue 29615 -/// @author a.semenov@unipro.ru - -import "dart:async"; -import "allTests_A03.lib.dart"; - -Stream create(Iterable data) { - return new Stream.fromFutures(data.map((T x) => new Future.value(x))); -} - -main() { - test(create); -} diff --git a/LibTest/async/Stream/Stream.fromIterable_all_t03.dart b/LibTest/async/Stream/Stream.fromIterable_all_t03.dart deleted file mode 100644 index 6cec9cdde8..0000000000 --- a/LibTest/async/Stream/Stream.fromIterable_all_t03.dart +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// @assertion Stream.fromIterable(Iterable data) -/// Creates a single-subscription stream that gets its data from data. -/// The iterable is iterated when the stream receives a listener, and stops -/// iterating if the listener cancels the subscription. -/// @description Checks Stream interface methods -/// @Issue 29615 -/// @author a.semenov@unipro.ru - -import "dart:async"; -import "allTests_A03.lib.dart"; - -main() { - test((Iterable data) => new Stream.fromIterable(data)); -} diff --git a/LibTest/async/Stream/Stream.periodic_all_t03.dart b/LibTest/async/Stream/Stream.periodic_all_t03.dart deleted file mode 100644 index bca5d01577..0000000000 --- a/LibTest/async/Stream/Stream.periodic_all_t03.dart +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// @assertion Stream.periodic(Duration period, -/// [T computation(int computationCount)]) -/// Creates a stream that repeatedly emits events at period intervals. -/// If computation is omitted the event values will all be null. -/// @description Checks Stream interface methods -/// @Issue 29615 -/// @author a.semenov@unipro.ru - -import "dart:async"; -import "allTests_A03.lib.dart" as all; - -Stream create(Iterable data) { - return new Stream.periodic( - new Duration(milliseconds: 10), (int i) => data.elementAt(i)) - .take(data.length); -} - -main() { - all.test(create); -} diff --git a/LibTest/async/Stream/allTests_A01.lib.dart b/LibTest/async/Stream/allTests_A01.lib.dart index 45714fc3c7..2fe5e20601 100644 --- a/LibTest/async/Stream/allTests_A01.lib.dart +++ b/LibTest/async/Stream/allTests_A01.lib.dart @@ -35,6 +35,7 @@ import "asyncMap_A01_t04.test.dart" as asyncMap_A01_t04; import "asyncMap_A02_t01.test.dart" as asyncMap_A02_t01; import "asyncMap_A03_t02.test.dart" as asyncMap_A03_t02; import "asyncMap_A03_t03.test.dart" as asyncMap_A03_t03; +import "asyncMap_A04_t01.test.dart" as asyncMap_A04_t01; import "contains_A01_t01.test.dart" as contains_A01_t01; import "contains_A02_t01.test.dart" as contains_A02_t01; @@ -186,6 +187,7 @@ void test(CreateStreamFunction create) { asyncMap_A02_t01.test(create); asyncMap_A03_t02.test(create); asyncMap_A03_t03.test(create); + asyncMap_A04_t01.test(create); contains_A01_t01.test(create); contains_A02_t01.test(create); diff --git a/LibTest/async/Stream/allTests_A03.lib.dart b/LibTest/async/Stream/allTests_A03.lib.dart deleted file mode 100644 index 7f23e01cb6..0000000000 --- a/LibTest/async/Stream/allTests_A03.lib.dart +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// @assertion class Stream -/// @description Aggregates currently failing tests for Stream interface -/// @author a.semenov@unipro.ru - -library allTests_A03; - -import "../../../Utils/expect.dart"; - -import "asBroadcastStream_A05_t03.test.dart" as asBroadcastStream_A05_t03; - -import "asyncMap_A04_t01.test.dart" as asyncMap_A04_t01; - -void test(CreateStreamFunction create) { - asyncStart(); - asBroadcastStream_A05_t03.test(create); - // failures TODO move in place when fixed - asyncMap_A04_t01.test(create); // issue #29615 - asyncEnd(); -} diff --git a/LibTest/async/Stream/asBroadcastStream_A05_t03.test.dart b/LibTest/async/Stream/asBroadcastStream_A05_t03.test.dart deleted file mode 100644 index 32d4619c20..0000000000 --- a/LibTest/async/Stream/asBroadcastStream_A05_t03.test.dart +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// @assertion Stream asBroadcastStream ( -/// {void onListen(StreamSubscription subscription), -/// void onCancel(StreamSubscription subscription)}) -/// Returns a multi-subscription stream that produces the same events as this. -/// -/// @description Checks Stream interface methods -/// @author a.semenov@unipro.ru - -library asBroadcastStream_A05_t03; - -import "dart:async"; -import "../../../Utils/expect.dart"; -import "allTests_A03.lib.dart" as StreamTests; - -void test(CreateStreamFunction create) { - Stream s = create([]); - if (!s.isBroadcast) { - StreamTests.test((Iterable data) => create(data).asBroadcastStream()); - } -} diff --git a/LibTest/async/Stream/asyncMap_A04_t01.test.dart b/LibTest/async/Stream/asyncMap_A04_t01.test.dart index 0032ea3246..d4fba80495 100644 --- a/LibTest/async/Stream/asyncMap_A04_t01.test.dart +++ b/LibTest/async/Stream/asyncMap_A04_t01.test.dart @@ -2,16 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -/// @assertion Stream asyncMap(dynamic convert(T event)) -/// This acts like [map], ... -/// -/// The convert function is called once per data event per listener. -/// If a broadcast stream is listened to more than once, each subscription -/// will individually call convert on each data event. +/// @assertion Stream asyncMap(FutureOr convert(T event)) +/// ... +/// This acts like [map], in that [convert] function is called once per +/// data event, but here [convert] may be asynchronous and return a [Future]. +/// If that happens, this stream waits for that future to complete before +/// continuing with further events. /// /// @description Checks that convert function is called once per data event /// per listener. -/// /// @issue #29615 /// @author a.semenov@unipro.ru @@ -39,18 +38,19 @@ Future? check(Stream stream, List expected) { return event; } - asyncStart(); Stream converted = stream.asyncMap(convert); Future.wait( [subscribe(converted), subscribe(converted), subscribe(converted)]) .then((List> result) { result.forEach((received) => Expect.listEquals(expected, received)); - expected.forEach((event) => Expect.equals(3, convertLog[event])); + expected.forEach((event) => Expect.equals(1, convertLog[event])); asyncEnd(); }); + return null; } void test(CreateStreamFunction create) { + asyncStart(3); check(create([]).asBroadcastStream(), []); check(create([1, 2, 3, 4, 5]).asBroadcastStream(), [1, 2, 3, 4, 5]); check(create(['a', 'b', 'c']).asBroadcastStream(), ['a', 'b', 'c']); diff --git a/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A01_t03.dart b/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A01_t03.dart deleted file mode 100644 index c74f5e25db..0000000000 --- a/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A01_t03.dart +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// @assertion StreamController.broadcast({void onListen(), void onCancel(), -/// bool sync: false}) -/// A controller where stream can be listened to more than once. -/// -/// The Stream returned by stream is a broadcast stream. It can be listened to -/// more than once. -/// -/// The controller distributes any events to all currently subscribed listeners -/// at the time when add, addError or close is called. -/// -/// @description Checks that property stream implements Stream interface -/// @Issue 29615 -/// @author a.semenov@unipro.ru - -import "dart:async"; -import "../Stream/allTests_A03.lib.dart"; - -Stream create(Iterable data, {bool isError(T element)?}) { - StreamController? sc; - sc = new StreamController.broadcast(onListen: () { - for (T e in data) { - if (isError != null && isError(e)) { - sc?.addError(e as Object); - } else { - sc?.add(e); - } - } - new Future(() => sc?.close()); - }, onCancel: () { - sc?.close(); - }); - return sc.stream; -} - -main() { - test(create); -} diff --git a/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A02_t03.dart b/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A02_t03.dart deleted file mode 100644 index 39f615f034..0000000000 --- a/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A02_t03.dart +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// @assertion StreamController.broadcast({void onListen(), void onCancel(), -/// bool sync: false}) -/// A controller where stream can be listened to more than once. -/// -/// The Stream returned by stream is a broadcast stream. It can be listened to -/// more than once. -/// -/// The controller distributes any events to all currently subscribed listeners -/// at the time when add, addError or close is called. -/// -/// @description Checks that property stream implements Stream interface -/// @Issue 29615 -/// @author a.semenov@unipro.ru - -import "dart:async"; -import "../Stream/allTests_A03.lib.dart"; - -Stream create(Iterable data, {bool isError(T element)?}) { - StreamController? sc; - sc = new StreamController.broadcast( - sync: true, - onListen: () { - new Future(() { - for (T e in data) { - if (sc!.isClosed) { - break; - } - if (isError != null && isError(e)) { - sc.addError(e as Object); - } else { - sc.add(e); - } - } - }).then((_) => sc?.close()); - }, - onCancel: () { - sc?.close(); - }); - return sc.stream; -} - -main() { - test(create); -} diff --git a/LibTest/async/StreamController/stream_all_A01_t03.dart b/LibTest/async/StreamController/stream_all_A01_t03.dart deleted file mode 100644 index 55aafaf776..0000000000 --- a/LibTest/async/StreamController/stream_all_A01_t03.dart +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// @assertion Stream stream -/// The stream that this controller is controlling. -/// @description Checks Stream interface implementation -/// @Issue 29615 -/// @author a.semenov@unipro.ru - -import "dart:async"; -import "../Stream/allTests_A03.lib.dart"; - -Stream create(Iterable data, {bool isError(T element)?}) { - StreamController sc = new StreamController(); - for (T e in data) { - if (isError != null && isError(e)) { - sc.addError(e as Object); - } else { - sc.add(e); - } - } - new Future(() => sc.close()); // close stream controller later - return sc.stream; -} - -main() { - test(create); -} diff --git a/LibTest/async/StreamController/stream_all_A02_t03.dart b/LibTest/async/StreamController/stream_all_A02_t03.dart deleted file mode 100644 index 21b9219a6e..0000000000 --- a/LibTest/async/StreamController/stream_all_A02_t03.dart +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// @assertion Stream stream -/// The stream that this controller is controlling. -/// @description Checks that property stream implements Stream interface -/// @Issue 29615 -/// @author a.semenov@unipro.ru - -import "dart:async"; -import "../Stream/allTests_A03.lib.dart"; - -Stream create(Iterable data, {bool isError(T element)?}) { - StreamController? sc; - sc = new StreamController( - sync: true, - onListen: () { - new Future(() { - for (T e in data) { - if (sc!.isClosed) { - break; - } - if (isError != null && isError(e)) { - sc.addError(e as Object); - } else { - sc.add(e); - } - } - }).then((_) => sc?.close()); - }, - onCancel: () { - sc?.close(); - }); - return sc.stream; -} - -main() { - test(create); -}