Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cksac committed Oct 25, 2023
1 parent b440b27 commit c190c01
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dummy_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dummy"
version = "0.6.0"
version = "0.7.0"
authors = ["cksac <[email protected]>"]
description = "Macros implementation of #[derive(Dummy)]"
keywords = ["faker", "data", "random"]
Expand Down
2 changes: 1 addition & 1 deletion fake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rust-version = "1.56"
all-features = true

[dependencies]
dummy = { version = "0.6", path = "../dummy_derive", optional = true }
dummy = { version = "0.7", path = "../dummy_derive", optional = true }
rand = "0.8"
random_color = { version = "0.6", optional = true }
deunicode = "1.4"
Expand Down
8 changes: 8 additions & 0 deletions fake/examples/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ struct EmptyStruct {}
#[derive(Debug, Dummy)]
struct NewType(#[dummy(faker = "1..100")] usize, String);

#[derive(Debug, Dummy)]
struct MyStruct<T> {
field: Vec<T>,
}

fn main() {
let order: Order = Faker.fake();
println!("{:#?}", order);
Expand Down Expand Up @@ -125,4 +130,7 @@ fn main() {

let v: DefaultStruct = Faker.fake();
println!("{:#?}", v);

let v: MyStruct<u32> = Faker.fake();
println!("{:#?}", v);
}
44 changes: 44 additions & 0 deletions fake/tests/derive_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,47 @@ mod test_trait_scope {
}
}
}

mod test_generic {
use super::*;

#[test]
#[allow(dead_code)]
fn generic_struct() {
#[derive(Eq, PartialEq, Debug, Dummy)]
struct MyStruct<T, U> {
f1: T,
f2: U,
}

let o: MyStruct<u8, f32> = Faker.fake_with_rng(&mut rng());

assert_eq!(o.f1, 118);
assert_eq!(o.f2, 0.56344515);
}

#[test]
#[allow(dead_code)]
fn generic_enum() {
#[derive(Eq, PartialEq, Debug, Dummy)]
enum MyEnum<T, U> {
F1(T),
F2(U),
}

let o: MyEnum<u8, f32> = Faker.fake_with_rng(&mut rng());

assert_eq!(o, MyEnum::F2(0.8961542));
}

#[test]
#[allow(dead_code)]
fn generic_tuple() {
#[derive(Eq, PartialEq, Debug, Dummy)]
struct MyTuple<T, U>(T, U);

let o: MyTuple<u8, f32> = Faker.fake_with_rng(&mut rng());
assert_eq!(o.0, 118);
assert_eq!(o.1, 0.56344515);
}
}

0 comments on commit c190c01

Please sign in to comment.