File: TextModelTestRemove.cpp

package info (click to toggle)
subcommander 2.0.0~b5p2-6
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 15,340 kB
  • ctags: 9,527
  • sloc: cpp: 63,594; sh: 4,050; xml: 1,992; makefile: 1,134; ansic: 786; ruby: 251; lisp: 24
file content (157 lines) | stat: -rw-r--r-- 3,896 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* ====================================================================
 * Copyright (c) 2003-2007, Martin Hauner
 *                          http://subcommander.tigris.org
 *
 * Subcommander is licensed as described in the file doc/COPYING, which
 * you should have received as part of this distribution.
 * ====================================================================
 */

#include "TextModelTestRemove.h"

// cppunit
#include <cppunit/TestSuite.h>
#include <cppunit/TestCaller.h>

// sc
#include "sublib/TextModelImpl.h"
#include "sublib/Cursor.h"
#include "sublib/Line.h"
#include "util/String.h"

void TextModelTestRemove::setUp()
{
  sc::String text( "test" );
  TextModelImpl* impl1 = new TextModelImpl( text );
  TextModelImpl* impl2 = new TextModelImpl( text );

  impl1->addLine( Line(sc::String("line1\x0a"),0,ctCommon) );
  impl1->addLine( Line(sc::String("line2\x0a"),0,ctCommon) );

  impl2->addLine( Line(sc::String("line1\x0d\x0a"),0,ctCommon) );
  impl2->addLine( Line(sc::String("line2\x0d\x0a"),0,ctCommon) );

  _text1 = impl1;
  _text2 = impl2;
}

void TextModelTestRemove::tearDown()
{
  delete _text1;
  delete _text2;
}

void TextModelTestRemove::testRemoveLeft()
{
  Cursor posBefore(0,3);
  Cursor posAfter(0,2);
  _text1->setCursor( posBefore );
  _text1->setCursor2( posBefore );

  _text1->removeTextLeft();

  {
    Cursor c1 = _text1->getCursor();
    Cursor c2 = _text1->getCursor2();
    CPPUNIT_ASSERT( c1.equalPos(posAfter) );
    CPPUNIT_ASSERT( c2.equalPos(posAfter) );
  }
  {
    const Line& res = _text1->getLine(0);
    CPPUNIT_ASSERT_EQUAL( sc::String("lie1\x0a"), res.getLine() );
  }

  _text1->undo();

  {
    Cursor c1 = _text1->getCursor();
    Cursor c2 = _text1->getCursor2();
    CPPUNIT_ASSERT( c1.equalPos(posBefore) );
    CPPUNIT_ASSERT( c2.equalPos(posBefore) );
  }
  {
    const Line& res = _text1->getLine(0);
    CPPUNIT_ASSERT_EQUAL( sc::String("line1\x0a"), res.getLine() );
  }
}


void TextModelTestRemove::testRemoveRight()
{
  Cursor posBefore(0,3);
  Cursor posAfter(0,3);
  _text1->setCursor( posBefore );
  _text1->setCursor2( posBefore );

  _text1->removeTextRight();

  {
    Cursor c1 = _text1->getCursor();
    Cursor c2 = _text1->getCursor2();
    CPPUNIT_ASSERT( c1.equalPos(posAfter) );
    CPPUNIT_ASSERT( c2.equalPos(posAfter) );
  }
  {
    const Line& res = _text1->getLine(0);
    CPPUNIT_ASSERT_EQUAL( sc::String("lin1\x0a"), res.getLine() );
  }

  _text1->undo();

  {
    Cursor c1 = _text1->getCursor();
    Cursor c2 = _text1->getCursor2();
    CPPUNIT_ASSERT( c1.equalPos(posBefore) );
    CPPUNIT_ASSERT( c2.equalPos(posBefore) );
  }
  {
    const Line& res = _text1->getLine(0);
    CPPUNIT_ASSERT_EQUAL( sc::String("line1\x0a"), res.getLine() );
  }
}


void TextModelTestRemove::testRemoveLeftLineEnd()
{
  Cursor posBefore(1,0);
  Cursor posAfter(0,5);
  _text1->setCursor( posBefore );
  _text1->setCursor2( posBefore );

  _text1->removeTextLeft();

  {
    Cursor c1 = _text1->getCursor();
    Cursor c2 = _text1->getCursor2();
    CPPUNIT_ASSERT( c1.equalPos(posAfter) );
    CPPUNIT_ASSERT( c2.equalPos(posAfter) );
  }
  {
    CPPUNIT_ASSERT( 1 == _text1->getLineCnt() );

    const Line& res = _text1->getLine(0);
    CPPUNIT_ASSERT_EQUAL( sc::String("line1line2\x0a"), res.getLine() );

    const Line& res2 = _text1->getLine(1);
    CPPUNIT_ASSERT_EQUAL( Line::getEmpty().getLine(), res2.getLine() );
  }

  _text1->undo();

  {
    Cursor c1 = _text1->getCursor();
    Cursor c2 = _text1->getCursor2();
    CPPUNIT_ASSERT( c1.equalPos(posBefore) );
    CPPUNIT_ASSERT( c2.equalPos(posBefore) );
  }
  {
    CPPUNIT_ASSERT( 2 == _text1->getLineCnt() );

    const Line& res = _text1->getLine(0);
    CPPUNIT_ASSERT_EQUAL( sc::String("line1\x0a"), res.getLine() );

    const Line& res2 = _text1->getLine(1);
    CPPUNIT_ASSERT_EQUAL( sc::String("line2\x0a"), res2.getLine() );
  }
}