mirror of
https://codeberg.org/JasterV/test-context.git
synced 2026-04-26 18:10:06 +00:00
Update README.md (#47)
This commit is contained in:
parent
5c8a0a1d51
commit
64a4e1ba7f
1 changed files with 0 additions and 36 deletions
36
README.md
36
README.md
|
|
@ -47,42 +47,6 @@ fn test_generic_type(ctx: &mut MyGenericContext<u32>) {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
with generic types, you can use same type with different values
|
|
||||||
|
|
||||||
```rust
|
|
||||||
use test_context::{test_context, TestContext};
|
|
||||||
use std::marker::PhantomData;
|
|
||||||
|
|
||||||
struct MyGenericContext<T> {
|
|
||||||
value: u32,
|
|
||||||
_marker: PhantomData<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TestContext for MyGenericContext<String> {
|
|
||||||
fn setup() -> MyGenericContext<String> {
|
|
||||||
MyGenericContext { value: 1, _marker: PhantomData }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test_context(MyGenericContext<String>)]
|
|
||||||
#[test]
|
|
||||||
fn test_generic_type(ctx: &mut MyGenericContext<String>) {
|
|
||||||
assert_eq!(ctx.value, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TestContext for MyGenericContext<u32> {
|
|
||||||
fn setup() -> MyGenericContext<u32> {
|
|
||||||
MyGenericContext { value: 2, _marker: PhantomData }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test_context(MyGenericContext<u32>)]
|
|
||||||
#[test]
|
|
||||||
fn test_generic_type_u32(ctx: &mut MyGenericContext<u32>) {
|
|
||||||
assert_eq!(ctx.value, 2);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Alternatively, you can use `async` functions in your test context by using the
|
Alternatively, you can use `async` functions in your test context by using the
|
||||||
`AsyncTestContext`.
|
`AsyncTestContext`.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue