This repository has been archived by the owner on Sep 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
single_subscription_to_broadcast_test.dart
69 lines (53 loc) 路 2.19 KB
/
single_subscription_to_broadcast_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import 'package:distinct_value_connectable_stream/distinct_value_connectable_stream.dart';
import 'package:test/test.dart';
void main() {
final elements = [0, 1, 1, 2, 3, 4, 4];
final expected = <Object>[1, 2, 3, 4, emitsDone];
group('DistinctValueStream to broadcast DistinctValueStream', () {
group('using asBroadcastDistinctValueStream', () {
Future<void> _test(DistinctValueStream<int> stream) async {
expect(stream.value, 0);
expect(stream.isBroadcast, true);
expect(stream, emitsInOrder(expected));
await expectLater(stream, emitsInOrder(expected));
expect(stream, emitsDone);
}
test('with a Single-Subscription Stream', () async {
final source = Stream.fromIterable(elements).distinctValue(0);
final stream = source.asBroadcastDistinctValueStream();
expect(identical(stream.equals, source.equals), true);
expect(stream.errorOrNull, null);
expect(stream.stackTrace, null);
await _test(stream);
});
test('with a Broadcast Stream', () async {
final source = Stream.fromIterable(elements).shareValueDistinct(0);
final stream = source.asBroadcastDistinctValueStream();
expect(identical(stream, source), true);
await _test(stream);
});
});
group('using asDistinctValueConnectableStream', () {
Future<void> _test(DistinctValueConnectableStream<int> stream) async {
expect(stream.value, 0);
expect(stream.isBroadcast, true);
stream.connect();
expect(stream, emitsInOrder(expected));
await expectLater(stream, emitsInOrder(expected));
expect(stream, emitsDone);
}
test('with a Single-Subscription Stream', () async {
final stream = Stream.fromIterable(elements)
.distinctValue(0)
.asDistinctValueConnectableStream();
await _test(stream);
});
test('with a Broadcast Stream', () async {
final source = Stream.fromIterable(elements).publishValueDistinct(0);
final stream = source.asDistinctValueConnectableStream();
expect(identical(stream, source), true);
await _test(stream);
});
});
});
}