@@ -35,40 +35,87 @@ class ResultBuildersTests: BaseEurekaTests {
3535 }
3636 DecimalRow ( " DecimalRow_f1 " ) { $0. title = " Decimal " }
3737 }
38+
39+ @FormBuilder
40+ var form : Form {
41+ Section ( " Section A " ) { section in
42+ section. tag = " Section_A "
43+ }
44+ if true {
45+ Section ( " Section B " ) { section in
46+ section. tag = " Section_B "
47+ }
48+ }
49+ NameRow ( " NameRow_f1 " ) { $0. title = " Name " }
50+ }
3851 #endif
3952
53+ private var checkBuildEither = false
54+ private var checkBuildExpressionBaseRowOptional = false
55+
4056 func testSectionBuilder( ) {
4157 #if swift(>=5.4)
42- var checkBuildEither = false
58+ setupManySectionsForm ( )
59+ addMoreItemsToManySectionsForm ( )
60+
61+ XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " NameRow_f1 " ) )
62+ XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " IntRow_f1 " ) )
63+ XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " DecimalRow_f1 " ) )
64+ XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " UrlRow_f1 " ) )
65+ XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " TwitterRow_f1 " ) )
66+ XCTAssertNil ( manySectionsForm. rowBy ( tag: " TwitterRow_f2 " ) )
67+ XCTAssertNil ( manySectionsForm. rowBy ( tag: " EmailRow_f1 " ) )
68+ XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " AccountRow_f1 " ) )
69+ XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " PhoneRow_f1 " ) )
70+ XCTAssertNil ( manySectionsForm. rowBy ( tag: " PhoneRow_f2 " ) )
71+ XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " ZipCodeRow_f1 " ) )
72+ XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " PasswordRow_f1 " ) )
73+ #endif
74+ }
75+
76+ private func setupManySectionsForm( ) {
77+ checkBuildEither = false
78+ checkBuildExpressionBaseRowOptional = true
4379 manySectionsForm = ( section1 +++ {
4480 URLRow ( " UrlRow_f1 " ) { $0. title = " Url " }
4581 if checkBuildEither {
4682 TwitterRow ( " TwitterRow_f2 " ) { $0. title = " Twitter " }
4783 } else {
4884 TwitterRow ( " TwitterRow_f1 " ) { $0. title = " Twitter " }
4985 }
86+ if checkBuildExpressionBaseRowOptional {
87+ nil
88+ } else {
89+ EmailRow ( " EmailRow_f1 " ) { $0. title = " Email " }
90+ }
5091 AccountRow ( " AccountRow_f1 " ) { $0. title = " Account " }
5192 } )
52- checkBuildEither = true
93+ }
94+
95+ private func addMoreItemsToManySectionsForm( ) {
96+ checkBuildEither. toggle ( )
97+ checkBuildExpressionBaseRowOptional. toggle ( )
5398 manySectionsForm +++ {
5499 if checkBuildEither {
55100 PhoneRow ( " PhoneRow_f1 " ) { $0. title = " Phone " }
56101 } else {
57102 PhoneRow ( " PhoneRow_f2 " ) { $0. title = " Phone " }
58103 }
104+ if checkBuildExpressionBaseRowOptional {
105+ nil
106+ } else {
107+ ZipCodeRow ( " ZipCodeRow_f1 " ) { $0. title = " Zip Code " }
108+ }
59109 PasswordRow ( " PasswordRow_f1 " ) { $0. title = " Password " }
60110 }
61-
111+ }
112+
113+ func testFormBuilder( ) {
114+ #if swift(>=5.4)
115+ manySectionsForm = form
116+ XCTAssertNotNil ( manySectionsForm. sectionBy ( tag: " Section_A " ) )
117+ XCTAssertNotNil ( manySectionsForm. sectionBy ( tag: " Section_B " ) )
62118 XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " NameRow_f1 " ) )
63- XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " IntRow_f1 " ) )
64- XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " DecimalRow_f1 " ) )
65- XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " UrlRow_f1 " ) )
66- XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " TwitterRow_f1 " ) )
67- XCTAssertNil ( manySectionsForm. rowBy ( tag: " TwitterRow_f2 " ) )
68- XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " AccountRow_f1 " ) )
69- XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " PhoneRow_f1 " ) )
70- XCTAssertNil ( manySectionsForm. rowBy ( tag: " PhoneRow_f2 " ) )
71- XCTAssertNotNil ( manySectionsForm. rowBy ( tag: " PasswordRow_f1 " ) )
72119 #endif
73120 }
74121}
0 commit comments