rust/tests/coverage/yield.rs

40 lines
989 B
Rust
Raw Normal View History

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