#![allow(unused_variables)]
use interstellar::traversal::__;
use interstellar::value::{Value, VertexId};
use crate::common::graphs::create_small_graph;
#[test]
fn repeat_out_compiles_with_anonymous_traversal() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let _results = g.v().repeat(__.out()).times(1).to_list();
}
#[test]
fn repeat_returns_repeat_traversal_builder() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.alice])
.repeat(__.out_labels(&["knows"]))
.times(1)
.to_list();
assert_eq!(results.len(), 1);
assert_eq!(results[0].as_vertex_id(), Some(tg.bob));
}
#[test]
fn repeat_out_times_2_traverses_two_hops() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.alice])
.repeat(__.out_labels(&["knows"]))
.times(2)
.to_list();
assert_eq!(results.len(), 1);
assert_eq!(results[0].as_vertex_id(), Some(tg.charlie));
}
#[test]
fn repeat_until_terminates_on_condition() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.alice])
.repeat(__.out())
.until(__.has_label("software"))
.times(5) .to_list();
let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
assert!(ids.contains(&tg.graphdb));
}
#[test]
fn repeat_emit_includes_intermediates() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.alice])
.repeat(__.out_labels(&["knows"]))
.times(2)
.emit()
.to_list();
assert_eq!(results.len(), 2);
let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
assert!(ids.contains(&tg.bob));
assert!(ids.contains(&tg.charlie));
}
#[test]
fn repeat_emit_first_includes_starting_vertex() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.alice])
.repeat(__.out_labels(&["knows"]))
.times(1)
.emit()
.emit_first()
.to_list();
assert_eq!(results.len(), 2);
let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
assert!(ids.contains(&tg.alice)); assert!(ids.contains(&tg.bob)); }
#[test]
fn repeat_emit_if_selectively_emits() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.alice])
.repeat(__.out())
.times(2)
.emit_if(__.has_label("software"))
.to_list();
let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
assert!(ids.iter().all(|id| *id == tg.graphdb));
}
#[test]
fn repeat_continuation_step_returns_bound_traversal() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.alice])
.repeat(__.out_labels(&["knows"]))
.times(1)
.values("name")
.to_list();
assert_eq!(results.len(), 1);
assert_eq!(results[0], Value::String("Bob".to_string()));
}
#[test]
fn repeat_with_dedup_continuation() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.alice])
.repeat(__.out())
.times(2)
.emit()
.dedup()
.to_list();
let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
let unique_ids: std::collections::HashSet<_> = ids.iter().collect();
assert_eq!(ids.len(), unique_ids.len());
}
#[test]
fn repeat_from_multiple_starting_vertices() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.alice, tg.bob])
.repeat(__.out_labels(&["knows"]))
.times(1)
.to_list();
assert_eq!(results.len(), 2);
let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
assert!(ids.contains(&tg.bob));
assert!(ids.contains(&tg.charlie));
}
#[test]
fn repeat_from_leaf_vertex_with_no_outgoing_edges() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v_ids([tg.graphdb]).repeat(__.out()).times(3).to_list();
assert_eq!(results.len(), 1);
assert_eq!(results[0].as_vertex_id(), Some(tg.graphdb));
}
#[test]
fn repeat_times_zero_returns_input_unchanged() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v_ids([tg.alice]).repeat(__.out()).times(0).to_list();
assert_eq!(results.len(), 1);
assert_eq!(results[0].as_vertex_id(), Some(tg.alice));
}