@@ -15,9 +15,7 @@ def setUp(self):
1515 file = self .project .files .get ("main.c" )
1616 assert file is not None
1717 self .file = file
18- function = self .file .function_by_line (11 )
19- assert function is not None
20- self .function = function
18+ self .function = self .file .functions_by_name ("main" )[0 ]
2119
2220 def test_function_create (self ):
2321 function = scubatrace .Function .create (self .function .node , self .function .parent )
@@ -31,7 +29,7 @@ def test_function_callees(self):
3129 self .assertIn ("printf" , [callee .name for callee in callees ])
3230
3331 def test_function_callers (self ):
34- function = self .file .function_by_line (4 )
32+ function = self .file .function_by_line (6 )
3533 self .assertIsNotNone (function )
3634 assert function is not None
3735 callers = function .callers
@@ -43,7 +41,7 @@ def test_function_lines(self):
4341
4442 def test_function_parameter_lines (self ):
4543 self .assertEqual (len (self .function .parameter_lines ), 1 )
46- self .assertEqual (self .function .parameter_lines [0 ], 9 )
44+ self .assertEqual (self .function .parameter_lines [0 ], 11 )
4745
4846 def test_function_parameters (self ):
4947 parameters = self .function .parameters
@@ -58,10 +56,40 @@ def test_function_variables(self):
5856 self .assertEqual (variables [len (variables ) - 1 ].text , "count" )
5957
6058 def test_function_export_cfg_dot (self ):
61- cfg = self .function .export_cfg_dot ("cfg.dot" , with_cdg = True , with_ddg = True )
59+ cfg = self .function .export_cfg_dot (
60+ f"{ self .project_path } /{ self .function .name } .dot" ,
61+ with_cdg = True ,
62+ with_ddg = True ,
63+ )
6264 self .assertIsNotNone (cfg )
6365
6466 def test_function_slicing_by_lines (self ):
65- stats = self .function .slice_by_lines ([14 ])
66- self .assertEqual (stats [0 ].start_line , 9 )
67- self .assertEqual (stats [len (stats ) - 1 ].start_line , 38 )
67+ stats = self .function .slice_by_lines ([16 ])
68+ self .assertEqual (stats [0 ].start_line , 11 )
69+ self .assertEqual (stats [len (stats ) - 1 ].start_line , second = 40 )
70+
71+ def test_function_walk_backward (self ):
72+ function = self .file .functions_by_name ("add" )[0 ]
73+ assert function is not None
74+ functions = list (function .walk_backward ())
75+ self .assertEqual (len (functions ), 3 )
76+ functions_start_lines = sorted ([f .start_line for f in functions ])
77+ self .assertEqual (functions_start_lines , [6 , 11 , 51 ])
78+
79+ def test_function_walk_forward (self ):
80+ functions = list (self .function .walk_forward ())
81+ self .assertGreater (len (functions ), 0 )
82+ functions_start_lines = sorted ([f .start_line for f in functions ])
83+ self .assertIn (11 , functions_start_lines )
84+ self .assertIn (6 , functions_start_lines )
85+ self .assertIn (51 , functions_start_lines )
86+
87+ def test_function_export_callgraph (self ):
88+ function = self .file .functions_by_name ("add" )[0 ]
89+ callgraph = function .export_callgraph (
90+ f"{ self .project_path } /{ function .name } _callgraph.dot" ,
91+ depth = 1 ,
92+ )
93+ self .assertIsNotNone (callgraph )
94+ self .assertGreater (len (callgraph .nodes ), 0 )
95+ self .assertGreater (len (callgraph .edges ), 0 )
0 commit comments