forked from cloose/CuteMarkEd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompletionlistmodeltest.cpp
More file actions
101 lines (69 loc) · 3.19 KB
/
completionlistmodeltest.cpp
File metadata and controls
101 lines (69 loc) · 3.19 KB
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
#include "completionlistmodeltest.h"
#include <QtTest>
#include <snippets/snippet.h>
#include <completionlistmodel.h>
void CompletionListModelTest::acceptsNewSnippet()
{
model = new CompletionListModel(this);
QSignalSpy spy(model, SIGNAL(rowsInserted(QModelIndex,int,int)));
Snippet snippet;
snippet.trigger = "link";
snippet.description = "Hyperlink";
snippet.snippet = "[]()";
model->snippetCollectionChanged(SnippetCollection::ItemAdded, snippet);
QCOMPARE(spy.count(), 1);
QCOMPARE(model->rowCount(), 1);
assertItemMatchesSnippet(0, snippet);
delete model;
}
void CompletionListModelTest::updatesCorrectRowForSnippet()
{
model = new CompletionListModel(this);
Snippet snippet1; snippet1.trigger = "link"; snippet1.description = "Hyperlink";
Snippet snippet2; snippet2.trigger = "gq"; snippet2.description = "German Quotes";
model->snippetCollectionChanged(SnippetCollection::ItemAdded, snippet1);
model->snippetCollectionChanged(SnippetCollection::ItemAdded, snippet2);
snippet2.description = "Changed Description";
model->snippetCollectionChanged(SnippetCollection::ItemChanged, snippet2);
assertItemMatchesSnippet(0, snippet2);
delete model;
}
void CompletionListModelTest::removesCorrectRowForSnippet()
{
model = new CompletionListModel(this);
QSignalSpy spy(model, SIGNAL(rowsRemoved(QModelIndex,int,int)));
Snippet snippet1; snippet1.trigger = "link"; snippet1.description = "Hyperlink";
Snippet snippet2; snippet2.trigger = "gq"; snippet2.description = "German Quotes";
model->snippetCollectionChanged(SnippetCollection::ItemAdded, snippet1);
model->snippetCollectionChanged(SnippetCollection::ItemAdded, snippet2);
model->snippetCollectionChanged(SnippetCollection::ItemDeleted, snippet2);
QCOMPARE(spy.count(), 1);
QCOMPARE(model->rowCount(), 1);
assertItemMatchesSnippet(0, snippet1);
delete model;
}
void CompletionListModelTest::holdsSnippetsInTriggerOrder()
{
model = new CompletionListModel(this);
Snippet snippet1; snippet1.trigger = "a";
Snippet snippet2; snippet2.trigger = "b";
Snippet snippet3; snippet3.trigger = "c";
model->snippetCollectionChanged(SnippetCollection::ItemAdded, snippet2); // b
model->snippetCollectionChanged(SnippetCollection::ItemAdded, snippet3); // c
model->snippetCollectionChanged(SnippetCollection::ItemAdded, snippet1); // a
QCOMPARE(itemValue(0, Qt::EditRole).toString(), snippet1.trigger); // a
QCOMPARE(itemValue(1, Qt::EditRole).toString(), snippet2.trigger); // b
QCOMPARE(itemValue(2, Qt::EditRole).toString(), snippet3.trigger); // c
delete model;
}
void CompletionListModelTest::assertItemMatchesSnippet(int row, const Snippet &snippet)
{
QCOMPARE(itemValue(row, Qt::EditRole).toString(), snippet.trigger);
QVERIFY(itemValue(row, Qt::DisplayRole).toString().contains(snippet.trigger));
QVERIFY(itemValue(row, Qt::DisplayRole).toString().contains(snippet.description));
QCOMPARE(itemValue(row, Qt::ToolTipRole).toString(), snippet.snippet.toHtmlEscaped());
}
QVariant CompletionListModelTest::itemValue(int row, int role)
{
return model->data(model->index(row), role);
}