use component_model ::ComponentModel;
#[ derive( ComponentModel, Debug, PartialEq ) ]
#[ allow( clippy ::struct_excessive_bools ) ] struct MultipleBoolsDetailed
{
enabled: bool,
visible: bool,
active: bool,
debug: bool,
}
#[ test ]
fn test_multiple_identical_bool_fields()
{
let mut config = MultipleBoolsDetailed {
enabled: false,
visible: false,
active: false,
debug: false,
};
config.enabled_set( true );
config.visible_set( false );
config.active_set( true );
config.debug_set( false );
assert!( config.enabled );
assert!( !config.visible );
assert!( config.active );
assert!( !config.debug );
}
#[ test ]
fn test_multiple_bools_fluent()
{
let config = MultipleBoolsDetailed {
enabled: false,
visible: false,
active: false,
debug: false,
}
.enabled_with( true )
.visible_with( true )
.active_with( false )
.debug_with( true );
assert!( config.enabled );
assert!( config.visible );
assert!( !config.active );
assert!( config.debug );
}
#[ derive( ComponentModel, Debug ) ]
struct VeryLongFieldNames
{
this_is_a_very_long_field_name_that_tests_method_generation: String,
another_extremely_long_field_name_for_testing_purposes: i32,
}
#[ test ]
fn test_very_long_field_names()
{
let mut config = VeryLongFieldNames {
this_is_a_very_long_field_name_that_tests_method_generation: String ::new(),
another_extremely_long_field_name_for_testing_purposes: 0,
};
config.this_is_a_very_long_field_name_that_tests_method_generation_set( "long_test".to_string() );
config.another_extremely_long_field_name_for_testing_purposes_set( 999i32 );
assert_eq!( config.this_is_a_very_long_field_name_that_tests_method_generation, "long_test" );
assert_eq!( config.another_extremely_long_field_name_for_testing_purposes, 999 );
}
#[ derive( ComponentModel, Debug, PartialEq ) ]
struct MixedUsage
{
name: String,
count: i32,
enabled: bool,
}
#[ test ]
fn test_mixed_assign_and_impute()
{
let mut config = MixedUsage { name: String ::new(), count: 0, enabled: false };
config.name_set( "mixed".to_string() );
let config = config
.count_with( 42i32 )
.enabled_with( true );
assert_eq!( config.name, "mixed" );
assert_eq!( config.count, 42 );
assert!( config.enabled );
}
#[ derive( ComponentModel, Debug ) ]
struct NestedGenerics
{
data: Vec< Option< String > >,
mapping: std ::collections ::HashMap< String, Vec< i32 > >,
}
#[ test ]
fn test_nested_generic_types()
{
let mut config = NestedGenerics {
data: Vec ::new(),
mapping: std ::collections ::HashMap ::new(),
};
config.data_set( vec![ Some( "nested".to_string() ), None ] );
config.mapping_set( {
let mut map = std ::collections ::HashMap ::new();
map.insert( "key".to_string(), vec![ 1, 2, 3 ] );
map
} );
assert_eq!( config.data.len(), 2 );
assert_eq!( config.data[ 0 ], Some( "nested".to_string() ) );
assert_eq!( config.data[ 1 ], None );
assert_eq!( config.mapping.get( "key" ), Some( &vec![ 1, 2, 3 ] ) );
}