Repository navigation
Expand file tree
/
Copy pathtest_cpp_basic_syntax.py
More file actions
967 lines (776 loc) · 24.7 KB
/
Copy pathtest_cpp_basic_syntax.py
File metadata and controls
967 lines (776 loc) · 24.7 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
"""
Comprehensive C++ basic syntax parsing and relationship testing.
Tests basic C++ class definitions, function declarations, namespaces, and method relationships.
"""
from pathlib import Path
from typing import cast
from unittest.mock import MagicMock
import pytest
from codebase_rag.graph_updater import GraphUpdater
from codebase_rag.parser_loader import load_parsers
@pytest.fixture
def cpp_basic_project(temp_repo: Path) -> Path:
"""Create a comprehensive C++ project with basic syntax patterns."""
project_path = temp_repo / "cpp_basic_test"
project_path.mkdir()
# Create basic structure
(project_path / "src").mkdir()
(project_path / "include").mkdir()
(project_path / "lib").mkdir()
# Create base files
(project_path / "src" / "main.cpp").write_text("int main() { return 0; }")
(project_path / "include" / "base.h").write_text("#pragma once\nclass Base {};")
return project_path
def test_basic_class_declarations(
cpp_basic_project: Path,
mock_ingestor: MagicMock,
) -> None:
"""Test basic C++ class declaration parsing."""
test_file = cpp_basic_project / "basic_classes.cpp"
test_file.write_text(
"""
// Basic class declaration
class Person {
private:
std::string name;
int age;
public:
Person(const std::string& name, int age);
~Person();
void setName(const std::string& name);
std::string getName() const;
void setAge(int age);
int getAge() const;
void greet() const;
};
// Class with static members
class MathUtils {
public:
static const double PI;
static int instanceCount;
static double add(double a, double b);
static double multiply(double a, double b);
static double calculateCircleArea(double radius);
MathUtils();
~MathUtils();
private:
static void incrementCount();
};
// Struct definition (class in C++)
struct Point {
double x, y;
Point();
Point(double x, double y);
double distance(const Point& other) const;
Point operator+(const Point& other) const;
};
// Class with member functions
class Rectangle {
public:
Rectangle(double width, double height);
double getWidth() const { return width_; }
double getHeight() const { return height_; }
double area() const;
double perimeter() const;
void resize(double width, double height);
bool isSquare() const;
private:
double width_;
double height_;
void validateDimensions();
};
// Enum class (C++11)
enum class Color {
RED,
GREEN,
BLUE,
YELLOW
};
// Traditional enum
enum Status {
ACTIVE,
INACTIVE,
PENDING
};
// Using classes and functions
void demonstrateClasses() {
Person person("Alice", 30);
person.greet();
double sum = MathUtils::add(5.0, 3.0);
double area = MathUtils::calculateCircleArea(10.0);
Point p1(0, 0);
Point p2(3, 4);
double dist = p1.distance(p2);
Point p3 = p1 + p2;
Rectangle rect(10.0, 20.0);
double rectArea = rect.area();
bool isSquare = rect.isSquare();
Color color = Color::RED;
Status status = ACTIVE;
}
"""
)
parsers, queries = load_parsers()
updater = GraphUpdater(
ingestor=mock_ingestor,
repo_path=cpp_basic_project,
parsers=parsers,
queries=queries,
)
updater.run()
project_name = cpp_basic_project.name
# Expected class definitions
expected_classes = [
f"{project_name}.basic_classes.Person",
f"{project_name}.basic_classes.MathUtils",
f"{project_name}.basic_classes.Point",
f"{project_name}.basic_classes.Rectangle",
]
# Get all Class node creation calls
class_calls = [
call
for call in mock_ingestor.ensure_node_batch.call_args_list
if call[0][0] == "Class"
]
created_classes = {call[0][1]["qualified_name"] for call in class_calls}
# Verify all expected classes were created
for expected_qn in expected_classes:
assert expected_qn in created_classes, f"Missing class: {expected_qn}"
# Expected method definitions (class methods)
expected_methods = [
f"{project_name}.basic_classes.Person.Person", # constructor
f"{project_name}.basic_classes.Person.setName",
f"{project_name}.basic_classes.Person.getName",
f"{project_name}.basic_classes.Person.greet",
f"{project_name}.basic_classes.MathUtils.add",
f"{project_name}.basic_classes.MathUtils.calculateCircleArea",
f"{project_name}.basic_classes.Point.distance",
f"{project_name}.basic_classes.Rectangle.area",
]
# Expected free function definitions
expected_functions = [
f"{project_name}.basic_classes.demonstrateClasses",
]
# Get all Method node creation calls
method_calls = [
call
for call in mock_ingestor.ensure_node_batch.call_args_list
if call[0][0] == "Method"
]
# Get all Function node creation calls
function_calls = [
call
for call in mock_ingestor.ensure_node_batch.call_args_list
if call[0][0] == "Function"
]
created_methods = {call[0][1]["qualified_name"] for call in method_calls}
created_functions = {call[0][1]["qualified_name"] for call in function_calls}
# Verify all expected methods were created
missing_methods = set(expected_methods) - created_methods
assert not missing_methods, (
f"Missing expected methods: {sorted(list(missing_methods))}"
)
# Verify all expected functions were created
missing_functions = set(expected_functions) - created_functions
assert not missing_functions, (
f"Missing expected functions: {sorted(list(missing_functions))}"
)
def test_basic_function_declarations(
cpp_basic_project: Path,
mock_ingestor: MagicMock,
) -> None:
"""Test basic C++ function declaration parsing."""
test_file = cpp_basic_project / "basic_functions.cpp"
test_file.write_text(
"""
#include <iostream>
#include <string>
#include <vector>
// Global function declarations
int add(int a, int b);
double multiply(double x, double y);
void printMessage(const std::string& message);
// Function with default parameters
void greet(const std::string& name = "World");
// Function overloading
int max(int a, int b);
double max(double a, double b);
std::string max(const std::string& a, const std::string& b);
// Template function declaration
template<typename T>
T minimum(T a, T b);
// Function with complex return types
std::vector<int> createRange(int start, int end);
const std::string& getLongestString(const std::vector<std::string>& strings);
// Function implementations
int add(int a, int b) {
return a + b;
}
double multiply(double x, double y) {
return x * y;
}
void printMessage(const std::string& message) {
std::cout << message << std::endl;
}
void greet(const std::string& name) {
printMessage("Hello, " + name + "!");
}
int max(int a, int b) {
return (a > b) ? a : b;
}
double max(double a, double b) {
return (a > b) ? a : b;
}
std::string max(const std::string& a, const std::string& b) {
return (a > b) ? a : b;
}
template<typename T>
T minimum(T a, T b) {
return (a < b) ? a : b;
}
std::vector<int> createRange(int start, int end) {
std::vector<int> result;
for (int i = start; i <= end; ++i) {
result.push_back(i);
}
return result;
}
// Function with function calls
void demonstrateFunctions() {
int sum = add(10, 20);
double product = multiply(3.14, 2.0);
printMessage("Demonstrating functions");
greet("C++");
int maxInt = max(100, 200);
double maxDouble = max(1.5, 2.7);
auto minVal = minimum<int>(5, 10);
std::vector<int> range = createRange(1, 10);
}
"""
)
parsers, queries = load_parsers()
updater = GraphUpdater(
ingestor=mock_ingestor,
repo_path=cpp_basic_project,
parsers=parsers,
queries=queries,
)
updater.run()
project_name = cpp_basic_project.name
# Expected function definitions
expected_functions = [
f"{project_name}.basic_functions.add",
f"{project_name}.basic_functions.multiply",
f"{project_name}.basic_functions.printMessage",
f"{project_name}.basic_functions.greet",
f"{project_name}.basic_functions.max", # overloaded functions
f"{project_name}.basic_functions.minimum",
f"{project_name}.basic_functions.createRange",
f"{project_name}.basic_functions.demonstrateFunctions",
]
# Get all Function node creation calls
function_calls = [
call
for call in mock_ingestor.ensure_node_batch.call_args_list
if call[0][0] == "Function"
]
created_functions = {call[0][1]["qualified_name"] for call in function_calls}
# Verify at least some expected functions were created
missing_functions = set(expected_functions) - created_functions
assert not missing_functions, (
f"Missing expected functions: {sorted(list(missing_functions))}"
)
# Verify function calls are tracked
call_relationships = [
c
for c in cast(MagicMock, mock_ingestor.ensure_relationship_batch).call_args_list
if c.args[1] == "CALLS"
]
function_calls_relationships = [
call
for call in call_relationships
if "basic_functions" in call.args[0][2]
and any(
func_name in call.args[2][2]
for func_name in ["add", "multiply", "printMessage", "greet", "max"]
)
]
assert len(function_calls_relationships) >= 3, (
f"Expected at least 3 function call relationships, found {len(function_calls_relationships)}"
)
def test_basic_namespaces(
cpp_basic_project: Path,
mock_ingestor: MagicMock,
) -> None:
"""Test basic C++ namespace parsing and qualified names."""
test_file = cpp_basic_project / "basic_namespaces.cpp"
test_file.write_text(
"""
// Global namespace functions
void globalFunction();
// Basic namespace
namespace utils {
void printDebug(const std::string& message);
class Logger {
public:
static void log(const std::string& message);
void info(const std::string& message);
void error(const std::string& message);
};
namespace math {
const double PI = 3.14159;
double add(double a, double b);
double subtract(double a, double b);
class Calculator {
public:
double compute(double a, double b, char op);
void reset();
private:
double result_;
};
}
}
// Another namespace
namespace graphics {
struct Point {
double x, y;
Point(double x = 0, double y = 0);
};
struct Color {
int r, g, b;
Color(int r = 0, int g = 0, int b = 0);
};
class Shape {
public:
Shape(const Point& position);
virtual ~Shape();
virtual double area() const = 0;
virtual void draw() const = 0;
Point getPosition() const;
void setPosition(const Point& pos);
protected:
Point position_;
};
class Circle : public Shape {
public:
Circle(const Point& center, double radius);
double area() const override;
void draw() const override;
double getRadius() const;
private:
double radius_;
};
}
// Using namespace declarations and qualified names
void demonstrateNamespaces() {
// Qualified names
utils::printDebug("Debug message");
utils::Logger logger;
logger.info("Info message");
utils::Logger::log("Static log message");
// Nested namespace access
double sum = utils::math::add(10.0, 20.0);
utils::math::Calculator calc;
double result = calc.compute(5.0, 3.0, '+');
// Different namespace
graphics::Point origin(0, 0);
graphics::Color red(255, 0, 0);
graphics::Circle circle(origin, 5.0);
double area = circle.area();
circle.draw();
}
// Using directive
using namespace utils;
using utils::math::Calculator;
void demonstrateUsingDirectives() {
printDebug("Using directive test");
Logger logger;
logger.error("Error message");
Calculator calc;
calc.reset();
}
"""
)
parsers, queries = load_parsers()
updater = GraphUpdater(
ingestor=mock_ingestor,
repo_path=cpp_basic_project,
parsers=parsers,
queries=queries,
)
updater.run()
project_name = cpp_basic_project.name
# Expected classes in namespaces
expected_classes = [
f"{project_name}.basic_namespaces.utils.Logger",
f"{project_name}.basic_namespaces.utils.math.Calculator",
f"{project_name}.basic_namespaces.graphics.Point",
f"{project_name}.basic_namespaces.graphics.Shape",
f"{project_name}.basic_namespaces.graphics.Circle",
]
# Get all Class node creation calls
class_calls = [
call
for call in mock_ingestor.ensure_node_batch.call_args_list
if call[0][0] == "Class"
]
created_classes = {call[0][1]["qualified_name"] for call in class_calls}
# Verify at least some expected namespaced classes were created
missing_classes = set(expected_classes) - created_classes
assert not missing_classes, (
f"Missing expected classes: {sorted(list(missing_classes))}"
)
# Expected methods in namespaces (class methods)
expected_methods = [
f"{project_name}.basic_namespaces.graphics.Circle.area",
]
# Expected free functions in namespaces
expected_functions = [
f"{project_name}.basic_namespaces.globalFunction",
f"{project_name}.basic_namespaces.utils.printDebug",
f"{project_name}.basic_namespaces.utils.math.add",
f"{project_name}.basic_namespaces.demonstrateNamespaces",
]
# Get all Method node creation calls
method_calls = [
call
for call in mock_ingestor.ensure_node_batch.call_args_list
if call[0][0] == "Method"
]
# Get all Function node creation calls
function_calls = [
call
for call in mock_ingestor.ensure_node_batch.call_args_list
if call[0][0] == "Function"
]
created_methods = {call[0][1]["qualified_name"] for call in method_calls}
created_functions = {call[0][1]["qualified_name"] for call in function_calls}
# Verify expected methods were created
missing_methods = set(expected_methods) - created_methods
assert not missing_methods, (
f"Missing expected methods: {sorted(list(missing_methods))}"
)
# Verify expected functions were created
missing_functions = set(expected_functions) - created_functions
assert not missing_functions, (
f"Missing expected functions: {sorted(list(missing_functions))}"
)
def test_basic_member_functions(
cpp_basic_project: Path,
mock_ingestor: MagicMock,
) -> None:
"""Test C++ member function calls and method relationships."""
test_file = cpp_basic_project / "member_functions.cpp"
test_file.write_text(
"""
class BankAccount {
private:
double balance_;
std::string accountNumber_;
public:
BankAccount(const std::string& accountNumber, double initialBalance = 0.0);
~BankAccount();
// Accessor methods
double getBalance() const;
std::string getAccountNumber() const;
// Mutator methods
void deposit(double amount);
bool withdraw(double amount);
void transfer(BankAccount& toAccount, double amount);
// Utility methods
void printStatement() const;
bool isOverdrawn() const;
private:
void validateAmount(double amount) const;
void updateBalance(double newBalance);
};
class SavingsAccount : public BankAccount {
private:
double interestRate_;
public:
SavingsAccount(const std::string& accountNumber,
double initialBalance = 0.0,
double interestRate = 0.01);
// Override methods
void printStatement() const override;
// New methods
void calculateInterest();
double getInterestRate() const;
void setInterestRate(double rate);
private:
void compoundInterest();
};
// Implementation with method calls
BankAccount::BankAccount(const std::string& accountNumber, double initialBalance)
: accountNumber_(accountNumber), balance_(initialBalance) {
validateAmount(initialBalance);
}
void BankAccount::deposit(double amount) {
validateAmount(amount);
updateBalance(balance_ + amount);
printStatement();
}
bool BankAccount::withdraw(double amount) {
validateAmount(amount);
if (balance_ >= amount) {
updateBalance(balance_ - amount);
printStatement();
return true;
}
return false;
}
void BankAccount::transfer(BankAccount& toAccount, double amount) {
if (withdraw(amount)) {
toAccount.deposit(amount);
}
}
void SavingsAccount::calculateInterest() {
double interest = getBalance() * interestRate_;
deposit(interest);
compoundInterest();
}
// Function demonstrating method calls
void bankingDemo() {
BankAccount checking("CHK-001", 1000.0);
SavingsAccount savings("SAV-001", 5000.0, 0.025);
// Method calls on objects
double checkingBalance = checking.getBalance();
checking.deposit(500.0);
bool success = checking.withdraw(200.0);
// Method calls on different object types
double savingsBalance = savings.getBalance();
savings.calculateInterest();
savings.setInterestRate(0.03);
// Transfer between accounts
checking.transfer(savings, 300.0);
// Polymorphic method calls
BankAccount* account = &savings;
account->printStatement(); // Calls SavingsAccount::printStatement
}
"""
)
parsers, queries = load_parsers()
updater = GraphUpdater(
ingestor=mock_ingestor,
repo_path=cpp_basic_project,
parsers=parsers,
queries=queries,
)
updater.run()
project_name = cpp_basic_project.name
# Expected classes
expected_classes = [
f"{project_name}.member_functions.BankAccount",
f"{project_name}.member_functions.SavingsAccount",
]
# Get all Class node creation calls
class_calls = [
call
for call in mock_ingestor.ensure_node_batch.call_args_list
if call[0][0] == "Class"
]
created_classes = {call[0][1]["qualified_name"] for call in class_calls}
# Verify expected classes were created
for expected_qn in expected_classes:
assert expected_qn in created_classes, f"Missing class: {expected_qn}"
# Verify inheritance relationship
relationship_calls = [
call
for call in mock_ingestor.ensure_relationship_batch.call_args_list
if len(call[0]) >= 3 and call[0][1] == "INHERITS"
]
inheritance_found = any(
"SavingsAccount" in call[0][0][2] and "BankAccount" in call[0][2][2]
for call in relationship_calls
)
assert inheritance_found, (
"Expected inheritance relationship SavingsAccount -> BankAccount"
)
# Verify method calls are tracked
call_relationships = [
c
for c in cast(MagicMock, mock_ingestor.ensure_relationship_batch).call_args_list
if c.args[1] == "CALLS"
]
method_call_relationships = [
call
for call in call_relationships
if "member_functions" in call.args[0][2]
and any(
method_name in call.args[2][2]
for method_name in [
"deposit",
"withdraw",
"getBalance",
"transfer",
"calculateInterest",
]
)
]
assert len(method_call_relationships) >= 5, (
f"Expected at least 5 method call relationships, found {len(method_call_relationships)}"
)
def test_cpp_basic_comprehensive(
cpp_basic_project: Path,
mock_ingestor: MagicMock,
) -> None:
"""Comprehensive test ensuring all basic C++ patterns create proper relationships."""
test_file = cpp_basic_project / "comprehensive_basic.cpp"
test_file.write_text(
"""
// Every basic C++ pattern in one file
#include <iostream>
#include <string>
#include <vector>
// Forward declarations
class Vehicle;
void globalUtility();
// Basic namespace
namespace app {
// Global function in namespace
void initialize();
// Basic class
class Animal {
protected:
std::string name_;
public:
Animal(const std::string& name);
virtual ~Animal();
virtual void speak() const = 0;
std::string getName() const;
void setName(const std::string& name);
};
// Inheritance
class Dog : public Animal {
private:
std::string breed_;
public:
Dog(const std::string& name, const std::string& breed);
void speak() const override;
void fetch() const;
std::string getBreed() const;
};
// Static members
class Counter {
private:
static int count_;
int value_;
public:
Counter();
static int getCount();
static void resetCount();
void increment();
int getValue() const;
};
// Struct (public class)
struct Point {
double x, y;
Point(double x = 0, double y = 0);
double distance(const Point& other) const;
};
}
// Implementation
namespace app {
Animal::Animal(const std::string& name) : name_(name) {}
void Animal::setName(const std::string& name) {
name_ = name;
}
std::string Animal::getName() const {
return name_;
}
Dog::Dog(const std::string& name, const std::string& breed)
: Animal(name), breed_(breed) {}
void Dog::speak() const {
std::cout << getName() << " barks!" << std::endl;
}
void Dog::fetch() const {
std::cout << getName() << " fetches the ball!" << std::endl;
}
int Counter::count_ = 0;
Counter::Counter() : value_(0) {
count_++;
}
int Counter::getCount() {
return count_;
}
void Counter::increment() {
value_++;
}
}
// Using all patterns
void demonstrateBasicCpp() {
app::initialize();
// Object creation and method calls
app::Dog dog("Buddy", "Golden Retriever");
dog.speak(); // Virtual function call
dog.fetch(); // Regular method call
std::string name = dog.getName(); // Inherited method
dog.setName("Max"); // Inherited method
// Static method calls
int count1 = app::Counter::getCount();
app::Counter counter1;
app::Counter counter2;
counter1.increment();
counter2.increment();
int count2 = app::Counter::getCount();
// Struct usage
app::Point p1(0, 0);
app::Point p2(3, 4);
double dist = p1.distance(p2);
// Polymorphic usage
app::Animal* animal = &dog;
animal->speak(); // Virtual call through pointer
globalUtility();
}
void globalUtility() {
std::cout << "Global utility function called" << std::endl;
}
"""
)
parsers, queries = load_parsers()
updater = GraphUpdater(
ingestor=mock_ingestor,
repo_path=cpp_basic_project,
parsers=parsers,
queries=queries,
)
updater.run()
# Verify all relationship types exist
all_relationships = cast(
MagicMock, mock_ingestor.ensure_relationship_batch
).call_args_list
call_relationships = [c for c in all_relationships if c.args[1] == "CALLS"]
defines_relationships = [c for c in all_relationships if c.args[1] == "DEFINES"]
inherits_relationships = [c for c in all_relationships if c.args[1] == "INHERITS"]
# Should have comprehensive basic C++ coverage
comprehensive_calls = [
call for call in call_relationships if "comprehensive_basic" in call.args[0][2]
]
assert len(comprehensive_calls) >= 8, (
f"Expected at least 8 comprehensive basic calls, found {len(comprehensive_calls)}"
)
# Should have inheritance relationships
basic_inheritance = [
call
for call in inherits_relationships
if "comprehensive_basic" in call.args[0][2]
]
assert len(basic_inheritance) >= 1, (
f"Expected at least 1 inheritance relationship, found {len(basic_inheritance)}"
)
# Verify relationship structure
for relationship in comprehensive_calls:
assert len(relationship.args) == 3, "Call relationship should have 3 args"
assert relationship.args[1] == "CALLS", "Second arg should be 'CALLS'"
source_module = relationship.args[0][2]
target_module = relationship.args[2][2]
# Source should be our test module
assert "comprehensive_basic" in source_module, (
f"Source module should contain test file name: {source_module}"
)
# Target should be a valid module name or function
assert isinstance(target_module, str) and target_module, (
f"Target should be non-empty string: {target_module}"
)
# Test that C++ parsing doesn't interfere with other relationships
assert defines_relationships, "Should still have DEFINES relationships"