libfringe/tests/iterator.rs
edef df7f261ca6 Expose unsafe_unwrap
This at least ensures we don't have to needlessly leak generators in the
tests, and covers similar use cases for consumers of libfringe.
2017-03-16 22:40:20 +01:00

23 lines
810 B
Rust

// This file is part of libfringe, a low-level green threading library.
// Copyright (c) whitequark <whitequark@whitequark.org>
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
extern crate fringe;
use fringe::OsStack;
use fringe::generator::Generator;
#[test]
fn producer() {
let stack = OsStack::new(0).unwrap();
let mut gen = Generator::new(stack, move |yielder, ()| {
for i in 0.. { yielder.suspend(i) }
});
assert_eq!(gen.next(), Some(0));
assert_eq!(gen.next(), Some(1));
assert_eq!(gen.next(), Some(2));
unsafe { gen.unsafe_unwrap(); }
}