Skip to content

Commit 752497c

Browse files
committed
former : tests purpose
1 parent 09f577f commit 752497c

11 files changed

+183
-133
lines changed

module/core/former/plan.md

Lines changed: 54 additions & 12 deletions
Large diffs are not rendered by default.

module/core/former/tests/inc/enum_unnamed_tests/generics_in_tuple_variant_only_test.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
//! Purpose: Provides shared test assertions and logic for verifying the constructors generated
22
//! by `#[derive(Former)]` for enums with unnamed (tuple) variants that have shared generic
3-
//! parameters and bounds, using the default subform behavior. This file is included by both
4-
//! `generics_in_tuple_variant_tuple_derive.rs` and `generics_in_tuple_variant_tuple_manual.rs`.
3+
//! parameters and bounds. This file is included by both `generics_in_tuple_variant_tuple_derive.rs`
4+
//! and `generics_in_tuple_variant_tuple_manual.rs`. It also contains tests for unit variants
5+
//! within a generic enum, included by `generics_in_tuple_variant_unit_derive.rs` and
6+
//! `generics_in_tuple_variant_unit_manual.rs`.
57
//!
68
//! Coverage:
79
//! - Rule 3d (Tuple + Single-Field + Default -> Subform): Tests static method `EnumOuter::<X>::variant()`.
810
//! - Rule 4b (Option 2 Logic): Tests the use of subformer methods and `.form()`.
11+
//! - Rule 3a (Unit + Default): Tests static method `EnumOuter::<X>::other_variant()`.
12+
//! - Rule 1a (Unit + `#[scalar]`): Tests static method `EnumOuter::<X>::other_variant()` (as default for unit is scalar).
913
//!
1014
//! Test Relevance/Acceptance Criteria:
1115
//! - Defines dummy bounds (`BoundA`, `BoundB`) and concrete types (`TypeForT`, `TypeForU`) that satisfy them.
12-
//! - Defines test functions (`basic_construction`, `construction_with_bounds`) that invoke the static method
13-
//! `EnumOuter::<X>::variant()` provided by the including file (either derived or manual).
14-
//! - This constructor returns a subformer (`InnerGenericFormer<X>`).
15-
//! - The tests use the subformer setter (`.inner_field()`) and `.form()` to build the final enum instance.
16+
//! - Defines test functions (`basic_construction`, `construction_with_bounds`, `unit_variant_generics`) that invoke the static methods
17+
//! (`EnumOuter::<X>::variant()`, `EnumOuter::<X>::other_variant()`) provided by the including file (either derived or manual).
18+
//! - For tuple variants, the constructor returns a subformer (`InnerGenericFormer<X>`). The tests use the subformer setter (`.inner_field()`) and `.form()` to build the final enum instance.
19+
//! - For unit variants, the constructor directly returns the enum instance.
1620
//! - Asserts that the resulting `EnumOuter` enum instances are equal to the expected variants
17-
//! (`EnumOuter::Variant(InnerGeneric { ... })`), confirming correct handling of shared generics and bounds.
18-
//! Test logic for enum variants with independent generic parameters.
19-
//!
20-
//! Purpose:
21-
//! - Define `EnumG5<T: BoundA>` and `InnerG5<U: BoundB>` with independent generics.
22-
//! - Apply `#[derive(Former)]` to both the enum and the inner struct.
23-
//! - Use the included `_only_test.rs` file to verify that the macro-generated code
24-
//! correctly handles the distinct generics `T` and `U` (instantiated as `TypeForU`
25-
//! in the variant) and their respective bounds.
26-
//!
27-
// File: module/core/former/tests/inc/former_enum_tests/generics_in_tuple_variant_only_test.rs
21+
//! (`EnumOuter::Variant(InnerGeneric { ... })`, `EnumOuter::OtherVariant`), confirming correct handling of shared generics and bounds for both tuple and unit variants.
22+
//! - Verifies that the bounds (`Copy`, `Debug`, `Default`, `PartialEq`) are correctly handled by using types that satisfy them.
2823
#[ allow( unused_imports ) ]
2924
use super::*; // Should import EnumOuter and InnerGeneric from either the manual or derive file
3025
use std::fmt::Debug; // Removed redundant import (E0252 fix)
@@ -76,6 +71,22 @@ fn construction_with_bounds()
7671
assert_eq!( got, expected );
7772
}
7873

74+
#[ test ]
75+
fn unit_variant_generics()
76+
{
77+
// Test the unit variant constructor within the generic enum
78+
// Uses a concrete type that satisfies the enum's bounds
79+
#[ derive( Debug, Copy, Clone, PartialEq ) ]
80+
struct MyType;
81+
impl Default for MyType { fn default() -> Self { Self } } // Added Default for EnumOuter bounds
82+
83+
let got = EnumOuter::< MyType >::other_variant(); // Assuming this constructor exists
84+
85+
let expected = EnumOuter::< MyType >::OtherVariant; // Assuming this variant exists
86+
87+
assert_eq!( got, expected );
88+
}
89+
7990
// Optional: Add a test that *should* fail compilation if bounds are not met.
8091
// This requires a compile-fail test setup (like trybuild), which is outside
8192
// the scope of just adding files here.

module/core/former/tests/inc/enum_unnamed_tests/generics_in_tuple_variant_tuple_derive.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
//!
55
//! Coverage:
66
//! - Rule 3d (Tuple + Single-Field + Default -> Subform): Verifies `EnumOuter::<X>::variant() -> InnerGenericFormer<X>`.
7-
//! - Rule 4a (#[standalone_constructors]): Verifies generation of top-level constructor functions (though not explicitly tested in `_only_test.rs`).
7+
//! - Rule 4b (Option 2 Logic): Verifies the use of the subformer returned by the variant constructor.
88
//!
99
//! Test Relevance/Acceptance Criteria:
10-
//! - Defines a generic enum `EnumOuter<X: Copy>` with a single-field tuple variant `Variant(InnerGeneric<X>)`.
11-
//! - The inner struct `InnerGeneric<T: Debug + Copy>` has its own generic `T` and bounds, and is instantiated with the enum's generic `X` in the variant.
10+
//! - Defines a generic enum `EnumOuter<X: Copy + Debug + Default + PartialEq>` with a single-field tuple variant `Variant(InnerGeneric<X>)`.
11+
//! - The inner struct `InnerGeneric<T: Debug + Copy + Default + PartialEq>` has its own generic `T` and bounds, and is instantiated with the enum's generic `X` in the variant.
1212
//! - The enum has `#[derive(Former)]` and `#[debug]`.
13-
//! - Relies on the derived static method `EnumOuter::<X>::variant()` defined in `generics_in_tuple_variant_only_test.rs`.
13+
//! - Relies on the derived static method `EnumOuter::<X>::variant()` provided by this file (via `include!`).
1414
//! - Asserts that this constructor returns the expected subformer (`InnerGenericFormer<X>`) and that using the subformer's setter (`.inner_field()`) and `.form()` results in the correct `EnumOuter` enum instance.
15-
//! - Verifies that the bounds (`Copy`, `Debug`, `PartialEq`, `Default`) are correctly handled by using types that satisfy them.
16-
// File: module/core/former/tests/inc/former_enum_tests/unnamed_tests/generics_in_tuple_variant_tuple_derive.rs
15+
//! - Verifies that the bounds (`Copy`, `Debug`, `Default`, `PartialEq`) are correctly handled by using types that satisfy them.
1716
#[ allow( unused_imports ) ]
1817
use super::*; // Imports testing infrastructure and potentially other common items
1918
use std::fmt::Debug; // Import Debug trait for bounds
@@ -22,13 +21,13 @@ use std::marker::PhantomData; // Import PhantomData
2221
// --- Inner Struct Definition with Bounds ---
2322
// Needs to derive Former for the enum's derive to work correctly for subforming.
2423
#[derive(Debug, PartialEq, Clone, Copy, former::Former)] // Added Former derive
25-
pub struct InnerGeneric< T : Debug + Copy > // Added Copy bound here too
24+
pub struct InnerGeneric< T : Debug + Copy + Default + PartialEq > // Added Copy bound here too
2625
{
2726
pub inner_field : T,
2827
}
2928

3029
// Implement Into manually for testing the constructor signature
31-
impl< T : Debug + Copy > From< T > for InnerGeneric< T >
30+
impl< T : Debug + Copy + Default + PartialEq > From< T > for InnerGeneric< T >
3231
{
3332
fn from( data : T ) -> Self { Self { inner_field : data } }
3433
}
@@ -37,7 +36,7 @@ impl< T : Debug + Copy > From< T > for InnerGeneric< T >
3736
// Apply Former derive here. This is what we are testing.
3837
#[derive(Debug, PartialEq, former::Former)]
3938
#[debug]
40-
pub enum EnumOuter< X : Copy > // Enum bound: Copy
39+
pub enum EnumOuter< X : Copy + Debug + Default + PartialEq > // Enum bound: Copy
4140
{
4241
// --- Tuple Variant with Generics ---
4342
Variant( InnerGeneric< X > ), // Inner type uses X, which must satisfy InnerGeneric's bounds (Debug + Copy)

module/core/former/tests/inc/enum_unnamed_tests/generics_in_tuple_variant_tuple_manual.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,13 @@
88
//! - Rule 4b (Option 2 Logic): Manual implementation of `FormingEnd` for the variant end type.
99
//!
1010
//! Test Relevance/Acceptance Criteria:
11-
//! - Defines a generic enum `EnumOuter<X: Copy>` with a single-field tuple variant `Variant(InnerGeneric<X>)`.
11+
//! - Defines a generic enum `EnumOuter<X: Copy + Debug + Default + PartialEq>` with a single-field tuple variant `Variant(InnerGeneric<X>)`.
1212
//! - The inner struct `InnerGeneric<T: Debug + Copy + Default + PartialEq>` has its own generic `T` and bounds,
1313
//! and is instantiated with the enum's generic `X` in the variant.
1414
//! - Manually implements a static method `EnumOuter::variant()` that mirrors the expected generated code for a subform variant.
1515
//! - Manually implements `FormingEnd` for the end type associated with the variant subformer.
1616
//! - This file is included by `generics_in_tuple_variant_only_test.rs` to provide the manual implementations
1717
//! that the shared tests compare against.
18-
//! Manual implementation for testing enum variants with independent generic parameters.
19-
//!
20-
//! Purpose:
21-
//! - Define an enum `EnumG5<T: BoundA>` where `T` is the enum's generic.
22-
//! - Define an inner struct `InnerG5<U: BoundB>` where `U` is the inner struct's generic.
23-
//! - Define a variant `V1(InnerG5<TypeForU>, PhantomData<T>)` where `U` is instantiated with a specific
24-
//! concrete type (`TypeForU`) that satisfies `BoundB`, while `T` remains generic for the enum.
25-
//! `PhantomData<T>` is added to ensure the `T` parameter is used.
26-
//! - Manually implement the `Former` logic (static method `v1`, `End` struct, `impl FormingEnd`)
27-
//! to ensure the distinct generics `T` and `U` (instantiated as `TypeForU`) and their bounds
28-
//! are handled correctly. The static method `v1` should be generic over `T`, while the
29-
//! returned former and the `End` logic operate on the concrete `InnerG5<TypeForU>`.
30-
//!
31-
//! This setup tests the macro's ability to handle scenarios where the enum's state (`T`)
32-
//! is independent of the specific type (`TypeForU`) being formed within one of its variants.
33-
//!
34-
// File: module/core/former/tests/inc/former_enum_tests/unnamed_tests/generics_in_tuple_variant_tuple_manual.rs
3518
#[ allow( unused_imports ) ]
3619
use super::*; // Imports testing infrastructure and potentially other common items
3720
use std::fmt::Debug; // Import Debug trait for bounds

module/core/former/tests/inc/enum_unnamed_tests/generics_independent_tuple_derive.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,8 @@
1010
//! - Defines a generic enum `EnumG5<T: BoundA>` with a single-field tuple variant `V1(InnerG5<TypeForU>, PhantomData<T>)`.
1111
//! - The inner struct `InnerG5<U: BoundB>` has its own generic `U` and bound `BoundB`, and is instantiated with a concrete `TypeForU` in the variant.
1212
//! - The variant `V1` is annotated with `#[scalar]`. The enum has `#[derive(Former)]`.
13-
//! - Relies on the derived static method `EnumG5::<TypeForT>::v1()` defined in `generics_independent_tuple_only_test.rs`.
13+
//! - Relies on the derived static method `EnumG5::<TypeForT>::v_1()` defined in `generics_independent_tuple_only_test.rs`.
1414
//! - Asserts that this constructor produces the correct `EnumG5` enum instance by comparing with a manually constructed variant, confirming correct handling of independent generics and the `#[scalar]` attribute.
15-
//! Derive-based test for enum variants with independent generic parameters.
16-
//!
17-
//! Purpose:
18-
//! - Define `EnumG5<T: BoundA>` and `InnerG5<U: BoundB>` with independent generics.
19-
//! - Apply `#[derive(Former)]` to both the enum and the inner struct.
20-
//! - Use the included `_only_test.rs` file to verify that the macro-generated code
21-
//! correctly handles the distinct generics `T` and `U` (instantiated as `TypeForU`
22-
//! in the variant) and their respective bounds.
23-
//!
24-
// File: module/core/former/tests/inc/former_enum_tests/generics_independent_tuple_derive.rs
2515
use super::*; // Imports testing infrastructure and potentially other common items
2616
use std::marker::PhantomData;
2717

module/core/former/tests/inc/enum_unnamed_tests/generics_independent_tuple_manual.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//!
55
//! Coverage:
66
//! - Rule 1d (Tuple + Single-Field + `#[scalar]` -> Scalar): Manual implementation of static method `EnumG5::v_1()`.
7-
//! - Rule 4a (#[standalone_constructors]): Not applicable to this manual implementation file.
87
//! - Rule 4b (Option 2 Logic): Manual implementation of `FormingEnd` for the variant end type.
98
//!
109
//! Test Relevance/Acceptance Criteria:
@@ -13,23 +12,6 @@
1312
//! - Manually implements `FormingEnd` for the end type associated with the variant subformer.
1413
//! - This file is included by `generics_independent_tuple_only_test.rs` to provide the manual implementations
1514
//! that the shared tests compare against.
16-
//! Manual implementation for testing enum variants with independent generic parameters.
17-
//!
18-
//! Purpose:
19-
//! - Define an enum `EnumG5<T: BoundA>` where `T` is the enum's generic.
20-
//! - Define an inner struct `InnerG5<U: BoundB>` where `U` is the inner struct's generic.
21-
//! - Define a variant `V1(InnerG5<TypeForU>, PhantomData<T>)` where `U` is instantiated with a specific
22-
//! concrete type (`TypeForU`) that satisfies `BoundB`, while `T` remains generic for the enum.
23-
//! `PhantomData<T>` is added to ensure the `T` parameter is used.
24-
//! - Manually implement the `Former` logic (static method `v1`, `End` struct, `impl FormingEnd`)
25-
//! to ensure the distinct generics `T` and `U` (instantiated as `TypeForU`) and their bounds
26-
//! are handled correctly. The static method `v1` should be generic over `T`, while the
27-
//! returned former and the `End` logic operate on the concrete `InnerG5<TypeForU>`.
28-
//!
29-
//! This setup tests the macro's ability to handle scenarios where the enum's state (`T`)
30-
//! is independent of the specific type (`TypeForU`) being formed within one of its variants.
31-
//!
32-
// File: module/core/former/tests/inc/former_enum_tests/generics_independent_tuple_manual.rs
3315
use super::*; // Imports testing infrastructure and potentially other common items
3416
use std::marker::PhantomData;
3517
use former_types::

module/core/former/tests/inc/enum_unnamed_tests/generics_independent_tuple_only_test.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! This file is included by both `generics_independent_tuple_derive.rs` and `generics_independent_tuple_manual.rs`.
55
//!
66
//! Coverage:
7-
//! - Rule 1d (Tuple + Single-Field + `#[scalar]` -> Scalar): Tests static method `EnumG5::<T>::v1()`.
7+
//! - Rule 1d (Tuple + Single-Field + `#[scalar]` -> Scalar): Tests static method `EnumG5::<T>::v_1()`.
88
//! - Rule 4b (Option 2 Logic): Tests the use of subformer methods and `.form()`.
99
//!
1010
//! Test Relevance/Acceptance Criteria:
@@ -15,16 +15,6 @@
1515
//! - The tests use the subformer setter (`._0()`) and `.form()` to build the final enum instance.
1616
//! - Asserts that the resulting `EnumG5` enum instances are equal to the expected variants
1717
//! (`EnumG5::V1(InnerG5 { ... }, PhantomData)`), confirming correct handling of independent generics and the `#[scalar]` attribute.
18-
//! Test logic for enum variants with independent generic parameters.
19-
//!
20-
//! Purpose:
21-
//! - Define `EnumG5<T: BoundA>` and `InnerG5<U: BoundB>` with independent generics.
22-
//! - Apply `#[derive(Former)]` to both the enum and the inner struct.
23-
//! - Use the included `_only_test.rs` file to verify that the macro-generated code
24-
//! correctly handles the distinct generics `T` and `U` (instantiated as `TypeForU`
25-
//! in the variant) and their respective bounds.
26-
//!
27-
// File: module/core/former/tests/inc/former_enum_tests/generics_independent_tuple_only_test.rs
2818
use super::*; // Imports items from the parent file (either manual or derive)
2919
// Define dummy bounds for testing purposes
3020
pub trait BoundA : core::fmt::Debug + Default + Clone + PartialEq {}

module/core/former/tests/inc/enum_unnamed_tests/generics_shared_tuple_derive.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
// File: module/core/former/tests/inc/former_enum_tests/generics_shared_tuple_derive.rs
1+
//! Purpose: Tests the `#[derive(Former)]` macro's generation of constructors for unnamed (tuple)
2+
//! variants with shared generic parameters and bounds, using the default subform behavior.
3+
//! This file focuses on verifying the derive-based implementation.
4+
//!
5+
//! Coverage:
6+
//! - Rule 3d (Tuple + Single-Field + Default -> Subform): Verifies `EnumG3::<T>::v1() -> InnerG3Former<T>`.
7+
//! - Rule 4b (Option 2 Logic): Verifies the use of the subformer returned by the variant constructor.
8+
//!
9+
//! Test Relevance/Acceptance Criteria:
10+
//! - Defines a generic enum `EnumG3<T: BoundA + BoundB>` with a single-field tuple variant `V1(InnerG3<T>)`.
11+
//! - The inner struct `InnerG3<T: BoundB>` has its own generic `T` and bound `BoundB`, and is instantiated with the enum's generic `T` in the variant.
12+
//! - The enum has `#[derive(Former)]`.
13+
//! - Relies on the derived static method `EnumG3::<T>::v_1()` provided by this file (via `include!`).
14+
//! - Asserts that this constructor returns the expected subformer (`InnerG3Former<T>`) and that using the subformer's setter (`.inner_field()`) and `.form()` results in the correct `EnumG3` enum instance.
15+
//! - Verifies that the bounds (`BoundA`, `BoundB`) are correctly handled by using a type that satisfies both.
16+
#[ allow( unused_imports ) ]
217
use super::*; // Imports testing infrastructure and potentially other common items
318

419
// --- Dummy Bounds ---

module/core/former/tests/inc/enum_unnamed_tests/generics_shared_tuple_manual.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
// File: module/core/former/tests/inc/former_enum_tests/generics_shared_tuple_manual.rs
1+
//! Purpose: Provides a manual implementation of constructors and `FormingEnd` for an enum
2+
//! with unnamed (tuple) variants that have shared generic parameters and bounds, using the
3+
//! default subform behavior, to serve as a reference for verifying the `#[derive(Former)]`
4+
//! macro's behavior.
5+
//!
6+
//! Coverage:
7+
//! - Rule 3d (Tuple + Single-Field + Default -> Subform): Manual implementation of static method `EnumG3::v_1()`.
8+
//! - Rule 4b (Option 2 Logic): Manual implementation of `FormingEnd` for the variant end type.
9+
//!
10+
//! Test Relevance/Acceptance Criteria:
11+
//! - Defines a generic enum `EnumG3<T: BoundA + BoundB>` with a single-field tuple variant `V1(InnerG3<T>)`.
12+
//! - The inner struct `InnerG3<T: BoundB>` has its own generic `T` and bound `BoundB`, and is instantiated with the enum's generic `T` in the variant.
13+
//! - Manually implements a static method `EnumG3::v_1()` that mirrors the expected generated code for a subform variant.
14+
//! - Manually implements `FormingEnd` for the end type associated with the variant subformer.
15+
//! - This file is included by `generics_shared_tuple_only_test.rs` to provide the manual implementations
16+
//! that the shared tests compare against.
17+
#[ allow( unused_imports ) ]
218
use super::*; // Imports testing infrastructure and potentially other common items
319
use std::marker::PhantomData;
420
use former_types::
@@ -103,7 +119,7 @@ where Definition : FormerDefinition< Storage = InnerG3FormerStorage< T > >
103119
// --- Enum Definition with Bounds ---
104120
#[ derive( Debug, PartialEq, Clone ) ]
105121
// CORRECTED: Added BoundB to the enum's generic constraint for T
106-
pub enum EnumG3< T : BoundA + BoundB > // BoundA required by the enum, BoundB required by InnerG3<T>
122+
pub enum EnumG3< T : BoundA + BoundB > // BoundA required by enum, BoundB required by InnerG3<T>
107123
{
108124
V1( InnerG3< T > ), // Inner type uses T, so T must satisfy InnerG3's bounds (BoundB) *in addition* to EnumG3's bounds (BoundA)
109125
}

0 commit comments

Comments
 (0)