component_model 0.16.0

Revolutionary type-safe component assignment for Rust. Build complex objects with zero boilerplate using derive macros and type-driven field setting. Perfect for configuration builders, fluent APIs, and object composition patterns.
Documentation
//! Edge cases and boundary condition tests
//!
//! ## Test Matrix for Edge Cases
//!
//! | ID   | Test Case                       | Expected Output                    |
//! |------|---------------------------------|------------------------------------|
//! | T5.3 | Multiple identical bool fields | Each gets own specific method      |
//! | T5.4 | Very long field names          | Method names generated correctly   |
//! | T5.6 | Mixed assign/impute usage      | Mixed patterns work correctly      |
//! | T5.8 | Nested generic types           | Complex nested types supported     |
//!
//! Note: Unit structs and tuple structs are not supported (requires named fields)

use component_model ::ComponentModel;

// Note: Unit structs are not supported by ComponentModel (requires named fields)
// This is expected behavior as the macro needs fields to generate methods for

// Test multiple identical boolean fields (each should get specific methods)
/// Test multiple bool fields each get specific methods
/// Test Combination: T5.3
#[ derive( ComponentModel, Debug, PartialEq ) ]
#[ allow( clippy ::struct_excessive_bools ) ]  // Needed for testing multiple bool fields
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,
 };
  
  // Each boolean field should have its own specific method
  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 fluent pattern with multiple bool fields
/// Test Combination: T5.3
#[ 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 );
}

// Test very long field names
/// Test very long field names generate correct method names
/// Test Combination: T5.4
#[ 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,
 };
  
  // Methods should be generated correctly even for very long names
  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 );
}

// Test mixed assignment and impute usage
/// Test mixed usage of assign and impute methods
/// Test Combination: T5.6 (additional)
#[ 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 };
  
  // Mix assignment and fluent patterns
  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 );
}

// Note: Generic types with complex bounds are not yet supported
// This is a limitation of the current implementation

// Test nested generic types
/// Test nested generic types work correctly
/// Test Combination: T5.8 (additional)
#[ 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 ] ) );
}