File: TextModelTest.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 (135 lines) | stat: -rw-r--r-- 2,931 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
/* ====================================================================
 * 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 "TextModelTest.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 TextModelTest::setUp()
{
  sc::String text("test");

  _text = new TextModelImpl( text );
}

void TextModelTest::tearDown()
{
  delete _text;
}

void TextModelTest::testSingleCharAdd()
{
  Cursor null(0,0);

  Cursor c1 = _text->getCursor();
  Cursor c2 = _text->getCursor2();
  CPPUNIT_ASSERT( c1.equalPos(null) );
  CPPUNIT_ASSERT( c2.equalPos(null) );

  _text->addText( sc::String("1") );

  Cursor pos(0,1);

  c1 = _text->getCursor();
  c2 = _text->getCursor2();
  CPPUNIT_ASSERT( c1.equalPos(pos) );
  CPPUNIT_ASSERT( c2.equalPos(pos) );
}

void TextModelTest::testEmptyDelLeft()
{
  Cursor null(0,0);

  _text->removeTextLeft();
  _text->undo();

  Cursor c1 = _text->getCursor();
  Cursor c2 = _text->getCursor2();
  CPPUNIT_ASSERT( c1.equalPos(null) );
  CPPUNIT_ASSERT( c2.equalPos(null) );
}

void TextModelTest::testEmptyDelRight()
{
  Cursor null(0,0);

  _text->removeTextRight();
  _text->undo();

  Cursor c1 = _text->getCursor();
  Cursor c2 = _text->getCursor2();
  CPPUNIT_ASSERT( c1.equalPos(null) );
  CPPUNIT_ASSERT( c2.equalPos(null) );
}

void TextModelTest::testAddReturn()
{
  _text->addText( sc::String("\n") );

  {
    CPPUNIT_ASSERT( 2 == _text->getLineCnt() );

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

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

  _text->undo();

  {
    CPPUNIT_ASSERT( 1 == _text->getLineCnt() );

    const Line& res = _text->getLine(0);
    CPPUNIT_ASSERT_EQUAL( Line::getEmpty().getLine(), res.getLine() );
  }
}

void TextModelTest::testAddMultiLineLE()
{
  _text->addText( sc::String("line1\nline2\n") );

  CPPUNIT_ASSERT( 3 == _text->getLineCnt() );

  _text->undo();

  CPPUNIT_ASSERT( 1 == _text->getLineCnt() );
}

void TextModelTest::testAddMultiLine()
{
  _text->addText( sc::String("line1\nline2") );

  CPPUNIT_ASSERT( 2 == _text->getLineCnt() );

  _text->undo();

  CPPUNIT_ASSERT( 1 == _text->getLineCnt() );
}

void TextModelTest::testCalcNearestCursorPos()
{
  Cursor in(10,0);
  Cursor out = _text->calcNearestCursorPos(in);
  CPPUNIT_ASSERT( out.equalPos(Cursor(-1,0)) );

  _text->addText( sc::String("line1\nline2") );
  out = _text->calcNearestCursorPos(in);
  CPPUNIT_ASSERT( out.equalPos(Cursor(1,0)) );
}