1
/* This file is part of the KDE libraries
2
Copyright (C) 2010 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
20
#include "scriptdocument_test.h"
21
#include "moc_scriptdocument_test.cpp"
23
#include <qtest_kde.h>
25
#include <ktexteditor/view.h>
27
#include <katedocument.h>
28
#include <katescriptdocument.h>
30
Q_DECLARE_METATYPE(KTextEditor::Cursor)
32
QTEST_KDEMAIN(ScriptDocumentTest, GUI)
36
char *toString(const KTextEditor::Cursor &cursor)
38
QByteArray ba = "Cursor[";
39
ba += QByteArray::number(cursor.line()) + ", " + QByteArray::number(cursor.column());
41
return qstrdup(ba.data());
45
QtMsgHandler ScriptDocumentTest::s_msgHandler = 0;
47
void myMessageOutput(QtMsgType type, const char *msg)
54
ScriptDocumentTest::s_msgHandler(type, msg);
58
void ScriptDocumentTest::initTestCase()
60
s_msgHandler = qInstallMsgHandler(myMessageOutput);
63
void ScriptDocumentTest::cleanupTestCase()
65
qInstallMsgHandler(0);
68
ScriptDocumentTest::ScriptDocumentTest()
76
ScriptDocumentTest::~ScriptDocumentTest()
80
void ScriptDocumentTest::init()
82
m_doc = new KateDocument(false, false, false, 0, this);
83
m_view = m_doc->createView(0);
84
m_scriptDoc = new KateScriptDocument(this);
85
m_scriptDoc->setDocument(m_doc);
88
void ScriptDocumentTest::cleanup()
96
void ScriptDocumentTest::testRfind_data()
98
QTest::addColumn<KTextEditor::Range>("searchRange");
99
QTest::addColumn<KTextEditor::Range>("expectedResult");
101
QTest::newRow("") << KTextEditor::Range(0, 0, 1, 10) << KTextEditor::Range(1, 6, 1, 10);
102
QTest::newRow("") << KTextEditor::Range(0, 0, 1, 5) << KTextEditor::Range(1, 0, 1, 4);
103
QTest::newRow("") << KTextEditor::Range(0, 0, 1, 0) << KTextEditor::Range(0, 10, 0, 14);
106
void ScriptDocumentTest::testRfind()
108
QFETCH(KTextEditor::Range, searchRange);
109
QFETCH(KTextEditor::Range, expectedResult);
111
m_doc->setText("aaaa aaaa aaaa\n"
114
QCOMPARE(m_search->search(searchRange, "aaaa", true), expectedResult);
118
void ScriptDocumentTest::testRfind_data()
120
QTest::addColumn<KTextEditor::Cursor>("searchStart");
121
QTest::addColumn<KTextEditor::Cursor>("result");
123
QTest::newRow("a a a a a a a a a a a a|") << KTextEditor::Cursor(0, 23) << KTextEditor::Cursor(0, 18);
124
QTest::newRow("a a a a a a a a a a a |a") << KTextEditor::Cursor(0, 22) << KTextEditor::Cursor(0, 16);
125
QTest::newRow("a a a a| a a a a a a a a") << KTextEditor::Cursor(0, 7) << KTextEditor::Cursor(0, 2);
126
QTest::newRow("a a a |a a a a a a a a a") << KTextEditor::Cursor(0, 6) << KTextEditor::Cursor(0, 0);
127
QTest::newRow("a a a| a a a a a a a a a") << KTextEditor::Cursor(0, 5) << KTextEditor::Cursor(0, 0);
128
QTest::newRow("a a |a a a a a a a a a a") << KTextEditor::Cursor(0, 4) << KTextEditor::Cursor::invalid();
131
void ScriptDocumentTest::testRfind()
133
QFETCH(KTextEditor::Cursor, searchStart);
134
QFETCH(KTextEditor::Cursor, result);
136
m_scriptDoc->setText("a a a a a a a a a a a a");
138
QCOMPARE(m_scriptDoc->rfind(searchStart.line(), searchStart.column(), "a a a"), result);