Skip to content

Commit

Permalink
moved tests to druid-derive
Browse files Browse the repository at this point in the history
added entry to changelog
  • Loading branch information
chris-zen committed Jun 29, 2020
1 parent edec816 commit cc31aae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ You can find its changes [documented below](#060---2020-06-01).
- macOS: Timers not firing during modal loop. ([#1028] by [@xStrom])
- GTK: Directory selection now properly ignores file filters. ([#957] by [@xStrom])
- GTK: Don't crash when receiving an external command while a file dialog is visible. ([#1043] by [@jneem])
- Fix derive `Data` when type param bounds are defined ([#1058] by [@chris-zen])

### Visual

Expand Down
40 changes: 40 additions & 0 deletions druid-derive/tests/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ struct MultiFieldStruct {
c: String,
}

trait UserTrait {}

#[derive(Clone, Data)]
struct TypeParamForUserTraitStruct<T: UserTrait + Data> {
a: T,
}

#[derive(Clone, Data)]
struct TypeParamForUserTraitWithWhereClauseStruct<T>
where
T: UserTrait,
{
b: T,
}

#[derive(Clone, Data)]
enum TypeParamForUserTraitAndLifetimeEnum<T: UserTrait + 'static> {
V1(T),
}

#[test]
fn test_data_derive_same() {
let plain = PlainStruct;
Expand Down Expand Up @@ -70,4 +90,24 @@ fn test_data_derive_same() {
c: "Fail".to_string()
})
);

#[derive(Clone, Data)]
struct Value(u32);

impl UserTrait for Value {}

let v = TypeParamForUserTraitStruct { a: Value(1) };
assert!(v.same(&v));
assert_eq!(false, v.same(&TypeParamForUserTraitStruct { a: Value(2) }));

let v = TypeParamForUserTraitWithWhereClauseStruct { b: Value(3) };
assert!(v.same(&v));
assert_eq!(
false,
v.same(&TypeParamForUserTraitWithWhereClauseStruct { b: Value(6) })
);

let v = TypeParamForUserTraitAndLifetimeEnum::V1(Value(10));
assert!(v.same(&v));
assert_eq!(false, v.same(&TypeParamForUserTraitAndLifetimeEnum::V1(Value(12))));
}
31 changes: 0 additions & 31 deletions druid/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,34 +474,3 @@ mod test {
assert!(!one.same(&two));
}
}

#[cfg(test)]
mod tests {

#[allow(dead_code)]
#[test]
fn test_derive() {
use crate::data::Data;

trait X {}

#[derive(Clone, Data)]
struct A<T: X + Data> {
a: T,
}

#[derive(Clone, Data)]
struct B<T>
where
T: X,
{
b: T,
}

#[derive(Clone, Data)]
enum C<T: X + 'static> {
V1(T),
V2,
}
}
}

0 comments on commit cc31aae

Please sign in to comment.