granite-rust/tests/coverage/yield.rs
Zalathar 9dc6e08279 Manually run x fmt on all source files in tests/coverage/
Currently we can't automatically enforce formatting on tests (see ), but
we can at least keep things relatively tidy by occasionally running the
formatter manually.

This was done by temporarily commenting out the `"/tests/"` exclusion in
`rustfmt.toml`, and then running `x fmt tests/coverage` and
`x test coverage --bless`.
2024-05-29 14:34:17 +10:00

39 lines
989 B
Rust

#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
#![allow(unused_assignments)]
use std::ops::{Coroutine, CoroutineState};
use std::pin::Pin;
fn main() {
let mut coroutine = #[coroutine]
|| {
yield 1;
return "foo";
};
match Pin::new(&mut coroutine).resume(()) {
CoroutineState::Yielded(1) => {}
_ => panic!("unexpected value from resume"),
}
match Pin::new(&mut coroutine).resume(()) {
CoroutineState::Complete("foo") => {}
_ => panic!("unexpected value from resume"),
}
let mut coroutine = #[coroutine]
|| {
yield 1;
yield 2;
yield 3;
return "foo";
};
match Pin::new(&mut coroutine).resume(()) {
CoroutineState::Yielded(1) => {}
_ => panic!("unexpected value from resume"),
}
match Pin::new(&mut coroutine).resume(()) {
CoroutineState::Yielded(2) => {}
_ => panic!("unexpected value from resume"),
}
}