@@ -9,6 +9,7 @@ use stack_graphs::graph::StackGraph;
99use tree_sitter_graph:: Variables ;
1010use tree_sitter_stack_graphs:: NoCancellation ;
1111use tree_sitter_stack_graphs:: StackGraphLanguage ;
12+ use tree_sitter_stack_graphs:: FILE_PATH_VAR ;
1213
1314use crate :: edges:: check_stack_graph_edges;
1415use crate :: nodes:: check_stack_graph_nodes;
@@ -22,12 +23,18 @@ fn can_support_preexisting_nodes() {
2223 "# ;
2324 let python = "pass" ;
2425
26+ let file_name = "test.py" ;
27+
2528 let mut graph = StackGraph :: new ( ) ;
26- let file = graph. get_or_create_file ( "test.py" ) ;
29+ let file = graph. get_or_create_file ( file_name ) ;
2730 let node_id = graph. new_node_id ( file) ;
2831 let _preexisting_node = graph. add_scope_node ( node_id, true ) . unwrap ( ) ;
2932
30- let globals = Variables :: new ( ) ;
33+ let mut globals = Variables :: new ( ) ;
34+ globals
35+ . add ( FILE_PATH_VAR . into ( ) , file_name. into ( ) )
36+ . expect ( "failed to add file path variable" ) ;
37+
3138 let language = StackGraphLanguage :: from_str ( tree_sitter_python:: language ( ) , tsg) . unwrap ( ) ;
3239 language
3340 . build_stack_graph_into ( & mut graph, file, python, & globals, & NoCancellation )
@@ -45,15 +52,21 @@ fn can_support_injected_nodes() {
4552 "# ;
4653 let python = "pass" ;
4754
55+ let file_name = "test.py" ;
56+
4857 let mut graph = StackGraph :: new ( ) ;
49- let file = graph. get_or_create_file ( "test.py" ) ;
58+ let file = graph. get_or_create_file ( file_name ) ;
5059 let node_id = graph. new_node_id ( file) ;
5160 let _preexisting_node = graph. add_scope_node ( node_id, true ) . unwrap ( ) ;
5261
5362 let language = StackGraphLanguage :: from_str ( tree_sitter_python:: language ( ) , tsg) . unwrap ( ) ;
5463 let mut builder = language. builder_into_stack_graph ( & mut graph, file, python) ;
5564
5665 let mut globals = Variables :: new ( ) ;
66+ globals
67+ . add ( FILE_PATH_VAR . into ( ) , file_name. into ( ) )
68+ . expect ( "failed to add file path variable" ) ;
69+
5770 globals
5871 . add ( "EXT_NODE" . into ( ) , builder. inject_node ( node_id) . into ( ) )
5972 . expect ( "Failed to add EXT_NODE variable" ) ;
0 commit comments