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
37 changes: 37 additions & 0 deletions LibTest/async/Stream/Stream.error_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2024, 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 @Since("2.5")
/// Stream<T>.error( Object error, [ StackTrace? stackTrace ])
///
/// Creates a stream which emits a single error event before completing.
///
/// This stream emits a single error event of `error` and `stackTrace` and then
/// completes with a done event.
///
/// @description Checks that `Stream.error()` constructor creates a stream which
/// emits a single error event before completing.
/// @author sgrekhov22@gmail.com

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

main() async {
Stream stream1 = Stream.error("Stream.error");
try {
await for (var x in stream1) {
Expect.fail("Unexpected event $x");
}
} catch (e) {
Expect.equals("Stream.error", e);
}

Stream stream2 = Stream.error("Stream.error");
try {
await stream2.isEmpty;
Expect.fail("Expected an error");
} catch (e) {
Expect.equals("Stream.error", e);
}
}
29 changes: 29 additions & 0 deletions LibTest/async/Stream/Stream.error_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2024, 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 @Since("2.5")
/// Stream<T>.error( Object error, [ StackTrace? stackTrace ])
///
/// Creates a stream which emits a single error event before completing.
///
/// This stream emits a single error event of `error` and `stackTrace` and then
/// completes with a done event.
///
/// @description Checks that if `stackTrace` is specified it is available when a
/// `catch` clause is executed to catch the error.
/// @author sgrekhov22@gmail.com

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

main() async {
StackTrace stackTrace = StackTrace.fromString("My StackTrace");
Stream stream = Stream.error("Stream.error", stackTrace);
try {
var v = await stream.first;
Expect.fail("Unexpected event $v");
} catch (e, st) {
Expect.equals("My StackTrace", st.toString());
}
}
33 changes: 33 additions & 0 deletions LibTest/async/Stream/Stream.error_A01_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2024, 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 @Since("2.5")
/// Stream<T>.error( Object error, [ StackTrace? stackTrace ])
///
/// Creates a stream which emits a single error event before completing.
///
/// This stream emits a single error event of `error` and `stackTrace` and then
/// completes with a done event.
///
/// @description Checks that the `Stream.error()` constructor creates a stream
/// which emits a single error event and then calls 'onDone'.
/// @author sgrekhov22@gmail.com

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

main() {
var onErrors = 0;
asyncStart();
Stream stream = Stream.error("Stream.error");
stream.listen((v) {
Expect.fail("Unexpected event $v");
}, onError: (e) {
onErrors++;
Expect.equals("Stream.error", e);
}, onDone: () {
Expect.equals(onErrors, 1);
asyncEnd();
});
}
27 changes: 27 additions & 0 deletions LibTest/async/Stream/Stream.value_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2024, 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 @Since("2.5")
/// Stream<T>.value( T value )
/// Creates a stream which emits a single data event before closing.
///
/// This stream emits a single data event of value and then closes with a done
/// event.
///
/// @description Checks that the `Stream.value()` constructor creates a stream
/// which emits a single data event before closing.
/// @author sgrekhov22@gmail.com

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

main() async {
var stream1 = Stream<String>.value("Stream.value");
var v = await stream1.first;
Expect.equals("Stream.value", v);

Stream stream2 = Stream.value("Stream.value");
var empty = await stream2.isEmpty;
Expect.isFalse(empty);
}
30 changes: 30 additions & 0 deletions LibTest/async/Stream/Stream.value_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2024, 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 @Since("2.5")
/// Stream<T>.value( T value )
/// Creates a stream which emits a single data event before closing.
///
/// This stream emits a single data event of value and then closes with a done
/// event.
///
/// @description Checks that the `Stream.value()` constructor creates a stream
/// which emits a single data event before closing.
/// @author sgrekhov22@gmail.com

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

main() {
int counter = 0;
asyncStart();
Stream stream = Stream.value("Stream.value");
stream.listen((v) {
counter++;
Expect.equals("Stream.value", v);
}, onDone: () {
Expect.equals(1, counter);
asyncEnd();
});
}