1- #include < QTest>
21#include " TreeSitterEngine.hpp"
2+ #include < QTest>
33
44// Collect member names returned by findSymbolsGlobal for "prev sep name".
55static QStringList memberNames (TreeSitterEngine &engine, const QString &prev, const QString &sep,
6- const QString &file, int line, int col,
7- const QByteArray &content) {
6+ const QString &file, int line, int col, const QByteArray &content) {
87 auto results = engine.findSymbolsGlobal (" " , false , prev, sep, file, line, col, content);
98 auto names = QStringList{};
109 for (const auto &s : results) {
@@ -30,19 +29,17 @@ class TestTreeSitterEngine : public QObject {
3029
3130 // Icon i; i-> should resolve Icon -> std::shared_ptr<ImageData> -> ImageData members.
3231 void localVarViaTypeAlias_arrow () {
33- const auto header = QByteArrayLiteral (
34- " struct ImageData {\n "
35- " int x;\n "
36- " char data[256];\n "
37- " };\n "
38- " using Icon = std::shared_ptr<ImageData>;\n " );
32+ const auto header = QByteArrayLiteral (" struct ImageData {\n "
33+ " int x;\n "
34+ " char data[256];\n "
35+ " };\n "
36+ " using Icon = std::shared_ptr<ImageData>;\n " );
3937
4038 // source file: local variable inside a function — NOT indexed by cppLightQuery
41- const auto source = QByteArrayLiteral (
42- " void foo() {\n " // line 0
43- " Icon i;\n " // line 1
44- " i->x;\n " // line 2 <- cursor
45- " }\n " );
39+ const auto source = QByteArrayLiteral (" void foo() {\n " // line 0
40+ " Icon i;\n " // line 1
41+ " i->x;\n " // line 2 <- cursor
42+ " }\n " );
4643
4744 TreeSitterEngine engine;
4845 indexHeader (engine, " test.hpp" , header);
@@ -56,18 +53,16 @@ class TestTreeSitterEngine : public QObject {
5653
5754 // Same but via dot accessor — dot on a shared_ptr alias should also yield inner members.
5855 void localVarViaTypeAlias_dot () {
59- const auto header = QByteArrayLiteral (
60- " struct ImageData {\n "
61- " int x;\n "
62- " char data[256];\n "
63- " };\n "
64- " using Icon = std::shared_ptr<ImageData>;\n " );
56+ const auto header = QByteArrayLiteral (" struct ImageData {\n "
57+ " int x;\n "
58+ " char data[256];\n "
59+ " };\n "
60+ " using Icon = std::shared_ptr<ImageData>;\n " );
6561
66- const auto source = QByteArrayLiteral (
67- " void foo() {\n "
68- " Icon i;\n "
69- " i.get();\n " // line 2 <- cursor
70- " }\n " );
62+ const auto source = QByteArrayLiteral (" void foo() {\n "
63+ " Icon i;\n "
64+ " i.get();\n " // line 2 <- cursor
65+ " }\n " );
7166
7267 TreeSitterEngine engine;
7368 indexHeader (engine, " test.hpp" , header);
@@ -92,11 +87,10 @@ class TestTreeSitterEngine : public QObject {
9287 " void foo();\n "
9388 " };\n " );
9489
95- const auto source = QByteArrayLiteral (
96- " void SomeClass::foo() {\n " // line 0
97- " Icon i;\n " // line 1 local shadows class member
98- " i->x;\n " // line 2 <- cursor
99- " }\n " );
90+ const auto source = QByteArrayLiteral (" void SomeClass::foo() {\n " // line 0
91+ " Icon i;\n " // line 1 local shadows class member
92+ " i->x;\n " // line 2 <- cursor
93+ " }\n " );
10094
10195 TreeSitterEngine engine;
10296 indexHeader (engine, " shadow.hpp" , header);
@@ -106,8 +100,7 @@ class TestTreeSitterEngine : public QObject {
106100
107101 QVERIFY2 (names.contains (" x" ),
108102 " Local 'Icon i' should shadow class member 'std::string i' and find x" );
109- QVERIFY2 (!names.contains (" size" ) && !names.contains (" length" ) &&
110- !names.contains (" empty" ),
103+ QVERIFY2 (!names.contains (" size" ) && !names.contains (" length" ) && !names.contains (" empty" ),
111104 " std::string members must not appear — class member must be shadowed" );
112105 }
113106
@@ -118,15 +111,15 @@ class TestTreeSitterEngine : public QObject {
118111 // -----------------------------------------------------------------------
119112 void localStructInSameSourceFile_dot () {
120113 // Everything in one .cpp file — struct members are NOT in the global index.
121- const auto source = QByteArrayLiteral (
122- " struct ImageData {\n " // line 0
123- " int x;\n " // line 1
124- " char data[256];\n " // line 2
125- " };\n " // line 3
126- " void foo() {\n " // line 4
127- " ImageData ii;\n " // line 5 local var, not indexed
128- " ii.x;\n " // line 6 <- cursor
129- " }\n " );
114+ const auto source =
115+ QByteArrayLiteral ( " struct ImageData {\n " // line 0
116+ " int x;\n " // line 1
117+ " char data[256];\n " // line 2
118+ " };\n " // line 3
119+ " void foo() {\n " // line 4
120+ " ImageData ii;\n " // line 5 local var, not indexed
121+ " ii.x;\n " // line 6 <- cursor
122+ " }\n " );
130123
131124 TreeSitterEngine engine;
132125 engine.updateFile (" local.cpp" , source);
@@ -142,38 +135,38 @@ class TestTreeSitterEngine : public QObject {
142135
143136 // Arrow accessor variant of the same scenario.
144137 void localStructInSameSourceFile_arrow () {
145- const auto source = QByteArrayLiteral (
146- " struct ImageData {\n "
147- " int x;\n "
148- " char data[256];\n "
149- " };\n "
150- " void foo() {\n "
151- " ImageData *ii;\n " // line 5
152- " ii->x;\n " // line 6 <- cursor
153- " }\n " );
138+ const auto source = QByteArrayLiteral (" struct ImageData {\n "
139+ " int x;\n "
140+ " char data[256];\n "
141+ " };\n "
142+ " void foo() {\n "
143+ " ImageData *ii;\n " // line 5
144+ " ii->x;\n " // line 6 <- cursor
145+ " }\n " );
154146
155147 TreeSitterEngine engine;
156148 engine.updateFile (" local.cpp" , source);
157149
158150 auto names = memberNames (engine, " ii" , " ->" , " local.cpp" , 6 , 8 , source);
159151 QVERIFY2 (names.contains (" x" ), " Pointer to local struct should find 'x' via temp tree" );
160- QVERIFY2 (names.contains (" data" ), " Pointer to local struct should find 'data' via temp tree" );
152+ QVERIFY2 (names.contains (" data" ),
153+ " Pointer to local struct should find 'data' via temp tree" );
161154 }
162155
163156 // Exact reproduction of the reported failure: struct, alias, and variable all
164157 // inside the same function body, with an extra variable declaration in between.
165158 void localStructAndAliasInsideFunction () {
166- const auto source = QByteArrayLiteral (
167- " void testFn() {\n " // line 0
168- " struct ImageData {\n " // line 1
169- " int x;\n " // line 2
170- " char data[256];\n " // line 3
171- " };\n " // line 4
172- " ImageData ii;\n " // line 5
173- " using Icon = std::shared_ptr<ImageData>;\n " // line 6
174- " Icon i;\n " // line 7
175- " i->x;\n " // line 8 <- cursor
176- " }\n " );
159+ const auto source =
160+ QByteArrayLiteral ( " void testFn() {\n " // line 0
161+ " struct ImageData {\n " // line 1
162+ " int x;\n " // line 2
163+ " char data[256];\n " // line 3
164+ " };\n " // line 4
165+ " ImageData ii;\n " // line 5
166+ " using Icon = std::shared_ptr<ImageData>;\n " // line 6
167+ " Icon i;\n " // line 7
168+ " i->x;\n " // line 8 <- cursor
169+ " }\n " );
177170
178171 TreeSitterEngine engine;
179172 engine.updateFile (" funclocal.cpp" , source);
@@ -187,16 +180,15 @@ class TestTreeSitterEngine : public QObject {
187180
188181 // shared_ptr<T> treated as a transparent pointer: both . and -> yield T's members.
189182 void sharedPtrTreatedAsPointer_sameFile () {
190- const auto source = QByteArrayLiteral (
191- " struct ImageData {\n "
192- " int x;\n "
193- " char data[256];\n "
194- " };\n "
195- " using Icon = std::shared_ptr<ImageData>;\n " // line 4
196- " void foo() {\n " // line 5
197- " Icon i;\n " // line 6
198- " i->x;\n " // line 7 <- cursor
199- " }\n " );
183+ const auto source = QByteArrayLiteral (" struct ImageData {\n "
184+ " int x;\n "
185+ " char data[256];\n "
186+ " };\n "
187+ " using Icon = std::shared_ptr<ImageData>;\n " // line 4
188+ " void foo() {\n " // line 5
189+ " Icon i;\n " // line 6
190+ " i->x;\n " // line 7 <- cursor
191+ " }\n " );
200192
201193 TreeSitterEngine engine;
202194 engine.updateFile (" sameFile.cpp" , source);
0 commit comments