Skip to content

Commit

Permalink
add test for enum and union
Browse files Browse the repository at this point in the history
Signed-off-by: Petros Angelatos <[email protected]>
  • Loading branch information
petrosagg committed Mar 28, 2021
1 parent 9969a39 commit 0051a2c
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions escher/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,49 @@ fn adversarial_capture_non_stack() {
});
}

#[test]
fn capture_enum() {
/// Holds a vector and a str reference to the data of the vector
#[derive(Rebindable,PartialEq,Debug)]
enum MaybeStr<'a> {
Some(&'a str),
None
}

let mut escher_heart = Escher::new(|r| async move {
let data: Vec<u8> = vec![240, 159, 146, 150];
let sparkle_heart = std::str::from_utf8(&data).unwrap();

r.capture(MaybeStr::Some(sparkle_heart)).await;
});
assert_eq!(MaybeStr::Some("💖"), *escher_heart.as_ref());
*escher_heart.as_mut() = MaybeStr::None;
assert_eq!(MaybeStr::None, *escher_heart.as_ref());
}

#[test]
fn capture_union() {
/// Holds a vector and a str reference to the data of the vector
#[derive(Rebindable)]
union MaybeStr<'a> {
some: &'a str,
none: (),
}

let mut escher_heart = Escher::new(|r| async move {
let data: Vec<u8> = vec![240, 159, 146, 150];
let sparkle_heart = std::str::from_utf8(&data).unwrap();

r.capture(MaybeStr { some: sparkle_heart }).await;
});

unsafe {
assert_eq!("💖", escher_heart.as_ref().some);
escher_heart.as_mut().none = ();
assert_eq!((), escher_heart.as_ref().none);
}
}

#[test]
fn it_works() {
/// Holds a vector and a str reference to the data of the vector
Expand Down

0 comments on commit 0051a2c

Please sign in to comment.