MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeText-parser / Test_CppParser

Class Test_CppParser

tests/test_parser/test_cpp.py:10–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class Test_CppParser(unittest.TestCase):
11 def setUp(self) -> None:
12 with open('tests/test_parser/test_sample/cpp_test_sample.cpp', 'r') as file:
13 self.code_sample = file.read()
14
15 tree = parse_code(self.code_sample, 'c++')
16 self.root_node = tree.root_node
17
18 return super().setUp()
19
20 def test_get_function_list(self):
21 root = self.root_node
22
23 function_list = CppParser.get_function_list(root)
24
25 self.assertEqual(len(function_list), 3)
26
27 def test_get_class_list(self):
28 root = self.root_node
29
30 class_list = CppParser.get_class_list(root)
31
32 self.assertEqual(len(class_list), 2)
33
34 def test_get_function_metadata(self):
35 root = self.root_node
36
37 function = list(CppParser.get_function_list(root))[0]
38 metadata = CppParser.get_function_metadata(function)
39
40 for key in ['identifier', 'parameters', 'return_type']:
41 self.assertTrue(key in metadata.keys(), "Missing {}".format(key))
42 self.assertEqual(metadata['parameters'], {'a': 'int', 'b': 'int'})
43 self.assertEqual(metadata['identifier'], 'sum2number')
44 self.assertEqual(metadata['return_type'], 'int')
45
46 def test_get_class_metadata(self):
47 root = self.root_node
48
49 classes = list(CppParser.get_class_list(root))[0]
50 metadata = CppParser.get_class_metadata(classes)
51
52 self.assertEqual(metadata['parameters'], {'Vehicle': None, 'B': None})
53 self.assertEqual(metadata['identifier'], 'Car')
54
55 def test_get_docstring(self):
56 code_sample = """
57 /**
58 * Find 2 sum
59 *
60 * @param nums List number.
61 * @param target Sum target.
62 * @return postion of 2 number.
63 */
64 vector<int> twoSum(vector<int>& nums, int target) {
65 map<int,int> m;
66 vector<int> v;
67 int n= nums.size();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected