Created
July 12, 2016 23:26
-
-
Save thieux/8cb12d911ac28d211b53042c4d6dddf3 to your computer and use it in GitHub Desktop.
Java String split behavior
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Test; | |
import static org.assertj.core.api.Assertions.assertThat; | |
public class StringTest { | |
@Test | |
public void empty_regex_on_empty_char() { | |
assertThat("".split("")).isEqualTo(new String[]{""}); | |
} | |
@Test | |
public void empty_regex_cuts_each_char() { | |
assertThat("abc".split("")).isEqualTo(new String[]{"a", "b", "c"}); | |
} | |
@Test | |
public void cuts_empty_string_to_empty_component() { | |
assertThat("".split(":")).isEqualTo(new String[]{""}); | |
} | |
@Test | |
public void do_not_cut_when_input_equals_regex() { | |
assertThat(":".split(":")).isEqualTo(new String[]{}); | |
} | |
@Test | |
public void cut_into_one_component() { | |
assertThat("A".split(":")).isEqualTo(new String[]{"A"}); | |
} | |
@Test | |
public void suffix_input_by_regex_cut_into_one_component() { | |
assertThat("A:".split(":")).isEqualTo(new String[]{"A"}); | |
} | |
@Test | |
public void prefix_input_by_regex_cuts_into_two_components() { | |
assertThat(":A".split(":")).isEqualTo(new String[]{"", "A"}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment