Changeset View
Changeset View
Standalone View
Standalone View
plugins/clang/tests/test_codecompletion.cpp
Show First 20 Lines • Show All 1109 Lines • ▼ Show 20 Line(s) | 1092 | { | |||
---|---|---|---|---|---|
1110 | VERIFY(item); | 1110 | VERIFY(item); | ||
1111 | QCOMPARE(item->declaration()->range().start, CursorInRevision(1, 14)); | 1111 | QCOMPARE(item->declaration()->range().start, CursorInRevision(1, 14)); | ||
1112 | } | 1112 | } | ||
1113 | 1113 | | |||
1114 | void TestCodeCompletion::testArgumentHintCompletion() | 1114 | void TestCodeCompletion::testArgumentHintCompletion() | ||
1115 | { | 1115 | { | ||
1116 | QFETCH(QString, code); | 1116 | QFETCH(QString, code); | ||
1117 | QFETCH(CompletionItems, expectedItems); | 1117 | QFETCH(CompletionItems, expectedItems); | ||
1118 | QFETCH(QStringList, hints); | ||||
1118 | 1119 | | |||
1119 | executeCompletionTest(code, expectedItems); | 1120 | executeCompletionTest(code, expectedItems, NoMacroOrBuiltin, [&](const ClangCodeCompletionItemTester& tester) { | ||
1121 | QStringList actualHints; | ||||
1122 | for (const auto& item : tester.items) { | ||||
1123 | if (item->argumentHintDepth() == 1) { | ||||
1124 | actualHints << tester.itemData(item).toString() + tester.itemData(item, KTextEditor:: CodeCompletionModel::Arguments).toString(); | ||||
1125 | } | ||||
1126 | } | ||||
1127 | actualHints.sort(); | ||||
1128 | hints.sort(); | ||||
1129 | QCOMPARE(actualHints, hints); | ||||
1130 | }); | ||||
1120 | } | 1131 | } | ||
1121 | 1132 | | |||
1122 | void TestCodeCompletion::testArgumentHintCompletion_data() | 1133 | void TestCodeCompletion::testArgumentHintCompletion_data() | ||
1123 | { | 1134 | { | ||
1124 | #if CINDEX_VERSION_MINOR < 30 | 1135 | #if CINDEX_VERSION_MINOR < 30 | ||
1125 | QSKIP("You need at least LibClang 3.7"); | 1136 | QSKIP("You need at least LibClang 3.7"); | ||
1126 | #endif | 1137 | #endif | ||
1127 | 1138 | | |||
1128 | QTest::addColumn<QString>("code"); | 1139 | QTest::addColumn<QString>("code"); | ||
1129 | QTest::addColumn<CompletionItems>("expectedItems"); | 1140 | QTest::addColumn<CompletionItems>("expectedItems"); | ||
1141 | QTest::addColumn<QStringList>("hints"); | ||||
1130 | 1142 | | |||
1131 | QTest::newRow("global function") | 1143 | QTest::newRow("global function") | ||
1132 | << "void foo(int);\n" | 1144 | << "void foo(int);\n" | ||
1133 | "int main() { \nfoo( " | 1145 | "int main() { \nfoo( " | ||
1134 | << CompletionItems{{2,4}, { | 1146 | << CompletionItems{{2,4}, { | ||
1135 | "foo", "foo", | 1147 | "foo", "foo", | ||
1136 | "main" | 1148 | "main" | ||
1137 | }}; | 1149 | }} | ||
1150 | << QStringList{"foo(int)"}; | ||||
1138 | 1151 | | |||
1139 | QTest::newRow("member function") | 1152 | QTest::newRow("member function") | ||
1140 | << "struct Struct{ void foo(int);}\n" | 1153 | << "struct Struct{ void foo(int);}\n" | ||
1141 | "int main() {Struct s; \ns.foo( " | 1154 | "int main() {Struct s; \ns.foo( " | ||
1142 | << CompletionItems{{2,6}, { | 1155 | << CompletionItems{{2,6}, { | ||
1143 | "Struct", "foo", | 1156 | "Struct", "foo", | ||
1144 | "main", "s" | 1157 | "main", "s" | ||
1145 | }}; | 1158 | }} | ||
1159 | << QStringList{"foo(int)"}; | ||||
1146 | 1160 | | |||
1147 | QTest::newRow("template function") | 1161 | QTest::newRow("template function") | ||
1148 | << "template <typename T> void foo(T);\n" | 1162 | << "template <typename T> void foo(T);\n" | ||
1149 | "int main() { \nfoo( " | 1163 | "int main() { \nfoo( " | ||
1150 | << CompletionItems{{2,6}, { | 1164 | << CompletionItems{{2,6}, { | ||
1151 | "foo", "foo", | 1165 | "foo", "foo", | ||
1152 | "main" | 1166 | "main" | ||
1153 | }}; | 1167 | }} | ||
1168 | << QStringList{"foo(T)"}; | ||||
1154 | 1169 | | |||
1155 | QTest::newRow("overloaded functions") | 1170 | QTest::newRow("overloaded functions") | ||
1156 | << "void foo(int); void foo(int, double)\n" | 1171 | << "void foo(int); void foo(int, double)\n" | ||
1157 | "int main() { \nfoo( " | 1172 | "int main() { \nfoo( " | ||
1158 | << CompletionItems{{2,6}, { | 1173 | << CompletionItems{{2,6}, { | ||
1159 | "foo", "foo", "foo", "foo", | 1174 | "foo", "foo", "foo", "foo", | ||
1160 | "main" | 1175 | "main" | ||
1161 | }}; | 1176 | }} | ||
1177 | << QStringList{"foo(int)", "foo(int, double)"}; | ||||
1162 | 1178 | | |||
1163 | QTest::newRow("overloaded functions2") | 1179 | QTest::newRow("overloaded functions2") | ||
1164 | << "void foo(int); void foo(int, double)\n" | 1180 | << "void foo(int); void foo(int, double)\n" | ||
1165 | "int main() { foo(1,\n " | 1181 | "int main() { foo(1,\n " | ||
1166 | << CompletionItems{{2,1}, { | 1182 | << CompletionItems{{2,1}, { | ||
1167 | "foo", "foo", "foo", | 1183 | "foo", "foo", "foo", | ||
1168 | "main" | 1184 | "main" | ||
1169 | }}; | 1185 | }} | ||
1186 | << QStringList{"foo(int, double)"}; | ||||
1187 | | ||||
1188 | QTest::newRow("constructor") | ||||
1189 | << "struct foo { foo(int); foo(int, double); }\n" | ||||
1190 | "int main() { foo f(\n " | ||||
1191 | << CompletionItems{{2,1}, { | ||||
1192 | "f", "foo", "foo", "foo", "foo", "foo", | ||||
1193 | "main" | ||||
1194 | }} | ||||
1195 | << QStringList{"foo(int)", "foo(int, double)", "foo(foo &&)", "foo(const foo &)"}; | ||||
1196 | | ||||
1197 | QTest::newRow("constructor2") | ||||
1198 | << "struct foo { foo(int); foo(int, double); }\n" | ||||
1199 | "int main() { foo f(1,\n " | ||||
1200 | << CompletionItems{{2,1}, { | ||||
1201 | "f", "foo", "foo", | ||||
1202 | "main" | ||||
1203 | }} | ||||
1204 | << QStringList{"foo(int, double)"}; | ||||
1170 | } | 1205 | } | ||
1171 | 1206 | | |||
1172 | void TestCodeCompletion::testArgumentHintCompletionDefaultParameters() | 1207 | void TestCodeCompletion::testArgumentHintCompletionDefaultParameters() | ||
1173 | { | 1208 | { | ||
1174 | #if CINDEX_VERSION_MINOR < 30 | 1209 | #if CINDEX_VERSION_MINOR < 30 | ||
1175 | QSKIP("You need at least LibClang 3.7"); | 1210 | QSKIP("You need at least LibClang 3.7"); | ||
1176 | #endif | 1211 | #endif | ||
1177 | 1212 | | |||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |