Changed license to CC0
[svjatoslav_commons.git] / src / test / java / eu / svjatoslav / commons / string / String2Test.java
1 /*
2  * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
3  * This project is released under Creative Commons Zero (CC0) license.
4  */
5 package eu.svjatoslav.commons.string;
6
7 import org.junit.Test;
8
9 import static org.junit.Assert.assertEquals;
10
11 public class String2Test {
12
13     @Test
14     public void testTrimPrefix() {
15
16         final String2 s = new String2("this is a test");
17
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());
22     }
23
24     @Test
25     public void testTrimSuffix() {
26
27         final String2 s = new String2("this is a test");
28
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());
33     }
34
35
36     @Test
37     public void testEnforceLength() {
38         final String2 s = new String2("12345678");
39         s.enforceLength(3);
40         assertEquals("123", s.toString());
41
42         s.enforceLength(5);
43         assertEquals("123  ", s.toString());
44     }
45
46     @Test
47     public void testSuffixAndPrefix() {
48         final String2 s = new String2("experiment");
49         s.addPrefix("The ").addSuffix(" !");
50
51         assertEquals("The experiment !", s.toString());
52     }
53
54 }