mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-28 05:35:44 +00:00
Prevent leading and trailing whitespace in group names.
This commit is contained in:
committed by
Greyson Parrelli
parent
9c54e39eae
commit
ab76112f5f
@@ -0,0 +1,54 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public final class StringUtilTest_whitespace_handling {
|
||||
|
||||
private final String input;
|
||||
private final String expectedTrimmed;
|
||||
private final boolean isVisuallyEmpty;
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
return Arrays.asList(new Object[][]{
|
||||
|
||||
{ "", "", true },
|
||||
{ " ", "", true },
|
||||
{ "A", "A", false },
|
||||
{ " B", "B", false },
|
||||
{ "C ", "C", false },
|
||||
|
||||
/* Unicode whitespace */
|
||||
{ "\u200E", "", true },
|
||||
{ "\u200F", "", true },
|
||||
{ "\u2007", "", true },
|
||||
{ "\u2007\u200FA\tB\u200EC\u200E\u200F", "A\tB\u200EC", false },
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public StringUtilTest_whitespace_handling(String input, String expectedTrimmed, boolean isVisuallyEmpty) {
|
||||
this.input = input;
|
||||
this.expectedTrimmed = expectedTrimmed;
|
||||
this.isVisuallyEmpty = isVisuallyEmpty;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isVisuallyEmpty() {
|
||||
assertEquals(isVisuallyEmpty, StringUtil.isVisuallyEmpty(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trim() {
|
||||
assertEquals(expectedTrimmed, StringUtil.trimToVisualBounds(input));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user