forked from andreikop/qutepart-cpp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_char_iterator.cpp
76 lines (58 loc) · 2.21 KB
/
test_char_iterator.cpp
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
/*
* Copyright (C) 2018-2023 Andrei Kopats
* Copyright (C) 2023-... Diego Iastrubni <[email protected]>
* SPDX-License-Identifier: MIT
*/
#include <memory>
#include <QDebug>
#include <QObject>
#include <QTest>
#include "char_iterator.h"
#include "qutepart.h"
class Test : public QObject {
Q_OBJECT
private slots:
void DataDrivenTest_data() {
QTest::addColumn<QString>("text");
QTest::addColumn<int>("blockNumber");
QTest::addColumn<int>("column");
QTest::addColumn<bool>("forward");
QTest::addColumn<QString>("expected");
QTest::newRow("forward from start")
<< "one\ntwo\nthree\nfour" << 0 << 0 << true << "onetwothreefour";
QTest::newRow("forward from middle")
<< "one\ntwo\nthree\nfour" << 1 << 2 << true << "othreefour";
QTest::newRow("backward from end")
<< "one\ntwo\nthree\nfour" << 3 << 3 << false << "ruofeerhtowteno";
QTest::newRow("backward from middle")
<< "one\ntwo\nthree\nfour" << 2 << 1 << false << "htowteno";
QTest::newRow("with new lines")
<< "{\n new OpenFileList(mainWindow_, this);\n\n}" << 0 << 0 << true
<< "{ new OpenFileList(mainWindow_, this);}";
QTest::newRow("with new lines backward")
<< "{\n new OpenFileList(mainWindow_, this);\n\n}" << 3 << 0 << false
<< "};)siht ,_wodniWniam(tsiLeliFnepO wen {";
}
void DataDrivenTest() {
QFETCH(QString, text);
QFETCH(int, blockNumber);
QFETCH(int, column);
QFETCH(bool, forward);
QFETCH(QString, expected);
Qutepart::Qutepart qpart(nullptr, text);
Qutepart::TextPosition pos(qpart.document()->findBlockByNumber(blockNumber), column);
std::unique_ptr<Qutepart::CharIterator> it;
if (forward) {
it = std::make_unique<Qutepart::ForwardCharIterator>(pos);
} else {
it = std::make_unique<Qutepart::BackwardCharIterator>(pos);
}
QString accumulatedText;
while (!it->atEnd()) {
accumulatedText += it->step();
}
QCOMPARE(accumulatedText, expected);
}
};
QTEST_MAIN(Test)
#include "test_char_iterator.moc"