graph_api_test/steps/
context.rs

1use crate::{Edge, Vertex, assert_elements_eq, populate_graph};
2use graph_api_lib::{EdgeSearch, Graph};
3
4pub fn test_vertices_context<T>(graph: &mut T)
5where
6    T: Graph<Vertex = Vertex, Edge = Edge>,
7{
8    let refs = populate_graph(graph);
9    let collected = graph
10        .walk()
11        .vertices_by_id(vec![refs.bryn])
12        .push_context(|_vertex, _ctx| "hi".to_string())
13        .push_context(|_vertex, ctx| assert_eq!(ctx.as_str(), "hi"))
14        .collect::<Vec<_>>();
15
16    assert_elements_eq!(graph, collected, vec![refs.bryn]);
17}
18
19pub fn test_edges_context<T>(graph: &mut T)
20where
21    T: Graph<Vertex = Vertex, Edge = Edge>,
22{
23    let refs = populate_graph(graph);
24    let collected = graph
25        .walk()
26        .vertices_by_id(vec![refs.bryn])
27        .edges(EdgeSearch::scan().outgoing())
28        .push_context(|_edge, _ctx| "hi".to_string())
29        .push_context(|_edge, ctx| assert_eq!(ctx.as_str(), "hi"))
30        .collect::<Vec<_>>();
31
32    assert_elements_eq!(graph, collected, vec![refs.bryn]);
33}