Skip to content

Commit

Permalink
Small tests for derive Eq
Browse files Browse the repository at this point in the history
  • Loading branch information
photoszzt committed Aug 21, 2017
1 parent 3fc501f commit ff9d000
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 44 deletions.
8 changes: 4 additions & 4 deletions tests/expectations/tests/derive-hash-blacklisting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]

#[repr(C)] #[derive(Debug, Hash, Copy, Clone)] pub struct Blacklisted<T> {t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>> }
#[repr(C)] #[derive(Debug, Hash, Copy, Clone, PartialEq, Eq)] pub struct Blacklisted<T> {t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>> }

/// This would derive(Hash) if it didn't contain a blacklisted type,
/// causing us to conservatively avoid deriving hash for it.
/// This would derive(Hash, Eq, PartialEq) if it didn't contain a blacklisted type,
/// causing us to conservatively avoid deriving hash/Eq/PartialEq for it.
#[repr(C)]
#[derive(Debug, Copy)]
pub struct WhitelistedOne {
Expand All @@ -30,7 +30,7 @@ impl Clone for WhitelistedOne {
impl Default for WhitelistedOne {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
/// This can't derive(Hash) even if it didn't contain a blacklisted type.
/// This can't derive(Hash/Eq) even if it didn't contain a blacklisted type.
#[repr(C)]
#[derive(Debug, Copy)]
pub struct WhitelistedTwo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


/// A struct containing a struct containing a float that cannot derive hash.
/// A struct containing a struct containing a float that cannot derive hash/eq but can derive partial eq.
#[repr(C)]
#[derive(Debug, Default, Copy)]
#[derive(Debug, Default, Copy, PartialEq)]
pub struct foo {
pub bar: foo__bindgen_ty_1,
}
#[repr(C)]
#[derive(Debug, Default, Copy)]
#[derive(Debug, Default, Copy, PartialEq)]
pub struct foo__bindgen_ty_1 {
pub a: f32,
pub b: f32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


/// A struct containing an array of floats that cannot derive hash.
/// A struct containing an array of floats that cannot derive hash/eq but can derive partialeq.
#[repr(C)]
#[derive(Debug, Default, Copy)]
#[derive(Debug, Default, Copy, PartialEq)]
pub struct foo {
pub bar: [f32; 3usize],
}
Expand Down
10 changes: 5 additions & 5 deletions tests/expectations/tests/derive-hash-struct-with-pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


/// Pointers can derive hash/PartialEq
/// Pointers can derive hash/PartialEq/Eq
#[repr(C)]
#[derive(Debug, Copy, Hash, PartialEq)]
#[derive(Debug, Copy, Hash, PartialEq, Eq)]
pub struct ConstPtrMutObj {
pub bar: *const ::std::os::raw::c_int,
}
Expand All @@ -29,7 +29,7 @@ impl Default for ConstPtrMutObj {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
#[derive(Debug, Copy, Hash, PartialEq)]
#[derive(Debug, Copy, Hash, PartialEq, Eq)]
pub struct MutPtrMutObj {
pub bar: *mut ::std::os::raw::c_int,
}
Expand All @@ -52,7 +52,7 @@ impl Default for MutPtrMutObj {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
#[derive(Debug, Copy, Hash, PartialEq)]
#[derive(Debug, Copy, Hash, PartialEq, Eq)]
pub struct MutPtrConstObj {
pub bar: *const ::std::os::raw::c_int,
}
Expand All @@ -75,7 +75,7 @@ impl Default for MutPtrConstObj {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
#[derive(Debug, Copy, Hash, PartialEq)]
#[derive(Debug, Copy, Hash, PartialEq, Eq)]
pub struct ConstPtrConstObj {
pub bar: *const ::std::os::raw::c_int,
}
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/tests/derive-hash-template-def-float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


/// Template definition containing a float, which cannot derive hash.
/// Template definition containing a float, which cannot derive hash/eq but can derive partialeq.
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct foo<T> {
pub data: T,
pub b: f32,
Expand Down
12 changes: 6 additions & 6 deletions tests/expectations/tests/derive-hash-template-inst-float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


/// Template definition that doesn't contain float can derive hash
/// Template definition that doesn't contain float can derive hash/partialeq/eq
#[repr(C)]
#[derive(Debug, Copy, Clone, Hash)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct foo<T> {
pub data: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
impl <T> Default for foo<T> {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
/// Can derive hash when instantiated with int
/// Can derive hash/partialeq/eq when instantiated with int
#[repr(C)]
#[derive(Debug, Copy, Hash)]
#[derive(Debug, Copy, Hash, PartialEq, Eq)]
pub struct IntStr {
pub a: foo<::std::os::raw::c_int>,
}
Expand All @@ -38,9 +38,9 @@ impl Clone for IntStr {
impl Default for IntStr {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
/// Cannot derive hash when instantiated with float
/// Cannot derive hash/eq when instantiated with float but can derive partialeq
#[repr(C)]
#[derive(Debug, Copy)]
#[derive(Debug, Copy, PartialEq)]
pub struct FloatStr {
pub a: foo<f32>,
}
Expand Down
16 changes: 8 additions & 8 deletions tests/headers/derive-hash-blacklisting.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// bindgen-flags: --with-derive-hash --whitelist-type 'Whitelisted.*' --blacklist-type Blacklisted --raw-line "#[repr(C)] #[derive(Debug, Hash, Copy, Clone)] pub struct Blacklisted<T> {t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>> }"
// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --whitelist-type 'Whitelisted.*' --blacklist-type Blacklisted --raw-line "#[repr(C)] #[derive(Debug, Hash, Copy, Clone, PartialEq, Eq)] pub struct Blacklisted<T> {t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>> }"
//
template<class T>
template <class T>
struct Blacklisted {
T t;
T t;
};

/// This would derive(Hash) if it didn't contain a blacklisted type,
/// causing us to conservatively avoid deriving hash for it.
/// This would derive(Hash, Eq, PartialEq) if it didn't contain a blacklisted type,
/// causing us to conservatively avoid deriving hash/Eq/PartialEq for it.
struct WhitelistedOne {
Blacklisted<int> a;
Blacklisted<int> a;
};

/// This can't derive(Hash) even if it didn't contain a blacklisted type.
/// This can't derive(Hash/Eq) even if it didn't contain a blacklisted type.
struct WhitelistedTwo {
Blacklisted<float> b;
Blacklisted<float> b;
};
4 changes: 2 additions & 2 deletions tests/headers/derive-hash-struct-with-anon-struct-float.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// bindgen-flags: --with-derive-hash
// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
//
/// A struct containing a struct containing a float that cannot derive hash.
/// A struct containing a struct containing a float that cannot derive hash/eq but can derive partial eq.
struct foo {
struct {
float a;
Expand Down
4 changes: 2 additions & 2 deletions tests/headers/derive-hash-struct-with-float-array.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// bindgen-flags: --with-derive-hash
// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
//
/// A struct containing an array of floats that cannot derive hash.
/// A struct containing an array of floats that cannot derive hash/eq but can derive partialeq.
struct foo {
float bar[3];
};
4 changes: 2 additions & 2 deletions tests/headers/derive-hash-struct-with-pointer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// bindgen-flags: --with-derive-hash --with-derive-partialeq
// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
//
/// Pointers can derive hash/PartialEq
/// Pointers can derive hash/PartialEq/Eq
struct ConstPtrMutObj {
int* const bar;
};
Expand Down
6 changes: 3 additions & 3 deletions tests/headers/derive-hash-template-def-float.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// bindgen-flags: --with-derive-hash
// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
//
/// Template definition containing a float, which cannot derive hash.
template<typename T>
/// Template definition containing a float, which cannot derive hash/eq but can derive partialeq.
template <typename T>
struct foo {
T data;
float b;
Expand Down
10 changes: 5 additions & 5 deletions tests/headers/derive-hash-template-inst-float.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// bindgen-flags: --with-derive-hash
// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
//
/// Template definition that doesn't contain float can derive hash
template<typename T>
/// Template definition that doesn't contain float can derive hash/partialeq/eq
template <typename T>
struct foo {
T data;
};

/// Can derive hash when instantiated with int
/// Can derive hash/partialeq/eq when instantiated with int
struct IntStr {
foo<int> a;
};

/// Cannot derive hash when instantiated with float
/// Cannot derive hash/eq when instantiated with float but can derive partialeq
struct FloatStr {
foo<float> a;
};

0 comments on commit ff9d000

Please sign in to comment.