Renamed CuttableString to more generic String2.
[svjatoslav_commons.git] / src / test / java / eu / svjatoslav / commons / string / String2Test.java
diff --git a/src/test/java/eu/svjatoslav/commons/string/String2Test.java b/src/test/java/eu/svjatoslav/commons/string/String2Test.java
new file mode 100755 (executable)
index 0000000..f13d0d2
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality.
+ * Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.commons.string;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class String2Test {
+
+       @Test
+       public void testCutLeft() {
+
+               final String2 s = new String2("this is a test");
+
+               assertEquals("this ", s.cutLeft(5));
+               assertEquals("is ", s.cutLeft(3));
+               assertEquals("a ", s.cutLeft(2));
+               assertEquals("test", s.cutLeft(25));
+               assertEquals("", s.cutLeft(5));
+
+       }
+
+       @Test
+       public void testEnforceLength() {
+               final String2 s = new String2("12345678");
+               s.enforceLength(3);
+               assertEquals("123", s.toString());
+
+               s.enforceLength(5);
+               assertEquals("123  ", s.toString());
+       }
+
+       @Test
+       public void testSuffexAndPrefix() {
+               final String2 s = new String2("experiment");
+               s.addPrefix("The ").addSuffix(" !");
+
+               assertEquals("The experiment !", s.toString());
+       }
+
+}