mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-15 04:05:50 -07:00
[Bleeding] ChatPaginator now preserves the color of a line after wrapping the line of text. Fixes BUKKIT-1048
By: rmichela <deltahat@gmail.com>
This commit is contained in:
@@ -12,12 +12,12 @@ import static org.junit.Assert.assertThat;
|
||||
public class ChatPaginatorTest {
|
||||
@Test
|
||||
public void testWordWrap1() {
|
||||
String rawString = "123456789 123456789 123456789";
|
||||
String rawString = ChatColor.RED + "123456789 123456789 123456789";
|
||||
String[] lines = ChatPaginator.wordWrap(rawString, 19);
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is("123456789 123456789"));
|
||||
assertThat(lines[1], is("123456789"));
|
||||
assertThat(lines[0], is(ChatColor.RED + "123456789 123456789"));
|
||||
assertThat(lines[1], is(ChatColor.RED.toString() + "123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -26,19 +26,19 @@ public class ChatPaginatorTest {
|
||||
String[] lines = ChatPaginator.wordWrap(rawString, 22);
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is("123456789 123456789"));
|
||||
assertThat(lines[1], is("123456789"));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "123456789 123456789"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWordWrap3() {
|
||||
String rawString = "123456789 123456789 123456789";
|
||||
String rawString = ChatColor.RED + "123456789 " + ChatColor.RED + ChatColor.RED + "123456789 " + ChatColor.RED + "123456789";
|
||||
String[] lines = ChatPaginator.wordWrap(rawString, 16);
|
||||
|
||||
assertThat(lines.length, is(3));
|
||||
assertThat(lines[0], is("123456789"));
|
||||
assertThat(lines[1], is("123456789"));
|
||||
assertThat(lines[2], is("123456789"));
|
||||
assertThat(lines[0], is(ChatColor.RED + "123456789"));
|
||||
assertThat(lines[1], is(ChatColor.RED.toString() + ChatColor.RED + "123456789"));
|
||||
assertThat(lines[2], is(ChatColor.RED + "123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -47,8 +47,8 @@ public class ChatPaginatorTest {
|
||||
String[] lines = ChatPaginator.wordWrap(rawString, 19);
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is("123456789 123456789"));
|
||||
assertThat(lines[1], is("123456789 12345"));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "123456789 123456789"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789 12345"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -57,8 +57,8 @@ public class ChatPaginatorTest {
|
||||
String[] lines = ChatPaginator.wordWrap(rawString, 19);
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is("123456789"));
|
||||
assertThat(lines[1], is("123456789 123456789"));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "123456789"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789 123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,8 +67,8 @@ public class ChatPaginatorTest {
|
||||
String[] lines = ChatPaginator.wordWrap(rawString, 19);
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is("12345678 23456789"));
|
||||
assertThat(lines[1], is("123456789"));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "12345678 23456789"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,8 +77,8 @@ public class ChatPaginatorTest {
|
||||
String[] lines = ChatPaginator.wordWrap(rawString, 19);
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is("12345678 23456789"));
|
||||
assertThat(lines[1], is("123456789"));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "12345678 23456789"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,12 +87,12 @@ public class ChatPaginatorTest {
|
||||
String[] lines = ChatPaginator.wordWrap(rawString, 6);
|
||||
|
||||
assertThat(lines.length, is(6));
|
||||
assertThat(lines[0], is("123456"));
|
||||
assertThat(lines[1], is("789"));
|
||||
assertThat(lines[2], is("123456"));
|
||||
assertThat(lines[3], is("789"));
|
||||
assertThat(lines[4], is("123456"));
|
||||
assertThat(lines[5], is("789"));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "123456"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "789"));
|
||||
assertThat(lines[2], is(ChatColor.WHITE.toString() + "123456"));
|
||||
assertThat(lines[3], is(ChatColor.WHITE.toString() + "789"));
|
||||
assertThat(lines[4], is(ChatColor.WHITE.toString() + "123456"));
|
||||
assertThat(lines[5], is(ChatColor.WHITE.toString() + "789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,13 +101,13 @@ public class ChatPaginatorTest {
|
||||
String[] lines = ChatPaginator.wordWrap(rawString, 6);
|
||||
|
||||
assertThat(lines.length, is(7));
|
||||
assertThat(lines[0], is("1234"));
|
||||
assertThat(lines[1], is("123456"));
|
||||
assertThat(lines[2], is("789"));
|
||||
assertThat(lines[3], is("123456"));
|
||||
assertThat(lines[4], is("789"));
|
||||
assertThat(lines[5], is("123456"));
|
||||
assertThat(lines[6], is("789"));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "1234"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456"));
|
||||
assertThat(lines[2], is(ChatColor.WHITE.toString() + "789"));
|
||||
assertThat(lines[3], is(ChatColor.WHITE.toString() + "123456"));
|
||||
assertThat(lines[4], is(ChatColor.WHITE.toString() + "789"));
|
||||
assertThat(lines[5], is(ChatColor.WHITE.toString() + "123456"));
|
||||
assertThat(lines[6], is(ChatColor.WHITE.toString() + "789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,8 +116,17 @@ public class ChatPaginatorTest {
|
||||
String[] lines = ChatPaginator.wordWrap(rawString, 19);
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is("123456789"));
|
||||
assertThat(lines[1], is("123456789"));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "123456789"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWordWrap11() {
|
||||
String rawString = ChatColor.RED + "a a a " + ChatColor.BLUE + "a a";
|
||||
String[] lines = ChatPaginator.wordWrap(rawString, 9);
|
||||
|
||||
assertThat(lines.length, is(1));
|
||||
assertThat(lines[0], is(ChatColor.RED + "a a a " + ChatColor.BLUE + "a a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,8 +137,8 @@ public class ChatPaginatorTest {
|
||||
assertThat(page.getPageNumber(), is(1));
|
||||
assertThat(page.getTotalPages(), is(4));
|
||||
assertThat(page.getLines().length, is(2));
|
||||
assertThat(page.getLines()[0], is("1234"));
|
||||
assertThat(page.getLines()[1], is("123456"));
|
||||
assertThat(page.getLines()[0], is(ChatColor.WHITE.toString() + "1234"));
|
||||
assertThat(page.getLines()[1], is(ChatColor.WHITE.toString() + "123456"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,8 +149,8 @@ public class ChatPaginatorTest {
|
||||
assertThat(page.getPageNumber(), is(2));
|
||||
assertThat(page.getTotalPages(), is(4));
|
||||
assertThat(page.getLines().length, is(2));
|
||||
assertThat(page.getLines()[0], is("789"));
|
||||
assertThat(page.getLines()[1], is("123456"));
|
||||
assertThat(page.getLines()[0], is(ChatColor.WHITE.toString() + "789"));
|
||||
assertThat(page.getLines()[1], is(ChatColor.WHITE.toString() + "123456"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -152,6 +161,6 @@ public class ChatPaginatorTest {
|
||||
assertThat(page.getPageNumber(), is(4));
|
||||
assertThat(page.getTotalPages(), is(4));
|
||||
assertThat(page.getLines().length, is(1));
|
||||
assertThat(page.getLines()[0], is("789"));
|
||||
assertThat(page.getLines()[0], is(ChatColor.WHITE.toString() + "789"));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user