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::{asked, participates};

/// **THE ROUTE'S OWN WINS.** First tier of the chain, and the one a client reaches for when two
/// routes of one tier ask different questions.
#[test]
fn a_routes_own_question_beats_the_tiers_and_the_parents() {
  assert_eq!(
    asked(Some("sunset"), Some("harbour"), Some("dusk")),
    Some("sunset"),
  );
}

/// A silent route takes its TIER's question — the middle tier, and the reason a tier carries one at
/// all.
#[test]
fn a_silent_route_takes_the_tiers_question() {
  assert_eq!(asked(None, Some("harbour"), Some("dusk")), Some("harbour"));
}

/// A silent tier passes the PARENT's straight through, which is what makes one question at the root
/// reach every leaf of the tree.
#[test]
fn a_silent_tier_passes_the_parents_question_down() {
  assert_eq!(asked(None, None, Some("dusk")), Some("dusk"));
}

/// **AN UNRESOLVABLE QUESTION IS ABSENCE, not an empty query.** The chain's terminator is `None`,
/// and that `None` is the participation rule's input rather than an error.
#[test]
fn a_chain_nobody_answered_resolves_to_nothing() {
  assert_eq!(asked::<str>(None, None, None), None);
}

/// The walk BORROWS through — a question whose currency is an expensive shape costs the resolution
/// nothing, and the caller decides whether the winner is ever copied.
#[test]
fn the_winner_is_borrowed_and_never_copied() {
  let own = vec![0.5_f32, 0.25];
  let parent = vec![0.0_f32];

  let resolved = asked(Some(own.as_slice()), None, Some(parent.as_slice()))
    .expect("the route named its own coordinates");

  assert!(
    core::ptr::eq(resolved, own.as_slice()),
    "the resolution handed back the caller's own slice",
  );
}

/// **RAW-COORDINATE MULTI-ROUTE FUSION IS EXPRESSIBLE**, and this is the shape that makes it so:
/// each route is asked in its OWN currency, and the chain is generic over which one that is.
#[test]
fn two_routes_of_two_currencies_resolve_independently() {
  let coordinates = [0.5_f32, 0.5];

  let text = asked(None, None, Some("harbour at dusk"));
  let vector = asked(Some(coordinates.as_slice()), None, None);

  assert_eq!(text, Some("harbour at dusk"));
  assert_eq!(vector, Some(coordinates.as_slice()));
}

/// **THE PARTICIPATION RULE takes BOTH absences.** A route enters iff its parent walks it and it has
/// a question to walk with — two facts stated in two places, checked in one.
#[test]
fn a_route_enters_only_when_it_is_walked_and_answerable() {
  assert!(participates(true, Some("sunset")));
  assert!(
    !participates(false, Some("sunset")),
    "a disabled edge does not enter however answerable it is",
  );
  assert!(
    !participates::<str>(true, None),
    "an unanswerable route does not enter however enabled it is",
  );
  assert!(!participates::<str>(false, None));
}