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