2 * Svjatoslav Commons - shared library of common functionality.
3 * Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 3 of the GNU Lesser General Public License
7 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.commons.string;
12 import org.junit.Test;
14 import static org.junit.Assert.assertEquals;
16 public class String2Test {
19 public void testTrimPrefix() {
21 final String2 s = new String2("this is a test");
23 assertEquals("is a test", s.trimPrefix(5).toString());
24 assertEquals("a test", s.trimPrefix(3).toString());
25 assertEquals("test", s.trimPrefix(2).toString());
26 assertEquals("", s.trimPrefix(500).toString());
30 public void testTrimSuffix() {
32 final String2 s = new String2("this is a test");
34 assertEquals("this is a", s.trimSuffix(5).toString());
35 assertEquals("this is", s.trimSuffix(2).toString());
36 assertEquals("this", s.trimSuffix(3).toString());
37 assertEquals("", s.trimSuffix(500).toString());
42 public void testEnforceLength() {
43 final String2 s = new String2("12345678");
45 assertEquals("123", s.toString());
48 assertEquals("123 ", s.toString());
52 public void testSuffixAndPrefix() {
53 final String2 s = new String2("experiment");
54 s.addPrefix("The ").addSuffix(" !");
56 assertEquals("The experiment !", s.toString());