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