Skip to content

Commit

Permalink
Add some non-scalar value tests for Default.
Browse files Browse the repository at this point in the history
PR mcarton#38 made Default expressions with e.g. list values fail and there
weren't any tests for them.
  • Loading branch information
kankri committed Aug 23, 2019
1 parent 0bd0e52 commit 8c16772
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/derive-default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ struct Bar (
u8,
);

#[derive(Debug, PartialEq)]
struct B1(u8, u8);
#[derive(Debug, PartialEq)]
struct B2{a:u8, b:u8}

#[derive(Debug, Derivative, PartialEq)]
#[derivative(Default(new="true"))]
struct Baz (
#[derivative(Default(value="[1,2]"))]
[u8;2],
#[derivative(Default(value="[3;2]"))]
[u8;2],
#[derivative(Default(value="(4,5)"))]
(u8, u8),
#[derivative(Default(value="B1(6,7)"))]
B1,
#[derivative(Default(value="B2{a:8,b:9}"))]
B2,
);

#[derive(Debug, Derivative, PartialEq)]
#[derivative(Default)]
enum Enum1 {
Expand Down Expand Up @@ -51,6 +71,7 @@ fn main() {
assert_eq!(Foo::new(), Foo { foo: 0, bar: 42 });
assert_eq!(Bar::default(), Bar(0, 42));
assert_eq!(Bar::new(), Bar(0, 42));
assert_eq!(Baz::new(), Baz([1,2], [3,3], (4,5), B1(6,7), B2{a:8,b:9}));
assert_eq!(A::default(), A(NoDefault));
assert_eq!(Enum1::default(), Enum1::B);
assert_eq!(Enum2::default(), Enum2::A);
Expand Down

0 comments on commit 8c16772

Please sign in to comment.