2 * Sixth - System for data storage, computation, exploration and interaction.
3 * Copyright ©2012-2017, 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.sixth.e3d.gui.textEditorComponent;
12 import org.junit.Test;
14 import static org.junit.Assert.assertEquals;
16 public class TextLineTest {
19 public void testAddIdent() {
20 TextLine textLine = new TextLine("test");
22 assertEquals(" test", textLine.toString());
24 textLine = new TextLine();
26 assertEquals("", textLine.toString());
30 public void testCutFromBeginning() {
31 TextLine textLine = new TextLine("test");
32 textLine.cutFromBeginning(2);
33 assertEquals("st", textLine.toString());
35 textLine = new TextLine("test");
36 textLine.cutFromBeginning(4);
37 assertEquals("", textLine.toString());
39 textLine = new TextLine("test");
40 textLine.cutFromBeginning(5);
41 assertEquals("", textLine.toString());
43 textLine = new TextLine("test");
44 textLine.cutFromBeginning(100);
45 assertEquals("", textLine.toString());
49 public void testCutSubString() {
50 TextLine textLine = new TextLine("test");
51 assertEquals("es", textLine.cutSubString(1, 3));
52 assertEquals("tt", textLine.toString());
54 textLine = new TextLine("test");
55 assertEquals("st ", textLine.cutSubString(2, 5));
56 assertEquals("te", textLine.toString());
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));
68 public void testGetIdent() {
69 final TextLine textLine = new TextLine(" test");
70 assertEquals(3, textLine.getIdent());
74 public void testGetLength() {
75 final TextLine textLine = new TextLine("test");
76 assertEquals(4, textLine.getLength());
80 public void testInsertCharacter() {
81 TextLine textLine = new TextLine("test");
82 textLine.insertCharacter(1, 'o');
83 assertEquals("toest", textLine.toString());
85 textLine = new TextLine("test");
86 textLine.insertCharacter(5, 'o');
87 assertEquals("test o", textLine.toString());
92 public void testIsEmpty() {
93 TextLine textLine = new TextLine("");
94 assertEquals(true, textLine.isEmpty());
96 textLine = new TextLine(" ");
97 assertEquals(true, textLine.isEmpty());
99 textLine = new TextLine("l");
100 assertEquals(false, textLine.isEmpty());
104 public void testRemoveCharacter() {
105 TextLine textLine = new TextLine("test");
106 textLine.removeCharacter(0);
107 assertEquals("est", textLine.toString());
109 textLine = new TextLine("test");
110 textLine.removeCharacter(3);
111 assertEquals("tes", textLine.toString());
113 textLine = new TextLine("test");
114 textLine.removeCharacter(4);
115 assertEquals("test", textLine.toString());