mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 08:47:57 +00:00
@@ -15,9 +15,12 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Tests for DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound, and RuntimeDebugNoBound
|
||||
//! Tests for DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound, DefaultNoBound, and
|
||||
//! RuntimeDebugNoBound
|
||||
|
||||
use frame_support::{DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound};
|
||||
use frame_support::{
|
||||
DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound, DefaultNoBound,
|
||||
};
|
||||
|
||||
#[derive(RuntimeDebugNoBound)]
|
||||
struct Unnamed(u64);
|
||||
@@ -29,7 +32,7 @@ fn runtime_debug_no_bound_display_correctly() {
|
||||
}
|
||||
|
||||
trait Config {
|
||||
type C: std::fmt::Debug + Clone + Eq + PartialEq;
|
||||
type C: std::fmt::Debug + Clone + Eq + PartialEq + Default;
|
||||
}
|
||||
|
||||
struct Runtime;
|
||||
@@ -39,7 +42,7 @@ impl Config for Runtime {
|
||||
type C = u32;
|
||||
}
|
||||
|
||||
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound)]
|
||||
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound, DefaultNoBound)]
|
||||
struct StructNamed<T: Config, U, V> {
|
||||
a: u32,
|
||||
b: u64,
|
||||
@@ -56,6 +59,12 @@ fn test_struct_named() {
|
||||
phantom: Default::default(),
|
||||
};
|
||||
|
||||
let a_default: StructNamed::<Runtime, ImplNone, ImplNone> = Default::default();
|
||||
assert_eq!(a_default.a, 0);
|
||||
assert_eq!(a_default.b, 0);
|
||||
assert_eq!(a_default.c, 0);
|
||||
assert_eq!(a_default.phantom, Default::default());
|
||||
|
||||
let a_2 = a_1.clone();
|
||||
assert_eq!(a_2.a, 1);
|
||||
assert_eq!(a_2.b, 2);
|
||||
@@ -76,7 +85,7 @@ fn test_struct_named() {
|
||||
assert!(b != a_1);
|
||||
}
|
||||
|
||||
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound)]
|
||||
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound, DefaultNoBound)]
|
||||
struct StructUnnamed<T: Config, U, V>(u32, u64, T::C, core::marker::PhantomData<(U, V)>);
|
||||
|
||||
#[test]
|
||||
@@ -88,6 +97,12 @@ fn test_struct_unnamed() {
|
||||
Default::default(),
|
||||
);
|
||||
|
||||
let a_default: StructUnnamed::<Runtime, ImplNone, ImplNone> = Default::default();
|
||||
assert_eq!(a_default.0, 0);
|
||||
assert_eq!(a_default.1, 0);
|
||||
assert_eq!(a_default.2, 0);
|
||||
assert_eq!(a_default.3, Default::default());
|
||||
|
||||
let a_2 = a_1.clone();
|
||||
assert_eq!(a_2.0, 1);
|
||||
assert_eq!(a_2.1, 2);
|
||||
@@ -108,7 +123,7 @@ fn test_struct_unnamed() {
|
||||
assert!(b != a_1);
|
||||
}
|
||||
|
||||
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound)]
|
||||
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound, DefaultNoBound)]
|
||||
enum Enum<T: Config, U, V> {
|
||||
VariantUnnamed(u32, u64, T::C, core::marker::PhantomData<(U, V)>),
|
||||
VariantNamed {
|
||||
@@ -121,6 +136,32 @@ enum Enum<T: Config, U, V> {
|
||||
VariantUnit2,
|
||||
}
|
||||
|
||||
// enum that will have a named default.
|
||||
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound, DefaultNoBound)]
|
||||
enum Enum2<T: Config> {
|
||||
VariantNamed {
|
||||
a: u32,
|
||||
b: u64,
|
||||
c: T::C,
|
||||
},
|
||||
VariantUnnamed(u32, u64, T::C),
|
||||
VariantUnit,
|
||||
VariantUnit2,
|
||||
}
|
||||
|
||||
// enum that will have a unit default.
|
||||
#[derive(DebugNoBound, CloneNoBound, EqNoBound, PartialEqNoBound, DefaultNoBound)]
|
||||
enum Enum3<T: Config> {
|
||||
VariantUnit,
|
||||
VariantNamed {
|
||||
a: u32,
|
||||
b: u64,
|
||||
c: T::C,
|
||||
},
|
||||
VariantUnnamed(u32, u64, T::C),
|
||||
VariantUnit2,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_enum() {
|
||||
type TestEnum = Enum::<Runtime, ImplNone, ImplNone>;
|
||||
@@ -131,6 +172,22 @@ fn test_enum() {
|
||||
let variant_2 = TestEnum::VariantUnit;
|
||||
let variant_3 = TestEnum::VariantUnit2;
|
||||
|
||||
let default: TestEnum = Default::default();
|
||||
assert_eq!(
|
||||
default,
|
||||
// first variant is default.
|
||||
TestEnum::VariantUnnamed(0, 0, 0, Default::default())
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Enum2::<Runtime>::default(),
|
||||
Enum2::<Runtime>::VariantNamed { a: 0, b: 0, c: 0},
|
||||
);
|
||||
assert_eq!(
|
||||
Enum3::<Runtime>::default(),
|
||||
Enum3::<Runtime>::VariantUnit,
|
||||
);
|
||||
|
||||
assert!(variant_0 != variant_0_bis);
|
||||
assert!(variant_1 != variant_1_bis);
|
||||
assert!(variant_0 != variant_1);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
trait Config {
|
||||
type C;
|
||||
}
|
||||
|
||||
#[derive(frame_support::DefaultNoBound)]
|
||||
struct Foo<T: Config> {
|
||||
c: T::C,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,7 @@
|
||||
error[E0277]: the trait bound `<T as Config>::C: std::default::Default` is not satisfied
|
||||
--> $DIR/default.rs:7:2
|
||||
|
|
||||
7 | c: T::C,
|
||||
| ^ the trait `std::default::Default` is not implemented for `<T as Config>::C`
|
||||
|
|
||||
= note: required by `std::default::Default::default`
|
||||
Reference in New Issue
Block a user