dart-sdk/tests/lib/async/stream_join_test.dart
Liam Appelbe 2e75c3d7ca [nnbd] Fix remaining async tests in strong mode.
stream_controller_async_test and stream_join_test are built on
async_minitest, so most of the issues were fixed by migrating it to use
Never as the bottom type rather than Null.

Change-Id: I6f43e818a7a8d6793844166c8f9fc07b3b0f7a16
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143562
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
2020-04-16 21:15:45 +00:00

75 lines
1.8 KiB
Dart

// Copyright (c) 2013, 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.
// Test the basic StreamController and StreamController.singleSubscription.
library stream_join_test;
import 'dart:async';
import 'package:expect/expect.dart';
import 'package:async_helper/async_minitest.dart';
import 'event_helper.dart';
main() {
test("join-empty", () {
StreamController c = new StreamController();
c.stream.join("X").then(expectAsync((String s) => expect(s, equals(""))));
c.close();
});
test("join-single", () {
StreamController c = new StreamController();
c.stream
.join("X")
.then(expectAsync((String s) => expect(s, equals("foo"))));
c.add("foo");
c.close();
});
test("join-three", () {
StreamController c = new StreamController();
c.stream
.join("X")
.then(expectAsync((String s) => expect(s, equals("fooXbarXbaz"))));
c.add("foo");
c.add("bar");
c.add("baz");
c.close();
});
test("join-three-non-string", () {
StreamController c = new StreamController();
c.stream
.join("X")
.then(expectAsync((String s) => expect(s, equals("fooXbarXbaz"))));
c.add(new Foo("foo"));
c.add(new Foo("bar"));
c.add(new Foo("baz"));
c.close();
});
test("join-error", () {
StreamController c = new StreamController();
Future<String?>.value(c.stream.join("X"))
.catchError(expectAsync((String s) => expect(s, equals("BAD!"))));
c.add(new Foo("foo"));
c.add(new Foo("bar"));
c.add(new Bad());
c.add(new Foo("baz"));
c.close();
});
}
class Foo {
String value;
Foo(this.value);
String toString() => value;
}
class Bad {
Bad();
String toString() => throw "BAD!";
}