Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions LibTest/async/Stream/Stream.fromIterable_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,29 @@
// 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<T> data)
/// Creates a single-subscription stream that gets its data from data.
/// @description Checks that created stream is single-subscription.
/// @assertion Stream<T>.fromIterable( Iterable<T> elements )
///
/// Creates a stream that gets its data from `elements`.
///
/// The iterable is iterated when the stream receives a listener, and stops
/// iterating if the listener cancels the subscription, or if the
/// [Iterator.moveNext] method returns false or throws. Iteration is suspended
/// while the stream subscription is paused.
///
/// If calling [Iterator.moveNext] on `elements.iterator` throws, the stream
/// emits that error and then it closes. If reading [Iterator.current] on
/// `elements.iterator` throws, the stream emits that error, but keeps iterating
///
/// Can be listened to more than once. Each listener iterates elements
/// independently.
///
/// @description Checks that created stream is not a broadcast stream.
/// @author kaigorodov

import "dart:async";
import "../../../Utils/expect.dart";

main() {
Stream s = new Stream.fromIterable([1, 2, 3]);

Expect.isFalse(s.isBroadcast);
}
20 changes: 17 additions & 3 deletions LibTest/async/Stream/Stream.fromIterable_A01_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@
// 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<T> data)
/// Creates a single-subscription stream that gets its data from data.
/// @description Checks that created stream returns all the data from Iterable.
/// @assertion Stream<T>.fromIterable( Iterable<T> elements )
///
/// Creates a stream that gets its data from `elements`.
///
/// The iterable is iterated when the stream receives a listener, and stops
/// iterating if the listener cancels the subscription, or if the
/// [Iterator.moveNext] method returns false or throws. Iteration is suspended
/// while the stream subscription is paused.
///
/// If calling [Iterator.moveNext] on `elements.iterator` throws, the stream
/// emits that error and then it closes. If reading [Iterator.current] on
/// `elements.iterator` throws, the stream emits that error, but keeps iterating
///
/// Can be listened to more than once. Each listener iterates elements
/// independently.
///
/// @description Checks that created stream returns all the data from [Iterable]
/// @author kaigorodov

import "dart:async";
Expand Down
25 changes: 18 additions & 7 deletions LibTest/async/Stream/Stream.fromIterable_A02_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@
// 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<T> data)
/// If iterating data throws an error, the stream ends immediately with that
/// error. No done event will be sent (iteration is not complete), but no
/// further data events will be generated either, since iteration cannot
/// continue.
/// @description Checks that if iterating throws an error, onError callback
/// @assertion Stream<T>.fromIterable( Iterable<T> elements )
///
/// Creates a stream that gets its data from `elements`.
///
/// The iterable is iterated when the stream receives a listener, and stops
/// iterating if the listener cancels the subscription, or if the
/// [Iterator.moveNext] method returns false or throws. Iteration is suspended
/// while the stream subscription is paused.
///
/// If calling [Iterator.moveNext] on `elements.iterator` throws, the stream
/// emits that error and then it closes. If reading [Iterator.current] on
/// `elements.iterator` throws, the stream emits that error, but keeps iterating
///
/// Can be listened to more than once. Each listener iterates elements
/// independently.
///
/// @description Checks that if iterating throws an error, `onError` callback
/// is run with this error. Also checks that data events are neither further
/// generated nor fired and onDone event does not happen.
/// generated nor fired and `onDone` event does not happen.
/// @author ilya

import "dart:async";
Expand Down
19 changes: 16 additions & 3 deletions LibTest/async/Stream/elementAt_A01_t01.test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
// 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 Future<T> elementAt(int index)
/// Returns the value of the indexth data event of this stream.
/// Stops listening to the stream after the indexth data event has been received.
/// @assertion Future<T> elementAt( int index )
/// Returns the value of the indexth data event of this stream.
///
/// Stops listening to this stream after the indexth data event has been
/// received.
///
/// Internally the method cancels its subscription after these elements. This
/// means that single-subscription (non-broadcast) streams are closed and cannot
/// be reused after a call to this method.
///
/// If an error event occurs before the value is found, the future completes
/// with this error.
///
/// If a done event occurs before the value is found, the future completes with
/// a [RangeError].
///
/// @description Checks that the future returns the value of the indexth data
/// event of this stream.
/// @author kaigorodov
Expand Down
45 changes: 35 additions & 10 deletions LibTest/async/Stream/elementAt_A01_t02.test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,50 @@
// 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 Future<T> elementAt(int index)
/// @assertion Future<T> elementAt( int index )
/// Returns the value of the indexth data event of this stream.
/// Stops listening to the stream after the indexth data event has been received.
/// @description Checks that it stops listening to the stream after a value has
/// been found.
///
/// Stops listening to this stream after the indexth data event has been
/// received.
///
/// Internally the method cancels its subscription after these elements. This
/// means that single-subscription (non-broadcast) streams are closed and cannot
/// be reused after a call to this method.
///
/// If an error event occurs before the value is found, the future completes
/// with this error.
///
/// If a done event occurs before the value is found, the future completes with
/// a [RangeError].
///
/// @description Checks that after the indexth data event has been received
/// listening to this stream is stopped.
/// @author a.semenov@unipro.ru

library elementAt_A01_t02;

import "dart:async";
import "../../../Utils/expect.dart";

const index = 4;

void test(CreateStreamFunction create) {
Stream<int> s = create(new Iterable<int>.generate(100, (int i) => i));
asyncStart();
s.elementAt(5).then((int t) {
if (!s.isBroadcast) {
Expect.throws(() => s.listen((_) {}));
int count = -1;
Stream<int> s = create([0, 1, 2, 3, 4, 5, 6, 7, 8]);
s = s.map((event) {
count++;
if (count > index) {
Expect.fail("Stream should be cancelled");
}
asyncEnd();
return event;
});
asyncStart();
s.elementAt(index).then((int t) {
Expect.equals(index, count);
// Wait for some time to make sure that there are no more events
Future.delayed(Duration(seconds: 1), () {
Expect.equals(index, count);
asyncEnd();
});
});
}
17 changes: 15 additions & 2 deletions LibTest/async/Stream/elementAt_A01_t03.test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
// 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 Future<T> elementAt(int index)
/// @assertion Future<T> elementAt( int index )
/// Returns the value of the indexth data event of this stream.
/// Stops listening to the stream after the indexth data event has been received.
///
/// Stops listening to this stream after the indexth data event has been
/// received.
///
/// Internally the method cancels its subscription after these elements. This
/// means that single-subscription (non-broadcast) streams are closed and cannot
/// be reused after a call to this method.
///
/// If an error event occurs before the value is found, the future completes
/// with this error.
///
/// If a done event occurs before the value is found, the future completes with
/// a [RangeError].
///
/// @description Checks that it stops listening to the stream after a value has
/// been found.
/// @author ilya
Expand Down
15 changes: 14 additions & 1 deletion LibTest/async/Stream/elementAt_A02_t01.test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
// 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 Future<T> elementAt(int index)
/// @assertion Future<T> elementAt( int index )
/// Returns the value of the indexth data event of this stream.
///
/// Stops listening to this stream after the indexth data event has been
/// received.
///
/// Internally the method cancels its subscription after these elements. This
/// means that single-subscription (non-broadcast) streams are closed and cannot
/// be reused after a call to this method.
///
/// If an error event occurs before the value is found, the future completes
/// with this error.
///
/// If a done event occurs before the value is found, the future completes with
/// a [RangeError].
///
/// @description Checks that if an error event occurs before the value is found,
/// the future will end with this error.
/// @author kaigorodov
Expand Down
19 changes: 16 additions & 3 deletions LibTest/async/Stream/elementAt_A03_t01.test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
// 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 Future<T> elementAt(int index)
/// If a done event occurs before the value is found, the future completes with a
/// RangeError.
/// @assertion Future<T> elementAt( int index )
/// Returns the value of the indexth data event of this stream.
///
/// Stops listening to this stream after the indexth data event has been
/// received.
///
/// Internally the method cancels its subscription after these elements. This
/// means that single-subscription (non-broadcast) streams are closed and cannot
/// be reused after a call to this method.
///
/// If an error event occurs before the value is found, the future completes
/// with this error.
///
/// If a done event occurs before the value is found, the future completes with
/// a [RangeError].
///
/// @description Checks that if a done event occurs before the value is found,
/// the future completes with a RangeError.
/// @author kaigorodov
Expand Down
30 changes: 20 additions & 10 deletions LibTest/async/Stream/firstWhere_A04_t01.test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,36 @@
/// If an error occurs, or if this stream ends without finding a match and with
/// no orElse function provided, the returned future is completed with an error.
///
/// @description Checks that non broadcast stream can not be listened after
/// the first element is returned.
/// @description Checks that listening to this stream is stopped after the first
/// matching element received.
/// @author a.semenov@unipro.ru

library firstWhere_A04_t01;

import "dart:async";
import "../../../Utils/expect.dart";

void check(Stream s) {
asyncStart();
s.firstWhere((_) => true).then((_) {
if (!s.isBroadcast) {
Expect.throws(() => s.listen((_) {}));
void check(Stream s, int max) {
int count = 0;
s = s.map((event) {
count++;
if (count > max) {
Expect.fail("Stream should be cancelled");
}
asyncEnd();
return event;
});
asyncStart();
s.firstWhere((v) => v == 2).then((_) {
Expect.equals(count, max);
// Wait for some time to make sure that there is no more events
Future.delayed(Duration(seconds: 1), () {
Expect.equals(count, max);
asyncEnd();
});
});
}

void test(CreateStreamFunction create) {
check(create([123]));
check(create([1, 2, 3]));
check(create([1, 2, 3, 4, 5]), 2);
check(create([0, 1, 2, 3, 4]), 3);
}
20 changes: 18 additions & 2 deletions LibTest/async/Stream/first_A01_t01.test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@
// 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 Future<T> first
/// Returns the first element of the stream.
/// @assertion Future<T> get first
/// The first element of this stream.
///
/// Stops listening to this stream after the first element has been received.
///
/// Internally the method cancels its subscription after the first element. This
/// means that single-subscription (non-broadcast) streams are closed and cannot
/// be reused after a call to this getter.
///
/// If an error event occurs before the first data event, the returned future is
/// completed with that error.
///
/// If this stream is empty (a done event occurs before the first data event),
/// the returned future completes with an error.
///
/// Except for the type of the error, this method is equivalent to
/// [this.elementAt(0)].
///
/// @description Checks that the first element is returned.
/// @author kaigorodov

Expand Down
25 changes: 19 additions & 6 deletions LibTest/async/Stream/first_A02_t01.test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,32 @@
// 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 Future<T> first
/// @assertion Future<T> get first
/// The first element of this stream.
///
/// Stops listening to this stream after the first element has been received.
///
/// Internally the method cancels its subscription after the first element. This
/// means that single-subscription (non-broadcast) streams are closed and cannot
/// be reused after a call to this getter.
///
/// If an error event occurs before the first data event, the returned future is
/// completed with that error.
///
/// If this stream is empty (a done event occurs before the first data event),
/// the resulting future completes with a StateError.
/// the returned future completes with an error.
///
/// Except for the type of the error, this method is equivalent to
/// this.elementAt(0).
/// @description Checks that future completes with a StateError when this
/// stream is empty.
/// [this.elementAt(0)].
///
/// @description Checks that future completes with an error when this stream is
/// empty.
/// @author kaigorodov

library first_A02_t01;

import "../../../Utils/expect.dart";

void test(CreateStreamFunction create) {
AsyncExpect.error((e) => e is StateError, create([]).first);
AsyncExpect.error((e) => e is Error, create([]).first);
}
21 changes: 17 additions & 4 deletions LibTest/async/Stream/first_A02_t02.test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@
// 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 Future<T> first
/// @assertion Future<T> get first
/// The first element of this stream.
///
/// Stops listening to this stream after the first element has been received.
///
/// Internally the method cancels its subscription after the first element. This
/// means that single-subscription (non-broadcast) streams are closed and cannot
/// be reused after a call to this getter.
///
/// If an error event occurs before the first data event, the returned future is
/// completed with that error.
///
/// If this stream is empty (a done event occurs before the first data event),
/// the resulting future completes with a StateError.
/// the returned future completes with an error.
///
/// Except for the type of the error, this method is equivalent to
/// this.elementAt(0).
/// [this.elementAt(0)].
///
/// @description Checks that for non-empty stream, this.first is equivalent to
/// this.elementAt(0).
/// [this.elementAt(0)].
/// @author kaigorodov

library first_A02_t02;
Expand Down
Loading