forked from cloose/CuteMarkEd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnippetcollectiontest.cpp
More file actions
130 lines (101 loc) · 4.35 KB
/
snippetcollectiontest.cpp
File metadata and controls
130 lines (101 loc) · 4.35 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
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
/*
* Copyright 2013 Christian Loose <christian.loose@hamburg.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "snippetcollectiontest.h"
#include <QtTest>
#include <snippets/snippetcollection.h>
void SnippetCollectionTest::initTestCase()
{
qRegisterMetaType<SnippetCollection::CollectionChangedType>(); // for QSignalSpy
qRegisterMetaType<Snippet>(); // for QSignalSpy
}
void SnippetCollectionTest::notifiesListenersOfNewSnippets()
{
const Snippet snippet;
SnippetCollection collection;
QSignalSpy spy(&collection, SIGNAL(collectionChanged(SnippetCollection::CollectionChangedType, Snippet)));
collection.insert(snippet);
QCOMPARE(spy.count(), 1);
QList<QVariant> arguments = spy.takeFirst();
QCOMPARE(arguments.at(0).value<SnippetCollection::CollectionChangedType>(), SnippetCollection::ItemAdded);
}
void SnippetCollectionTest::notifiesListenersOfChangedSnippets()
{
const Snippet snippet;
SnippetCollection collection;
QSignalSpy spy(&collection, SIGNAL(collectionChanged(SnippetCollection::CollectionChangedType, Snippet)));
collection.insert(snippet);
collection.update(snippet);
QCOMPARE(spy.count(), 2);
QList<QVariant> arguments = spy.takeAt(1);
QCOMPARE(arguments.at(0).value<SnippetCollection::CollectionChangedType>(), SnippetCollection::ItemChanged);
}
void SnippetCollectionTest::notifiesListenersOfRemovedSnippets()
{
const Snippet snippet;
SnippetCollection collection;
QSignalSpy spy(&collection, SIGNAL(collectionChanged(SnippetCollection::CollectionChangedType, Snippet)));
collection.insert(snippet);
collection.remove(snippet);
QCOMPARE(spy.count(), 2);
QList<QVariant> arguments = spy.takeAt(1);
QCOMPARE(arguments.at(0).value<SnippetCollection::CollectionChangedType>(), SnippetCollection::ItemDeleted);
}
void SnippetCollectionTest::holdsSnippetsInTriggerOrder()
{
Snippet snippet1; snippet1.trigger = "a";
Snippet snippet2; snippet2.trigger = "b";
Snippet snippet3; snippet3.trigger = "c";
SnippetCollection collection;
collection.insert(snippet2); // b
collection.insert(snippet3); // c
collection.insert(snippet1); // a
QCOMPARE(collection.at(0).trigger, snippet1.trigger); // a
QCOMPARE(collection.at(1).trigger, snippet2.trigger); // b
QCOMPARE(collection.at(2).trigger, snippet3.trigger); // c
}
void SnippetCollectionTest::returnsNewCollectionOfUserDefinedSnippets()
{
Snippet snippet1; snippet1.trigger = "a"; snippet1.builtIn = true;
Snippet snippet2; snippet2.trigger = "b"; snippet2.builtIn = false;
Snippet snippet3; snippet3.trigger = "c"; snippet3.builtIn = false;
SnippetCollection collection;
collection.insert(snippet2);
collection.insert(snippet1);
collection.insert(snippet3);
QSharedPointer<SnippetCollection> userDefinedSnippets = collection.userDefinedSnippets();
QVERIFY(!userDefinedSnippets.isNull());
QVERIFY(userDefinedSnippets.data() != &collection);
QCOMPARE(userDefinedSnippets->count(), 2);
QVERIFY(!userDefinedSnippets->contains(snippet1.trigger));
QVERIFY(userDefinedSnippets->contains(snippet2.trigger));
QVERIFY(userDefinedSnippets->contains(snippet3.trigger));
}
void SnippetCollectionTest::returnsConstantNameOfJsonArray()
{
SnippetCollection collection;
QCOMPARE(collection.name(), QStringLiteral("snippets"));
}
void SnippetCollectionTest::returnsEmptySnippetForNonExistingTrigger()
{
Snippet snippet; snippet.trigger = "ArbitraryName";
SnippetCollection collection;
collection.insert(snippet);
Snippet foundSnippet = collection.snippet("NonExistingSnippet");
QCOMPARE(foundSnippet.trigger, QString());
QCOMPARE(foundSnippet.description, QString());
QCOMPARE(foundSnippet.snippet, QString());
}