#![allow(unused_imports)]
use super :: *;
use variadic_from ::exposed :: *;
use variadic_from_meta ::VariadicFrom;
#[ test ]
fn test_named_struct_1_field()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Test1
{
a: i32,
}
let x = Test1 ::from1(10);
assert_eq!(x, Test1 { a: 10 });
let x = Test1 ::from(20);
assert_eq!(x, Test1 { a: 20 });
}
#[ test ]
fn test_tuple_struct_1_field()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Test2(i32);
let x = Test2 ::from1(10);
assert_eq!(x, Test2(10));
let x = Test2 ::from(20);
assert_eq!(x, Test2(20));
}
#[ test ]
fn test_named_struct_2_identical_fields()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Test3
{
a: i32,
b: i32,
}
let x = Test3 ::from2(10, 20);
assert_eq!(x, Test3 { a: 10, b: 20 });
let x = Test3 ::from((30, 40));
assert_eq!(x, Test3 { a: 30, b: 40 });
let x = Test3 ::from1(50);
assert_eq!(x, Test3 { a: 50, b: 50 });
}
#[ test ]
fn test_tuple_struct_2_identical_fields()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Test4(i32, i32);
let x = Test4 ::from2(10, 20);
assert_eq!(x, Test4(10, 20));
let x = Test4 ::from((30, 40));
assert_eq!(x, Test4(30, 40));
let x = Test4 ::from1(50);
assert_eq!(x, Test4(50, 50));
}
#[ test ]
fn test_named_struct_2_different_fields()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Test5
{
a: i32,
b: String,
}
let x = Test5 ::from2(10, "hello".to_string());
assert_eq!(
x,
Test5 {
a: 10,
b: "hello".to_string()
}
);
let x = Test5 ::from((20, "world".to_string()));
assert_eq!(
x,
Test5 {
a: 20,
b: "world".to_string()
}
);
}
#[ test ]
fn test_tuple_struct_2_different_fields()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Test6(i32, String);
let x = Test6 ::from2(10, "hello".to_string());
assert_eq!(x, Test6(10, "hello".to_string()));
let x = Test6 ::from((20, "world".to_string()));
assert_eq!(x, Test6(20, "world".to_string()));
}
#[ test ]
fn test_named_struct_3_identical_fields()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Test7
{
a: i32,
b: i32,
c: i32,
}
let x = Test7 ::from3(10, 20, 30);
assert_eq!(x, Test7 { a: 10, b: 20, c: 30 });
let x = Test7 ::from((40, 50, 60));
assert_eq!(x, Test7 { a: 40, b: 50, c: 60 });
let x = Test7 ::from1(70);
assert_eq!(x, Test7 { a: 70, b: 70, c: 70 });
let x = Test7 ::from2(80, 90);
assert_eq!(x, Test7 { a: 80, b: 90, c: 90 });
}
#[ test ]
fn test_tuple_struct_3_identical_fields()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Test8(i32, i32, i32);
let x = Test8 ::from3(10, 20, 30);
assert_eq!(x, Test8(10, 20, 30));
let x = Test8(40, 50, 60);
assert_eq!(x, Test8(40, 50, 60));
let x = Test8 ::from1(70);
assert_eq!(x, Test8(70, 70, 70));
let x = Test8 ::from2(80, 90);
assert_eq!(x, Test8(80, 90, 90));
}
#[ test ]
fn test_named_struct_3_fields_last_different()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Test9
{
a: i32,
b: i32,
c: String,
}
let x = Test9 ::from3(10, 20, "hello".to_string().clone());
assert_eq!(
x,
Test9 {
a: 10,
b: 20,
c: "hello".to_string()
}
);
let x = Test9 ::from((30, 40, "world".to_string().clone()));
assert_eq!(
x,
Test9 {
a: 30,
b: 40,
c: "world".to_string()
}
);
}
#[ test ]
fn test_tuple_struct_3_fields_last_different()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Test10(i32, i32, String);
let x = Test10 ::from3(10, 20, "hello".to_string().clone());
assert_eq!(x, Test10(10, 20, "hello".to_string()));
let x = Test10 ::from((30, 40, "world".to_string().clone()));
assert_eq!(x, Test10(30, 40, "world".to_string()));
}
#[ test ]
fn test_named_struct_3_fields_last_two_identical()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Test11
{
a: i32,
b: String,
c: String,
}
let x = Test11 ::from3(10, "a".to_string().clone(), "b".to_string().clone());
assert_eq!(
x,
Test11 {
a: 10,
b: "a".to_string(),
c: "b".to_string()
}
);
let x = Test11 ::from((20, "c".to_string().clone(), "d".to_string().clone()));
assert_eq!(
x,
Test11 {
a: 20,
b: "c".to_string(),
c: "d".to_string()
}
);
let x = Test11 ::from2(30, "e".to_string().clone());
assert_eq!(
x,
Test11 {
a: 30,
b: "e".to_string(),
c: "e".to_string()
}
);
}
#[ test ]
fn test_tuple_struct_3_fields_last_two_identical()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Test12(i32, String, String);
let x = Test12 ::from3(10, "a".to_string().clone(), "b".to_string().clone());
assert_eq!(x, Test12(10, "a".to_string(), "b".to_string()));
let x = Test12 ::from((20, "c".to_string().clone(), "d".to_string().clone()));
assert_eq!(x, Test12(20, "c".to_string(), "d".to_string()));
let x = Test12 ::from2(30, "e".to_string().clone());
assert_eq!(x, Test12(30, "e".to_string(), "e".to_string()));
}
#[ test ]
fn test_named_struct_1_generic_field()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Test13< T >
where
T: Clone + core ::fmt ::Debug + PartialEq,
{
a: T,
}
let x = Test13 ::from1(10);
assert_eq!(x, Test13 { a: 10 });
let x = Test13 ::from(20);
assert_eq!(x, Test13 { a: 20 });
let x = Test13 ::from1("hello".to_string());
assert_eq!(x, Test13 { a: "hello".to_string() });
}
#[ test ]
fn test_tuple_struct_2_generic_fields()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Test14< T, U >
where
T: Clone + core ::fmt ::Debug + PartialEq,
U: Clone + core ::fmt ::Debug + PartialEq,
(T, U) : Into< (T, U) >,
{
a: T,
b: U,
}
let x = Test14 ::from2(10, "hello");
assert_eq!(x, Test14 { a: 10, b: "hello" });
let x = Test14 ::from((20, "world"));
assert_eq!(x, Test14 { a: 20, b: "world" });
}