Changed license to Creative Commons Zero (CC0).
[sixth-3d.git] / src / test / java / eu / svjatoslav / sixth / e3d / gui / textEditorComponent / TextLineTest.java
1 /*
2  * Sixth - System for data storage, computation, exploration and interaction.
3  * Author: Svjatoslav Agejenko. 
4  * This project is released under Creative Commons Zero (CC0) license.
5  *
6 */
7
8 package eu.svjatoslav.sixth.e3d.gui.textEditorComponent;
9
10 import org.junit.Test;
11
12 import static org.junit.Assert.assertEquals;
13
14 public class TextLineTest {
15
16     @Test
17     public void testAddIdent() {
18         TextLine textLine = new TextLine("test");
19         textLine.addIdent(4);
20         assertEquals("    test", textLine.toString());
21
22         textLine = new TextLine();
23         textLine.addIdent(4);
24         assertEquals("", textLine.toString());
25     }
26
27     @Test
28     public void testCutFromBeginning() {
29         TextLine textLine = new TextLine("test");
30         textLine.cutFromBeginning(2);
31         assertEquals("st", textLine.toString());
32
33         textLine = new TextLine("test");
34         textLine.cutFromBeginning(4);
35         assertEquals("", textLine.toString());
36
37         textLine = new TextLine("test");
38         textLine.cutFromBeginning(5);
39         assertEquals("", textLine.toString());
40
41         textLine = new TextLine("test");
42         textLine.cutFromBeginning(100);
43         assertEquals("", textLine.toString());
44     }
45
46     @Test
47     public void testCutSubString() {
48         TextLine textLine = new TextLine("test");
49         assertEquals("es", textLine.cutSubString(1, 3));
50         assertEquals("tt", textLine.toString());
51
52         textLine = new TextLine("test");
53         assertEquals("st ", textLine.cutSubString(2, 5));
54         assertEquals("te", textLine.toString());
55     }
56
57     @Test
58     public void testGetCharForLocation() {
59         final TextLine textLine = new TextLine("test");
60         assertEquals('s', textLine.getCharForLocation(2));
61         assertEquals('t', textLine.getCharForLocation(3));
62         assertEquals(' ', textLine.getCharForLocation(4));
63     }
64
65     @Test
66     public void testGetIdent() {
67         final TextLine textLine = new TextLine("   test");
68         assertEquals(3, textLine.getIdent());
69     }
70
71     @Test
72     public void testGetLength() {
73         final TextLine textLine = new TextLine("test");
74         assertEquals(4, textLine.getLength());
75     }
76
77     @Test
78     public void testInsertCharacter() {
79         TextLine textLine = new TextLine("test");
80         textLine.insertCharacter(1, 'o');
81         assertEquals("toest", textLine.toString());
82
83         textLine = new TextLine("test");
84         textLine.insertCharacter(5, 'o');
85         assertEquals("test o", textLine.toString());
86
87     }
88
89     @Test
90     public void testIsEmpty() {
91         TextLine textLine = new TextLine("");
92         assertEquals(true, textLine.isEmpty());
93
94         textLine = new TextLine("     ");
95         assertEquals(true, textLine.isEmpty());
96
97         textLine = new TextLine("l");
98         assertEquals(false, textLine.isEmpty());
99     }
100
101     @Test
102     public void testRemoveCharacter() {
103         TextLine textLine = new TextLine("test");
104         textLine.removeCharacter(0);
105         assertEquals("est", textLine.toString());
106
107         textLine = new TextLine("test");
108         textLine.removeCharacter(3);
109         assertEquals("tes", textLine.toString());
110
111         textLine = new TextLine("test");
112         textLine.removeCharacter(4);
113         assertEquals("test", textLine.toString());
114     }
115
116 }