use component_model ::ComponentModel;
use component_model_types ::Assign;
#[ derive( Default, ComponentModel, PartialEq, Debug ) ]
struct TestConfig
{
host: String,
port: i32,
enabled: bool,
}
#[ test ]
fn test_field_specific_assignment_methods()
{
let mut config = TestConfig ::default();
config.host_set( "localhost".to_string() );
config.port_set( 8080i32 );
config.enabled_set( true );
assert_eq!( config.host, "localhost" );
assert_eq!( config.port, 8080 );
assert!( config.enabled );
}
#[ test ]
fn test_field_specific_impute_methods()
{
let config = TestConfig ::default()
.host_with( "api.example.com".to_string() )
.port_with( 3000i32 )
.enabled_with( false );
assert_eq!( config.host, "api.example.com" );
assert_eq!( config.port, 3000 );
assert!( !config.enabled );
}
#[ test ]
fn test_explicit_assign_trait_still_works()
{
let mut config = TestConfig ::default();
Assign :: < String, String > ::assign( &mut config, "test".to_string() );
Assign :: < i32, i32 > ::assign( &mut config, 1234i32 );
Assign :: < bool, bool > ::assign( &mut config, true );
assert_eq!( config.host, "test" );
assert_eq!( config.port, 1234 );
assert!( config.enabled );
}
#[ derive( Default, ComponentModel, PartialEq, Debug ) ]
struct MultiBoolConfig
{
enabled: bool,
debug: bool,
verbose: bool,
}
#[ test ]
fn test_multiple_bool_fields_with_field_specific_methods()
{
let mut config = MultiBoolConfig ::default();
config.enabled_set( true );
config.debug_set( false );
config.verbose_set( true );
assert!( config.enabled );
assert!( !config.debug );
assert!( config.verbose );
}
#[ test ]
fn test_multiple_bool_fields_fluent_pattern()
{
let config = MultiBoolConfig ::default()
.enabled_with( true )
.debug_with( false )
.verbose_with( true );
assert!( config.enabled );
assert!( !config.debug );
assert!( config.verbose );
}