34
34
import net .kyori .adventure .text .NBTComponent ;
35
35
import net .kyori .adventure .text .TranslatableComponent ;
36
36
import net .kyori .adventure .text .TranslationArgument ;
37
+ import net .kyori .adventure .text .event .ClickEvent ;
38
+ import net .kyori .adventure .text .event .HoverEvent ;
37
39
import net .kyori .adventure .text .format .NamedTextColor ;
38
40
import net .kyori .adventure .text .format .Style ;
39
41
import net .kyori .adventure .text .format .TextDecoration ;
@@ -52,6 +54,7 @@ static class TrackingFlattener implements FlattenerListener {
52
54
int pushCount ;
53
55
int popCount ;
54
56
final List <Style > pushedStyles = new ArrayList <>();
57
+ final List <Style > poppedStyles = new ArrayList <>();
55
58
final List <String > strings = new ArrayList <>();
56
59
57
60
@ Override
@@ -68,6 +71,7 @@ public void component(final @NotNull String text) {
68
71
@ Override
69
72
public void popStyle (final @ NotNull Style style ) {
70
73
this .popCount ++;
74
+ this .poppedStyles .add (style );
71
75
}
72
76
73
77
public TrackingFlattener assertBalanced () {
@@ -90,6 +94,11 @@ public TrackingFlattener assertStyles(final Style... styles) {
90
94
assertIterableEquals (Arrays .asList (styles ), this .pushedStyles );
91
95
return this ;
92
96
}
97
+
98
+ public TrackingFlattener assertPoppedStyles (final Style ... styles ) {
99
+ assertIterableEquals (Arrays .asList (styles ), this .poppedStyles );
100
+ return this ;
101
+ }
93
102
}
94
103
95
104
static class CancellingFlattener extends TrackingFlattener {
@@ -154,6 +163,40 @@ void testComplex() {
154
163
.assertContents ("Hi there my" , " blue " , "friend" );
155
164
}
156
165
166
+ @ Test
167
+ void testComplexNested () {
168
+ final Component input = Component .text ()
169
+ .content ("Hi there my" )
170
+ .append (Component .text (" clickable " )
171
+ .clickEvent (ClickEvent .copyToClipboard ("some text" ))
172
+ .append (
173
+ Component .text ("and bold " )
174
+ .decorate (TextDecoration .BOLD )
175
+ .append (Component .text ("red " , NamedTextColor .RED )))
176
+ .append (
177
+ Component .text ("and blue " , NamedTextColor .BLUE )))
178
+ .append (Component .text ("friend" ))
179
+ .build ();
180
+
181
+ this .testFlatten (ComponentFlattener .basic (), input ).assertBalanced ()
182
+ .assertPushesAndPops (6 )
183
+ .assertStyles (
184
+ Style .empty (),
185
+ Style .style (ClickEvent .copyToClipboard ("some text" )),
186
+ Style .style (TextDecoration .BOLD ),
187
+ Style .style (NamedTextColor .RED ),
188
+ Style .style (NamedTextColor .BLUE ),
189
+ Style .empty ())
190
+ .assertPoppedStyles (
191
+ Style .style (NamedTextColor .RED ),
192
+ Style .style (TextDecoration .BOLD ),
193
+ Style .style (NamedTextColor .BLUE ),
194
+ Style .style (ClickEvent .copyToClipboard ("some text" )),
195
+ Style .empty (),
196
+ Style .empty ())
197
+ .assertContents ("Hi there my" , " clickable " , "and bold " , "red " , "and blue " , "friend" );
198
+ }
199
+
157
200
@ Test
158
201
void testTranslatable () {
159
202
this .testFlatten (ComponentFlattener .basic (), Component .translatable ("adventure.test.key" ))
0 commit comments