#![ allow( dead_code ) ]
use former::Former;
#[ derive( Debug, PartialEq, Former ) ]
pub struct SimpleConfig
{
host : String,
port : u16,
}
#[ derive( Debug, PartialEq, Former ) ]
pub struct ConfigWithOptional
{
host : String,
port : u16,
description : Option< String >,
}
#[ test ]
fn test_simple_former_usage()
{
let config = SimpleConfig::former()
.host( "localhost".to_string() )
.port( 8080_u16 )
.form();
assert_eq!( config.host, "localhost" );
assert_eq!( config.port, 8080 );
}
#[ test ]
fn test_former_with_optional()
{
let config = ConfigWithOptional::former()
.host( "localhost".to_string() )
.port( 3000_u16 )
.description( "Test server".to_string() )
.form();
assert_eq!( config.host, "localhost" );
assert_eq!( config.port, 3000 );
assert_eq!( config.description, Some( "Test server".to_string() ) );
}
#[ derive( Debug, PartialEq, Former ) ]
pub struct Database
{
connection_string : String,
timeout : u32,
}
#[ derive( Debug, PartialEq, Former ) ]
pub struct Application
{
name : String,
#[ subform_scalar ]
database : Database,
}
#[ test ]
fn test_former_with_subform()
{
let app = Application::former()
.name( "MyApp".to_string() )
.database()
.connection_string( "postgres://localhost".to_string() )
.timeout( 30_u32 )
.form()
.form();
assert_eq!( app.name, "MyApp" );
assert_eq!( app.database.connection_string, "postgres://localhost" );
assert_eq!( app.database.timeout, 30 );
}