aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2020-08-10 18:10:28 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2020-08-14 13:21:36 +0000
commit414561e4ccdc1a4a110234848b338c7bb78c4df5 (patch)
treea6bddd73d2c454677857c5c6e19e5ed3e2c6e78a /src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
parent5183994a3081005e83a9e4691208cf3c44a1fc22 (diff)
CppTools: More consistent fuzzy matching behavior
There were annoying inconsistencies, for instance: - A not fully matching declaration was found from the definition, but not vice versa. - An implementation MyClass::foo(int) would fall back to a declaration foo(), but an implementation MyClass::foo() would not fall back to a declaration foo(int). These cases behave consistently now. To this end, the clang code model now forwards to the built-in code model if a function lookup has failed. Fuzzy matching for free functions has been limited, as the cons appear to outweigh the pros. For instance: void foo(int); void foo(double) {} Following the definition would lead to the non-matching declaration, which the user most likely does not want. As a side effect, redundant code has been removed in the SymbolFinder class. Fixes: QTCREATORBUG-20279 Change-Id: Ib97d6710c7e12fb0fdbc30b51a0067e09bfc2190 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp')
-rw-r--r--src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp76
1 files changed, 72 insertions, 4 deletions
diff --git a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
index 8bbb010422..7532b77e8d 100644
--- a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
+++ b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
@@ -935,6 +935,16 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_data()
"void Foo::foo(int) {}\n"
);
+ QTest::newRow("matchFunctionSignature_Follow_3.5") << _(
+ "void foo(int);\n"
+ "void @$foo() {}\n"
+ );
+
+ QTest::newRow("matchFunctionSignature_Follow_3.6") << _(
+ "void foo(int);\n"
+ "void @$foo(double) {}\n"
+ );
+
QTest::newRow("matchFunctionSignature_Follow_4") << _(
"class Foo {\n"
" void foo(int);\n"
@@ -963,17 +973,33 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_data()
"void Foo::@foo(int) {}\n"
);
- QTest::newRow("matchFunctionSignature_Follow_8") << _(
+ QTest::newRow("matchFunctionSignature_Follow_8_fuzzy") << _(
"class Foo {\n"
- " void @$foo(int *);\n"
+ " void @foo(int *);\n"
+ "};\n"
+ "void Foo::$foo(const int *) {}\n"
+ );
+
+ QTest::newRow("matchFunctionSignature_Follow_8_exact") << _(
+ "class Foo {\n"
+ " void @foo(int *);\n"
"};\n"
"void Foo::foo(const int *) {}\n"
+ "void Foo::$foo(int *) {}\n"
);
- QTest::newRow("matchFunctionSignature_Follow_9") << _(
+ QTest::newRow("matchFunctionSignature_Follow_9_fuzzy") << _(
"class Foo {\n"
- " void @$foo(int&);\n"
+ " void @foo(int&);\n"
"};\n"
+ "void Foo::$foo(const int&) {}\n"
+ );
+
+ QTest::newRow("matchFunctionSignature_Follow_9_exact") << _(
+ "class Foo {\n"
+ " void @foo(int&);\n"
+ "};\n"
+ "void Foo::$foo(int&) {}\n"
"void Foo::foo(const int&) {}\n"
);
@@ -1171,6 +1197,48 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_multipleDocuments_data()
"foo.cpp")
);
+ QTest::newRow("matchFunctionSignatureFuzzy1Forward") << (QList<TestDocumentPtr>()
+ << TestDocument::create("class Foo {\n"
+ " void @foo(int);\n"
+ " void foo();\n"
+ "};\n",
+ "foo.h")
+ << TestDocument::create("#include \"foo.h\"\n"
+ "void Foo::$foo() {}\n",
+ "foo.cpp")
+ );
+
+ QTest::newRow("matchFunctionSignatureFuzzy1Backward") << (QList<TestDocumentPtr>()
+ << TestDocument::create("class Foo {\n"
+ " void $foo(int);\n"
+ "};\n",
+ "foo.h")
+ << TestDocument::create("#include \"foo.h\"\n"
+ "void Foo::@foo() {}\n",
+ "foo.cpp")
+ );
+
+ QTest::newRow("matchFunctionSignatureFuzzy2Forward") << (QList<TestDocumentPtr>()
+ << TestDocument::create("class Foo {\n"
+ " void foo(int);\n"
+ " void @foo();\n"
+ "};\n",
+ "foo.h")
+ << TestDocument::create("#include \"foo.h\"\n"
+ "void Foo::$foo(int) {}\n",
+ "foo.cpp")
+ );
+
+ QTest::newRow("matchFunctionSignatureFuzzy2Backward") << (QList<TestDocumentPtr>()
+ << TestDocument::create("class Foo {\n"
+ " void $foo();\n"
+ "};\n",
+ "foo.h")
+ << TestDocument::create("#include \"foo.h\"\n"
+ "void Foo::@foo(int) {}\n",
+ "foo.cpp")
+ );
+
QTest::newRow("globalVar") << QList<TestDocumentPtr>{
TestDocument::create("namespace NS { extern int @globalVar; }\n", "file.h"),
TestDocument::create(