-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// 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. | ||
/// @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(stackTrace, st); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>.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 and then calls 'onDone'. | ||
/// @author sgrekhov22@gmail.com | ||
import "dart:async"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
main() { | ||
asyncStart(); | ||
Stream stream = Stream.error("Stream.error"); | ||
stream.listen((v) { | ||
Expect.fail("Unexpected event $v"); | ||
}, onError: (e) { | ||
Expect.equals("Stream.error", e); | ||
}, onDone: () { | ||
asyncEnd(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 `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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 `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() { | ||
asyncStart(); | ||
Stream stream = Stream.value("Stream.value"); | ||
stream.listen((v) { | ||
Expect.equals("Stream.value", v); | ||
}, onDone: () { | ||
asyncEnd(); | ||
}); | ||
} |