@@ -19,15 +19,94 @@ struct InterpolationTests {
19
19
#expect( string == " <a href= \" \( test) \" >Test</a> " )
20
20
}
21
21
22
- @Test func multiline_with_interpolation ( ) {
23
- let test : String = " again "
22
+ @Test func multiline_decl_interpolation ( ) {
23
+ let test : String = " prophecy "
24
24
let string : String = #html(
25
25
div (
26
26
" dune " ,
27
27
test
28
28
)
29
29
)
30
- #expect( string == " <div>dune again</div> " )
30
+ #expect( string == " <div>dune prophecy</div> " )
31
+ }
32
+
33
+ @Test func multiline_func_interpolation( ) {
34
+ var string : String = #html(
35
+ div (
36
+ " Bikini Bottom: " ,
37
+ InterpolationTests . spongebobCharacter (
38
+ " spongebob "
39
+ ) ,
40
+ " , " ,
41
+ InterpolationTests . spongebobCharacter ( " patrick "
42
+ ) ,
43
+ " , " ,
44
+ InterpolationTests . spongebobCharacter (
45
+ " squidward " ) ,
46
+ " , " ,
47
+ InterpolationTests
48
+ . spongebobCharacter (
49
+ " krabs "
50
+ ) ,
51
+ " , " ,
52
+ InterpolationTests . sandyCheeks ( ) ,
53
+ " , " ,
54
+ InterpolationTests
55
+ . spongebobCharacter (
56
+ " pearl krabs "
57
+ )
58
+ )
59
+ )
60
+ #expect( string == " <div>Bikini Bottom: Spongebob Squarepants, Patrick Star, Squidward Tentacles, Mr. Krabs, Sandy Cheeks, Pearl Krabs</div> " )
61
+
62
+ string = #html(
63
+ div (
64
+ " Don't forget " ,
65
+ InterpolationTests . BikiniBottom. gary ( ) ,
66
+ " ! "
67
+ )
68
+ )
69
+ #expect( string == " <div>Don't forget Gary!</div> " )
70
+
71
+ string = #html(
72
+ div (
73
+ InterpolationTests
74
+ . spongebob (
75
+ isBoob: false ,
76
+ isSquare:
77
+ true ,
78
+ middleName: Shrek
79
+ . isLife
80
+ . rawValue,
81
+ lastName: InterpolationTests
82
+ . sandyCheeks ( )
83
+ )
84
+ )
85
+ )
86
+ #expect( string == " <div>Spongeboob</div> " )
87
+ }
88
+
89
+ @Test func multiline_member_interpolation( ) {
90
+ var string : String = #html(
91
+ div (
92
+ " Shrek " ,
93
+ Shrek . isLove. rawValue,
94
+ " , Shrek " ,
95
+ Shrek
96
+ . isLife. rawValue
97
+ )
98
+ )
99
+ #expect( string == " <div>Shrek isLove, Shrek isLife</div> " )
100
+
101
+ string = #html(
102
+ div (
103
+ " Shrek " ,
104
+ InterpolationTests . Shrek. isLove. rawValue,
105
+ " , Shrek " ,
106
+ InterpolationTests . Shrek. isLife. rawValue
107
+ )
108
+ )
109
+ #expect( string == " <div>Shrek isLove, Shrek isLife</div> " )
31
110
}
32
111
33
112
@Test func flatten( ) {
@@ -72,15 +151,28 @@ extension InterpolationTests {
72
151
}
73
152
74
153
extension InterpolationTests {
154
+ enum BikiniBottom {
155
+ static func gary( ) -> String { " Gary " }
156
+ }
75
157
static let spongebob : String = " Spongebob Squarepants "
76
158
static let patrick : String = " Patrick Star "
77
159
static func spongebobCharacter( _ string: String ) -> String {
78
160
switch string {
79
161
case " spongebob " : return " Spongebob Squarepants "
80
162
case " patrick " : return " Patrick Star "
163
+ case " squidward " : return " Squidward Tentacles "
164
+ case " krabs " : return " Mr. Krabs "
165
+ case " pearl krabs " : return " Pearl Krabs "
166
+ case " karen " : return " Karen "
81
167
default : return " Plankton "
82
168
}
83
169
}
170
+ static func sandyCheeks( ) -> String {
171
+ return " Sandy Cheeks "
172
+ }
173
+ static func spongebob( isBoob: Bool , isSquare: Bool , middleName: String , lastName: String ) -> String {
174
+ return " Spongeboob "
175
+ }
84
176
85
177
@Test func third_party_literal( ) {
86
178
var string : String = #html( div ( attributes: [ . title( InterpolationTests . spongebob) ] ) )
@@ -89,11 +181,11 @@ extension InterpolationTests {
89
181
string = #html( div ( attributes: [ . title( InterpolationTests . patrick) ] ) )
90
182
#expect( string == " <div title= \" Patrick Star \" ></div> " )
91
183
92
- var static_string : StaticString = #html( div ( attributes: [ . title( " Mr. Crabs " ) ] ) )
93
- #expect( static_string == " <div title= \" Mr. Crabs \" ></div> " )
184
+ var static_string : StaticString = #html( div ( attributes: [ . title( " Mr. Krabs " ) ] ) )
185
+ #expect( static_string == " <div title= \" Mr. Krabs \" ></div> " )
94
186
95
- static_string = #html( div ( attributes: [ . title( " Mr. Crabs " ) ] ) )
96
- #expect( static_string == " <div title= \" Mr. Crabs \" ></div> " )
187
+ static_string = #html( div ( attributes: [ . title( " Mr. Krabs " ) ] ) )
188
+ #expect( static_string == " <div title= \" Mr. Krabs \" ></div> " )
97
189
}
98
190
@Test func third_party_func( ) {
99
191
let string : String = #html( div ( attributes: [ . title( InterpolationTests . spongebobCharacter ( " patrick " ) ) ] ) )
0 commit comments