-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
176 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ where | |
} | ||
|
||
#[ test ] | ||
fn basic() | ||
fn container() | ||
{ | ||
|
||
let got = Parent::former() | ||
|
86 changes: 86 additions & 0 deletions
86
module/core/former/tests/inc/former_tests/subformer_container_setter_on.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#![ allow( dead_code ) ] | ||
|
||
use super::*; | ||
|
||
/// Child | ||
#[ derive( Debug, Default, PartialEq, the_module::Former ) ] | ||
pub struct Child | ||
{ | ||
name : String, | ||
is_mandatory : bool, | ||
} | ||
|
||
/// Parent | ||
#[ derive( Debug, Default, PartialEq, the_module::Former ) ] | ||
// #[ debug ] | ||
// #[ derive( Debug, Default, PartialEq ) ] | ||
pub struct Parent | ||
{ | ||
// Such parameters switch off generation of front-end container setter and switch on scalar setter. | ||
// Without explicit scalar_setter( true ) scalar setter is not generated. | ||
#[ subform( setter = false ) ] | ||
#[ scalar_setter( true ) ] | ||
children : Vec< Child >, | ||
} | ||
|
||
impl< Definition > ParentFormer< Definition > | ||
where | ||
Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, | ||
{ | ||
|
||
#[ inline( always ) ] | ||
pub fn children2( self ) -> former::ContainerSubformer:: | ||
< | ||
Child, | ||
former::VectorDefinition< Child, Self, Self, ParentFormerAssignChildrenEnd< Definition >, > | ||
> | ||
{ | ||
self._children_assign::< _ >() | ||
} | ||
|
||
} | ||
|
||
#[ test ] | ||
fn scalar() | ||
{ | ||
|
||
let children = vec! | ||
[ | ||
Child { name : "a".to_string(), is_mandatory : false }, | ||
Child { name : "b".to_string(), is_mandatory : false }, | ||
]; | ||
let got = Parent::former() | ||
.children( children ) | ||
.form(); | ||
|
||
let children = vec! | ||
[ | ||
Child { name : "a".to_string(), is_mandatory : false }, | ||
Child { name : "b".to_string(), is_mandatory : false }, | ||
]; | ||
let exp = Parent { children }; | ||
a_id!( got, exp ); | ||
|
||
} | ||
|
||
#[ test ] | ||
fn container() | ||
{ | ||
|
||
let got = Parent::former() | ||
.children2() | ||
.add( Child::former().name( "a" ).form() ) | ||
.add( Child::former().name( "b" ).form() ) | ||
.end() | ||
.form(); | ||
|
||
let children = vec! | ||
[ | ||
Child { name : "a".to_string(), is_mandatory : false }, | ||
Child { name : "b".to_string(), is_mandatory : false }, | ||
]; | ||
let exp = Parent { children }; | ||
a_id!( got, exp ); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
module/core/former/tests/inc/former_tests/subformer_subform_setter_on.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#![ allow( dead_code ) ] | ||
|
||
use super::*; | ||
|
||
/// Child | ||
#[ derive( Debug, Default, PartialEq, the_module::Former ) ] | ||
pub struct Child | ||
{ | ||
name : String, | ||
is_mandatory : bool, | ||
} | ||
|
||
/// Parent | ||
#[ derive( Debug, Default, PartialEq, the_module::Former ) ] | ||
// #[ debug ] | ||
// #[ derive( Debug, Default, PartialEq ) ] | ||
pub struct Parent | ||
{ | ||
// Such parameters switch off generation of front-end subform setter and switch on scalar setter. | ||
// Without explicit scalar_setter( true ) scalar setter is not generated. | ||
#[ subform( setter = false ) ] | ||
#[ scalar_setter( true ) ] | ||
children : Vec< Child >, | ||
} | ||
|
||
impl< Definition > ParentFormer< Definition > | ||
where | ||
Definition : former::FormerDefinition< Storage = < Parent as former::EntityToStorage >::Storage >, | ||
{ | ||
|
||
#[ inline( always ) ] | ||
pub fn children2( self, name : &str ) -> | ||
ChildAsSubformer< Self, impl ChildAsSubformerEnd< Self > > | ||
{ | ||
self._children_add | ||
::< ChildFormer< _ >, _, >() | ||
.name( name ) | ||
} | ||
|
||
} | ||
|
||
#[ test ] | ||
fn scalar() | ||
{ | ||
|
||
let children = vec! | ||
[ | ||
Child { name : "a".to_string(), is_mandatory : false }, | ||
Child { name : "b".to_string(), is_mandatory : false }, | ||
]; | ||
let got = Parent::former() | ||
.children( children ) | ||
.form(); | ||
|
||
let children = vec! | ||
[ | ||
Child { name : "a".to_string(), is_mandatory : false }, | ||
Child { name : "b".to_string(), is_mandatory : false }, | ||
]; | ||
let exp = Parent { children }; | ||
a_id!( got, exp ); | ||
|
||
} | ||
|
||
#[ test ] | ||
fn subform() | ||
{ | ||
|
||
let got = Parent::former() | ||
.children2( "a" ).end() | ||
.children2( "b" ).end() | ||
.form(); | ||
|
||
let children = vec! | ||
[ | ||
Child { name : "a".to_string(), is_mandatory : false }, | ||
Child { name : "b".to_string(), is_mandatory : false }, | ||
]; | ||
let exp = Parent { children }; | ||
a_id!( got, exp ); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters