2 * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.commons.string;
9 import static org.junit.Assert.assertEquals;
11 public class String2Test {
14 public void testTrimPrefix() {
16 final String2 s = new String2("this is a test");
18 assertEquals("is a test", s.trimPrefix(5).toString());
19 assertEquals("a test", s.trimPrefix(3).toString());
20 assertEquals("test", s.trimPrefix(2).toString());
21 assertEquals("", s.trimPrefix(500).toString());
25 public void testTrimSuffix() {
27 final String2 s = new String2("this is a test");
29 assertEquals("this is a", s.trimSuffix(5).toString());
30 assertEquals("this is", s.trimSuffix(2).toString());
31 assertEquals("this", s.trimSuffix(3).toString());
32 assertEquals("", s.trimSuffix(500).toString());
37 public void testEnforceLength() {
38 final String2 s = new String2("12345678");
40 assertEquals("123", s.toString());
43 assertEquals("123 ", s.toString());
47 public void testSuffixAndPrefix() {
48 final String2 s = new String2("experiment");
49 s.prepend("The ").append(" !");
51 assertEquals("The experiment !", s.toString());