#![ allow( unused_imports ) ]
use variadic_from ::exposed ::*;
use variadic_from_meta ::VariadicFrom;
#[ test ]
fn test_conformance_1_field_struct()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct OneField
{
value: i32,
}
let x = OneField ::from1( 42 );
assert_eq!( x, OneField { value: 42 } );
let x = OneField ::from( 100 );
assert_eq!( x, OneField { value: 100 } );
}
#[ test ]
fn test_conformance_2_field_different_types()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct TwoFields
{
id: i32,
name: String,
}
let x = TwoFields ::from2( 1, "Alice".to_string() );
assert_eq!
(
x,
TwoFields
{
id: 1,
name: "Alice".to_string()
}
);
let x = TwoFields ::from( ( 2, "Bob".to_string() ) );
assert_eq!
(
x,
TwoFields
{
id: 2,
name: "Bob".to_string()
}
);
}
#[ test ]
fn test_conformance_3_field_same_type()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Point3D( i32, i32, i32 );
let p = Point3D ::from3( 1, 2, 3 );
assert_eq!( p, Point3D( 1, 2, 3 ) );
let p = Point3D ::from( ( 4, 5, 6 ) );
assert_eq!( p, Point3D( 4, 5, 6 ) );
let p = Point3D ::from1( 10 );
assert_eq!( p, Point3D( 10, 10, 10 ) );
let p = Point3D ::from2( 20, 30 );
assert_eq!( p, Point3D( 20, 30, 30 ) );
}
#[ test ]
fn test_conformance_from_macro()
{
#[ derive( VariadicFrom, Debug, PartialEq, Default ) ]
struct TwoFieldsSame
{
x: i32,
y: i32,
}
let p: TwoFieldsSame = from!();
assert_eq!( p, TwoFieldsSame { x: 0, y: 0 } );
let p: TwoFieldsSame = from!( 5 );
assert_eq!( p, TwoFieldsSame { x: 5, y: 5 } );
let p: TwoFieldsSame = from!( 10, 20 );
assert_eq!( p, TwoFieldsSame { x: 10, y: 20 } );
}
#[ test ]
fn test_conformance_tuple_conversion()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Pair( i32, String );
let p = Pair ::from( ( 42, "answer".to_string() ) );
assert_eq!( p, Pair( 42, "answer".to_string() ) );
let p: Pair = ( 100, "century".to_string() ).into();
assert_eq!( p, Pair( 100, "century".to_string() ) );
}
#[ test ]
fn test_conformance_generics()
{
#[ derive( VariadicFrom, Debug, PartialEq ) ]
struct Generic< T, U >
where
T: Clone + core ::fmt ::Debug + PartialEq,
U: Clone + core ::fmt ::Debug + PartialEq,
{
first: T,
second: U,
}
let g = Generic ::from2( 42i32, "test".to_string() );
assert_eq!
(
g,
Generic
{
first: 42,
second: "test".to_string()
}
);
let g = Generic ::from( ( 100i32, "hundred".to_string() ) );
assert_eq!
(
g,
Generic
{
first: 100,
second: "hundred".to_string()
}
);
let g = Generic ::from2( "hello", vec![ 1, 2, 3 ] );
assert_eq!
(
g,
Generic
{
first: "hello",
second: vec![ 1, 2, 3 ]
}
);
}