Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from la10736/by_ref
Implement `#[by_ref]` attribute
- Loading branch information
Showing
21 changed files
with
941 additions
and
480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use rstest::*; | ||
use std::fs::File; | ||
use std::io::Read; | ||
use std::path::PathBuf; | ||
|
||
#[rstest] | ||
fn start_with_name( | ||
#[files("files/**/*.txt")] | ||
#[by_ref] | ||
path: &PathBuf, | ||
) { | ||
let name = path.file_name().unwrap(); | ||
let mut f = File::open(&path).unwrap(); | ||
let mut contents = String::new(); | ||
f.read_to_string(&mut contents).unwrap(); | ||
|
||
assert!(contents.starts_with(name.to_str().unwrap())) | ||
} | ||
|
||
#[fixture] | ||
fn f() -> u32 { | ||
42 | ||
} | ||
|
||
#[rstest] | ||
#[case(42)] | ||
fn test( | ||
#[by_ref] f: &u32, | ||
#[case] | ||
#[by_ref] | ||
c: &u32, | ||
#[values(42, 142)] | ||
#[by_ref] | ||
v: &u32, | ||
) { | ||
assert_eq!(f, c); | ||
assert_eq!(*c, *v % 100); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use std::cell::Cell; | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
enum E<'a> { | ||
A(bool), | ||
B(&'a Cell<E<'a>>), | ||
} | ||
|
||
fn make_e_from_bool<'a>(_bump: &'a (), b: bool) -> E<'a> { | ||
E::A(b) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use rstest::*; | ||
|
||
use super::*; | ||
|
||
#[fixture] | ||
fn bump() -> () {} | ||
|
||
#[rstest] | ||
#[case(true, E::A(true))] | ||
fn it_works<'a>(#[by_ref] bump: &'a (), #[case] b: bool, #[case] expected: E<'a>) { | ||
let actual = make_e_from_bool(&bump, b); | ||
assert_eq!(actual, expected); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.