ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
use super::RoutedProbe;

use crate::LaneIdent;

/// The general constructor and both accessors.
#[test]
fn a_probe_states_its_lane_and_what_it_asks_with() {
  let probe = RoutedProbe::new(LaneIdent::new("zh"), "世界");

  assert_eq!(probe.lane(), LaneIdent::new("zh"));
  assert_eq!(probe.probe(), &"世界");
}

/// **THE FOUR-PIECE ON BOTH SEATS**, because both are genuinely narrowable: a middleware re-points a
/// dispatch at another lane, or rewrites the probe and leaves the lane alone.
#[test]
fn both_seats_carry_the_consuming_and_the_in_place_forms() {
  let probe = RoutedProbe::new(LaneIdent::new("zh"), "世界".to_owned());

  let moved = probe.clone().with_lane(LaneIdent::new("ja"));
  assert_eq!(moved.lane(), LaneIdent::new("ja"));
  assert_eq!(moved.probe(), "世界");

  let rewritten = probe.clone().with_probe("せかい".to_owned());
  assert_eq!(rewritten.lane(), LaneIdent::new("zh"));
  assert_eq!(rewritten.probe(), "せかい");

  let mut held = probe.clone();
  held
    .set_lane(LaneIdent::new("ja"))
    .set_probe("せかい".to_owned());
  assert_eq!(held, moved.with_probe("せかい".to_owned()));
}

/// Both ways out, owned.
#[test]
fn a_probe_comes_apart_into_its_two_seats() {
  let probe = RoutedProbe::new(LaneIdent::new("en"), "hello".to_owned());

  assert_eq!(probe.clone().into_probe(), "hello");
  assert_eq!(
    probe.into_components(),
    (LaneIdent::new("en"), "hello".to_owned(), 1.0)
  );
}

/// **THE LANE SURVIVES THE CROSSING** a probe's type makes — the one combinator, and its whole
/// reason.
#[test]
fn mapping_the_probe_leaves_the_lane_alone() {
  let text = RoutedProbe::new(LaneIdent::new("zh"), "世界".to_owned());
  let counted = text.map_probe(|probe| probe.chars().count());

  assert_eq!(counted.lane(), LaneIdent::new("zh"));
  assert_eq!(counted.probe(), &2);
}

/// **THE WEIGHT DEFAULTS TO THE MULTIPLICATIVE IDENTITY**, so a router with no opinion costs the
/// fold nothing.
#[test]
fn a_probe_is_unweighted_unless_a_router_says_otherwise() {
  let probe = RoutedProbe::new(LaneIdent::new("en"), "hello");

  assert_eq!(probe.weight(), 1.0);
  assert_eq!(probe.weight(), RoutedProbe::<&str>::UNWEIGHTED);
}

/// The four-piece on the weight seat, like both others.
#[test]
fn the_weight_carries_the_consuming_and_the_in_place_forms() {
  let probe = RoutedProbe::new(LaneIdent::new("en"), "hello".to_owned());

  let leaned = probe.clone().with_weight(2.0);
  assert_eq!(leaned.weight(), 2.0);
  assert_eq!(leaned.lane(), LaneIdent::new("en"));
  assert_eq!(leaned.probe(), "hello");

  let mut held = probe;
  held.set_weight(0.5);
  assert_eq!(held.weight(), 0.5);
}

/// **`into_components` IS EVERY SEAT** — widened when the weight arrived rather than joined by a
/// second door, which is what the name already means one road over.
#[test]
fn a_probe_comes_apart_into_all_three_seats() {
  let probe = RoutedProbe::new(LaneIdent::new("ja"), "せかい".to_owned()).with_weight(2.0);

  assert_eq!(
    probe.into_components(),
    (LaneIdent::new("ja"), "せかい".to_owned(), 2.0)
  );
}

/// **`map_probe` PRESERVES THE WEIGHT** — only the probe crosses.
#[test]
fn mapping_the_probe_keeps_the_weight() {
  let text = RoutedProbe::new(LaneIdent::new("zh"), "世界".to_owned()).with_weight(2.5);
  let counted = text.map_probe(|probe| probe.chars().count());

  assert_eq!(counted.lane(), LaneIdent::new("zh"));
  assert_eq!(counted.probe(), &2);
  assert_eq!(counted.weight(), 2.5, "the weight survives the crossing");
}