Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit ac8f6fb

Browse files
author
Hendrik van Antwerpen
committed
Cleanup test with helpers
1 parent a127010 commit ac8f6fb

File tree

2 files changed

+43
-34
lines changed

2 files changed

+43
-34
lines changed

stack-graphs/tests/it/partial.rs

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -517,41 +517,18 @@ fn can_create_partial_path_from_node() {
517517
fn can_append_partial_paths() -> Result<(), PathResolutionError> {
518518
let mut graph = StackGraph::new();
519519
let file = graph.add_file("test").expect("");
520-
521520
let jump_to_scope_node = StackGraph::jump_to_node();
522-
523-
let scope0_id = graph.new_node_id(file);
524-
let scope0 = graph.add_scope_node(scope0_id, false).unwrap();
525-
526-
let scope1_id = graph.new_node_id(file);
527-
let scope1 = graph.add_scope_node(scope1_id, false).unwrap();
528-
529-
let foo = graph.add_symbol("foo");
530-
let foo_ref_id = graph.new_node_id(file);
531-
let foo_ref = graph.add_push_symbol_node(foo_ref_id, foo, false).unwrap();
532-
let foo_def_id = graph.new_node_id(file);
533-
let foo_def = graph.add_pop_symbol_node(foo_def_id, foo, false).unwrap();
534-
535-
let bar = graph.add_symbol("bar");
536-
let bar_ref_id = graph.new_node_id(file);
537-
let bar_ref = graph.add_push_symbol_node(bar_ref_id, bar, false).unwrap();
538-
let bar_def_id = graph.new_node_id(file);
539-
let bar_def = graph.add_pop_symbol_node(bar_def_id, bar, false).unwrap();
540-
541-
let exported_scope_id = graph.new_node_id(file);
542-
graph.add_scope_node(exported_scope_id, true);
543-
let baz = graph.add_symbol("baz");
544-
let baz_ref_id = graph.new_node_id(file);
545-
let baz_ref = graph
546-
.add_push_scoped_symbol_node(baz_ref_id, baz, exported_scope_id, false)
547-
.unwrap();
548-
let baz_def_id = graph.new_node_id(file);
549-
let baz_def = graph
550-
.add_pop_scoped_symbol_node(baz_def_id, baz, false)
551-
.unwrap();
552-
553-
let drop_scopes_id = graph.new_node_id(file);
554-
let drop_scopes = graph.add_drop_scopes_node(drop_scopes_id).unwrap();
521+
let scope0 = create_scope_node(&mut graph, file, false);
522+
let scope1 = create_scope_node(&mut graph, file, false);
523+
let foo_ref = create_push_symbol_node(&mut graph, file, "foo", false);
524+
let foo_def = create_pop_symbol_node(&mut graph, file, "foo", false);
525+
let bar_ref = create_push_symbol_node(&mut graph, file, "bar", false);
526+
let bar_def = create_pop_symbol_node(&mut graph, file, "bar", false);
527+
let exported_scope = create_scope_node(&mut graph, file, true);
528+
let exported_scope_id = graph[exported_scope].id();
529+
let baz_ref = create_push_scoped_symbol_node(&mut graph, file, "baz", exported_scope_id, false);
530+
let baz_def = create_pop_scoped_symbol_node(&mut graph, file, "baz", false);
531+
let drop_scopes = create_drop_scopes_node(&mut graph, file);
555532

556533
fn run(
557534
graph: &StackGraph,

stack-graphs/tests/it/util.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ pub(crate) type NiceScopedSymbol<'a> = (&'a str, Option<NiceScopeStack<'a>>);
2626
pub(crate) type NiceScopeStack<'a> = (&'a [u32], Option<ScopeStackVariable>);
2727
pub(crate) type NicePartialPath<'a> = &'a [Handle<Node>];
2828

29+
pub(crate) fn create_drop_scopes_node(graph: &mut StackGraph, file: Handle<File>) -> Handle<Node> {
30+
let id = graph.new_node_id(file);
31+
graph.add_drop_scopes_node(id).unwrap()
32+
}
33+
2934
pub(crate) fn create_scope_node(
3035
graph: &mut StackGraph,
3136
file: Handle<File>,
@@ -48,6 +53,20 @@ pub(crate) fn create_push_symbol_node(
4853
.unwrap()
4954
}
5055

56+
pub(crate) fn create_push_scoped_symbol_node(
57+
graph: &mut StackGraph,
58+
file: Handle<File>,
59+
symbol: &str,
60+
scope: NodeID,
61+
is_reference: bool,
62+
) -> Handle<Node> {
63+
let id = graph.new_node_id(file);
64+
let symbol = graph.add_symbol(symbol);
65+
graph
66+
.add_push_scoped_symbol_node(id, symbol, scope, is_reference)
67+
.unwrap()
68+
}
69+
5170
pub(crate) fn create_pop_symbol_node(
5271
graph: &mut StackGraph,
5372
file: Handle<File>,
@@ -61,6 +80,19 @@ pub(crate) fn create_pop_symbol_node(
6180
.unwrap()
6281
}
6382

83+
pub(crate) fn create_pop_scoped_symbol_node(
84+
graph: &mut StackGraph,
85+
file: Handle<File>,
86+
symbol: &str,
87+
is_definition: bool,
88+
) -> Handle<Node> {
89+
let id = graph.new_node_id(file);
90+
let symbol = graph.add_symbol(symbol);
91+
graph
92+
.add_pop_scoped_symbol_node(id, symbol, is_definition)
93+
.unwrap()
94+
}
95+
6496
pub(crate) fn create_symbol_stack(
6597
graph: &mut StackGraph,
6698
partials: &mut PartialPaths,

0 commit comments

Comments
 (0)