mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-07 11:05:13 +01:00
SPIGOT-3568: Fix single letter pagination edge case
By: md_5 <git@md-5.net>
This commit is contained in:
parent
663dce96c5
commit
28dfa926fd
2 changed files with 17 additions and 6 deletions
|
@ -93,7 +93,10 @@ public class ChatPaginator {
|
||||||
for (String partialWord : word.toString().split("(?<=\\G.{" + lineLength + "})")) {
|
for (String partialWord : word.toString().split("(?<=\\G.{" + lineLength + "})")) {
|
||||||
lines.add(partialWord);
|
lines.add(partialWord);
|
||||||
}
|
}
|
||||||
} else if (line.length() + word.length() - lineColorChars == lineLength) { // Line exactly the correct length...newline
|
} else if (line.length() + 1 + word.length() - lineColorChars == lineLength) { // Line exactly the correct length...newline
|
||||||
|
if (line.length() > 0) {
|
||||||
|
line.append(' ');
|
||||||
|
}
|
||||||
line.append(word);
|
line.append(word);
|
||||||
lines.add(line.toString());
|
lines.add(line.toString());
|
||||||
line = new StringBuilder();
|
line = new StringBuilder();
|
||||||
|
|
|
@ -7,14 +7,12 @@ import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.CoreMatchers.nullValue;
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public class ChatPaginatorTest {
|
public class ChatPaginatorTest {
|
||||||
@Test
|
@Test
|
||||||
public void testWordWrap1() {
|
public void testWordWrap1() {
|
||||||
String rawString = ChatColor.RED + "123456789 123456789 123456789";
|
String rawString = ChatColor.RED + "123456789 123456789 123456789";
|
||||||
String[] lines = ChatPaginator.wordWrap(rawString, 19);
|
String[] lines = ChatPaginator.wordWrap(rawString, 19);
|
||||||
|
|
||||||
assertThat(lines.length, is(2));
|
assertThat(lines.length, is(2));
|
||||||
assertThat(lines[0], is(ChatColor.RED + "123456789 123456789"));
|
assertThat(lines[0], is(ChatColor.RED + "123456789 123456789"));
|
||||||
assertThat(lines[1], is(ChatColor.RED.toString() + "123456789"));
|
assertThat(lines[1], is(ChatColor.RED.toString() + "123456789"));
|
||||||
|
@ -128,12 +126,22 @@ public class ChatPaginatorTest {
|
||||||
assertThat(lines.length, is(1));
|
assertThat(lines.length, is(1));
|
||||||
assertThat(lines[0], is(ChatColor.RED + "a a a " + ChatColor.BLUE + "a a"));
|
assertThat(lines[0], is(ChatColor.RED + "a a a " + ChatColor.BLUE + "a a"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWordWrap12() {
|
||||||
|
String rawString = "123 1 123";
|
||||||
|
String[] lines = ChatPaginator.wordWrap(rawString, 5);
|
||||||
|
|
||||||
|
assertThat(lines.length, is(2));
|
||||||
|
assertThat(lines[0], is(ChatColor.WHITE.toString() + "123 1"));
|
||||||
|
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPaginate1() {
|
public void testPaginate1() {
|
||||||
String rawString = "1234 123456789 123456789 123456789";
|
String rawString = "1234 123456789 123456789 123456789";
|
||||||
ChatPaginator.ChatPage page = ChatPaginator.paginate(rawString, 1, 6, 2);
|
ChatPaginator.ChatPage page = ChatPaginator.paginate(rawString, 1, 6, 2);
|
||||||
|
|
||||||
assertThat(page.getPageNumber(), is(1));
|
assertThat(page.getPageNumber(), is(1));
|
||||||
assertThat(page.getTotalPages(), is(4));
|
assertThat(page.getTotalPages(), is(4));
|
||||||
assertThat(page.getLines().length, is(2));
|
assertThat(page.getLines().length, is(2));
|
||||||
|
|
Loading…
Reference in a new issue