diff options
Diffstat (limited to 'src/test/run-make/coverage/yield.rs')
-rw-r--r-- | src/test/run-make/coverage/yield.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/test/run-make/coverage/yield.rs b/src/test/run-make/coverage/yield.rs new file mode 100644 index 000000000..ff7616656 --- /dev/null +++ b/src/test/run-make/coverage/yield.rs @@ -0,0 +1,37 @@ +#![feature(generators, generator_trait)] +#![allow(unused_assignments)] + +use std::ops::{Generator, GeneratorState}; +use std::pin::Pin; + +fn main() { + let mut generator = || { + yield 1; + return "foo" + }; + + match Pin::new(&mut generator).resume(()) { + GeneratorState::Yielded(1) => {} + _ => panic!("unexpected value from resume"), + } + match Pin::new(&mut generator).resume(()) { + GeneratorState::Complete("foo") => {} + _ => panic!("unexpected value from resume"), + } + + let mut generator = || { + yield 1; + yield 2; + yield 3; + return "foo" + }; + + match Pin::new(&mut generator).resume(()) { + GeneratorState::Yielded(1) => {} + _ => panic!("unexpected value from resume"), + } + match Pin::new(&mut generator).resume(()) { + GeneratorState::Yielded(2) => {} + _ => panic!("unexpected value from resume"), + } +} |