Skip to content

Commit

Permalink
former : introduce subform_scalar ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed May 12, 2024
1 parent 7dbf115 commit 401a6bd
Show file tree
Hide file tree
Showing 28 changed files with 134 additions and 54 deletions.
31 changes: 25 additions & 6 deletions module/core/derive_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,32 @@
#![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ]
#![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ]
#![ doc( html_root_url = "https://docs.rs/derive_tools/latest/derive_tools/" ) ]

//!
//! Collection of derives which extend STD.
//!
#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ]

// // xxx : implement derive new
//
// #[ derive( Debug, PartialEq, Default ) ]
// pub struct Property< Name >
// {
// name : Name,
// description : String,
// code : isize,
// }
//
// /// generated by new
// impl< Name > Property< Name >
// {
// #[ inline ]
// pub fn new< Description, Code >( name : Name, description : Description, code : Code ) -> Self
// where
// Name : core::convert::Into< Name >,
// Description : core::convert::Into< String >,
// Code : core::convert::Into< isize >,
// {
// Self { name : name.into(), description : description.into(), code : code.into() }
// }
// }

#[ cfg( feature = "enabled" ) ]
pub mod wtools;

Expand Down Expand Up @@ -56,7 +75,7 @@ mod derive_more
// #[ cfg( feature = "derive_reflect" ) ]
// pub mod reflect;

// use derive_tools_meta::Deref;
// use derive_tools_meta::Deref;
// use derive_tools_meta::VariadicFrom;

/// Namespace with dependencies.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ where
return result;
}

// xxx : update description
#[ inline( always ) ]
pub fn new( on_end : Definition::End ) -> Self
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#[ test ]
fn child()
fn subforme_scalar()
{

let got = Parent::former()
Expand Down
8 changes: 4 additions & 4 deletions module/core/former/tests/inc/former_tests/subform_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pub struct Child
// #[ derive( Debug, Default, PartialEq ) ]
pub struct Parent
{
#[ subform_entry( name = _child ) ]
#[ subform_collection( name = children2 ) ]
#[ scalar( name = children3 ) ]
#[ subform_collection( name = children2 ) ]
#[ subform_entry( name = _child ) ]
children : Vec< Child >,
}

Expand Down Expand Up @@ -51,6 +51,6 @@ where

// == end of generated

include!( "./only_test/subformer_subform_child.rs" );
include!( "./only_test/subformer_collection_children2.rs" );
include!( "./only_test/subform_entry_child.rs" );
include!( "./only_test/subform_collection_children2.rs" );
include!( "./only_test/scalar_children3.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ where
// #[ derive( Debug, Default, PartialEq ) ]
pub struct Parent< 'child >
{
#[ subform_entry( name = _child ) ]
#[ subform_collection( name = children2 ) ]
#[ scalar( name = children3 ) ]
#[ subform_collection( name = children2 ) ]
#[ subform_entry( name = _child ) ]
children : Vec< Child< 'child, str > >,
}

Expand Down Expand Up @@ -129,6 +129,6 @@ fn scalar()

}

// include!( "./only_test/subformer_subform_child.rs" );
// include!( "./only_test/subformer_collection_children2.rs" );
// include!( "./only_test/subformer_scalar_children3.rs" );
// include!( "./only_test/subform_entry_child.rs" );
// include!( "./only_test/subform_collection_children2.rs" );
// include!( "./only_test/subform_scalar_children3.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ struct Child
// #[ derive( Debug, Default, PartialEq ) ]
struct Parent
{
#[ subform_entry( name = _child ) ]
#[ subform_collection( name = children2 ) ]
#[ scalar( name = children3 ) ]
#[ subform_collection( name = children2 ) ]
#[ subform_entry( name = _child ) ]
children : Vec< Child >,
}

Expand Down Expand Up @@ -51,6 +51,6 @@ where

// == end of generated

include!( "./only_test/subformer_subform_child.rs" );
include!( "./only_test/subformer_collection_children2.rs" );
include!( "./only_test/subform_entry_child.rs" );
include!( "./only_test/subform_collection_children2.rs" );
include!( "./only_test/scalar_children3.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ pub struct Parent

// == end of generated

include!( "./only_test/subformer_collection.rs" );
include!( "./only_test/subform_collection.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ pub struct Parent

// == end of generated

include!( "./only_test/subformer_collection.rs" );
include!( "./only_test/subform_collection.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ where

// == end of generated for Parent in context of attribute collection( former::VectorDefinition ) ]

include!( "./only_test/subformer_collection.rs" );
include!( "./only_test/subform_collection.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ where

// == end of generated

include!( "./only_test/subformer_collection_children2.rs" );
include!( "./only_test/subform_collection_children2.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct Property< Name >
code : isize,
}

// xxx : implement derive new
// zzz : implement derive new
/// generated by new
impl< Name > Property< Name >
{
Expand Down Expand Up @@ -109,4 +109,4 @@ where

// ==

include!( "./only_test/subformer_basic.rs" );
include!( "./only_test/subform_basic.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ where

}

include!( "./only_test/subformer_collection_children2.rs" );
include!( "./only_test/subform_collection_children2.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ where

}

include!( "./only_test/subformer_scalar_children.rs" );
include!( "./only_test/subformer_collection_children2.rs" );
include!( "./only_test/subform_scalar_children.rs" );
include!( "./only_test/subform_collection_children2.rs" );
2 changes: 1 addition & 1 deletion module/core/former/tests/inc/former_tests/subform_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ where

// == end of generated

include!( "./only_test/subformer_subform_child.rs" );
include!( "./only_test/subform_entry_child.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ where
// Definition::Types : former::FormerDefinitionTypes< Storage = < Parent as former::EntityToStorage >::Storage >,
{

// xxx : rename
#[ inline( always ) ]
pub fn _children_subform_entry< Former2, Definition2 >( self ) ->
Former2
Expand Down Expand Up @@ -200,4 +199,4 @@ where

// == end of generated for Parent in context of attribute subform

include!( "./only_test/subformer_subform_child.rs" );
include!( "./only_test/subform_entry_child.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ where

// == end of generated

include!( "./only_test/subformer_subform_child.rs" );
include!( "./only_test/subform_entry_child.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ where

// == end of generated for Parent in context of attribute subform

include!( "./only_test/subformer_subform_child.rs" );
include!( "./only_test/subform_entry_child.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ where

}

include!( "./only_test/subformer_subform_children2.rs" );
include!( "./only_test/subform_entry_children2.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ where
}

include!( "./only_test/scalar_children.rs" );
include!( "./only_test/subformer_subform_children2.rs" );
include!( "./only_test/subform_entry_children2.rs" );
10 changes: 1 addition & 9 deletions module/core/former/tests/inc/former_tests/subform_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,8 @@ pub struct Parent
child : Child,
}

impl< Definition > ParentFormer< Definition >
where
Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >,
{

}

// == begin of generated

// == end of generated

include!( "./only_test/subformer_scalar_subform.rs" );
// xxx : uncomment
include!( "./only_test/subform_scalar.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ where
{

#[ inline( always ) ]
pub fn _child_scalar_subformer< Former2, Definition2 >( self ) ->
pub fn _child_subform_scalar< Former2, Definition2 >( self ) ->
Former2
where
Definition2 : former::FormerDefinition
Expand Down Expand Up @@ -60,7 +60,7 @@ where
pub fn child( self ) ->
ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > >
{
self._child_scalar_subformer
self._child_subform_scalar
::< < Child as former::EntityToFormer< _ > >::Former, _, >()
}

Expand Down Expand Up @@ -137,7 +137,4 @@ where

// == end of generated

include!( "./only_test/subformer_scalar_subform.rs" );
// xxx : uncomment
// xxx : write few more tests to cover name, setter
// xxx : extend all test
include!( "./only_test/subform_scalar.rs" );
73 changes: 73 additions & 0 deletions module/core/former/tests/inc/former_tests/subform_scalar_name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#![ allow( dead_code ) ]

use super::*;

/// Child
#[ derive( Debug, Default, PartialEq, the_module::Former ) ]
pub struct Child
{
name : String,
data : bool,
}

/// Parent
#[ derive( Debug, Default, PartialEq, the_module::Former ) ]
// #[ debug ]
// #[ derive( Debug, Default, PartialEq ) ]
pub struct Parent
{
#[ subform_scalar( name = child2 ) ]
child : Child,
}

impl< Definition > ParentFormer< Definition >
where
Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >,
{

pub fn child()
{
}

#[ inline( always ) ]
pub fn child3( self ) ->
ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > >
{
self._child_subform_scalar
::< < Child as former::EntityToFormer< _ > >::Former, _, >()
}

}

// == begin of generated

// == end of generated

#[ test ]
fn subforme_scalar_2()
{

let got = Parent::former()
.child2().name( "a" ).data( true ).end()
.form();

let exp = Parent { child : Child { name : "a".to_string(), data : true } };
a_id!( got, exp );

}

#[ test ]
fn subforme_scalar_3()
{

let got = Parent::former()
.child3().name( "a" ).data( true ).end()
.form();

let exp = Parent { child : Child { name : "a".to_string(), data : true } };
a_id!( got, exp );

}

// qqq : write tests similar to `subform_all` which apply attributes `scalar`, `subform_entry` and `subform_scalar` on the same field and check all three attribtues don't interfere with each other
5 changes: 3 additions & 2 deletions module/core/former/tests/inc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ mod former_tests

// = subform scalar

// xxx
#[ cfg( any( not( feature = "no_std" ) ) ) ]
mod subform_scalar_manual;
#[ cfg( any( not( feature = "no_std" ) ) ) ]
mod subform_scalar;
#[ cfg( any( not( feature = "no_std" ) ) ) ]
mod subform_scalar_manual;
mod subform_scalar_name;

// = subform entry

Expand Down

0 comments on commit 401a6bd

Please sign in to comment.