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::*;

/// **THE FOLD AT THE DOOR** — one kind, however a producer spelled it.
#[test]
fn every_spelling_of_a_named_member_reaches_that_member() {
  for spelling in ["wifi", "Wifi", "WIFI", "Wi Fi", "Wi-Fi", "WI_FI"] {
    assert_eq!(
      BarcodePayloadKind::new(spelling),
      BarcodePayloadKind::Wifi,
      "`{spelling}` names one kind"
    );
  }
}

/// **THE ROSTER IS ITS OWN AUTHORITY**: every named member round-trips through its slug, and the
/// published list is exactly the slugs the table holds.
///
/// Two lists exist — the table the doors walk and the `VARIANTS` a schema documents — and they are
/// asserted against each other rather than each against a copy of the words. The escape is in
/// neither, which is the whole of what an open vocabulary promises.
#[test]
fn the_published_roster_is_the_table_the_doors_walk() {
  let table: Vec<_> = ROSTER.iter().map(|(_, canonical)| *canonical).collect();
  assert_eq!(table, BarcodePayloadKind::VARIANTS);
  assert_eq!(BarcodePayloadKind::VARIANTS.len(), 10);

  for (member, canonical) in ROSTER {
    assert_eq!(member.as_str(), *canonical);
    assert_eq!(BarcodePayloadKind::new(canonical), *member);
    assert!(
      member.is_registered(),
      "{canonical} is a name this crate KNOWS"
    );
    assert!(!member.is_other());
  }
}

/// **THE ESCAPE CARRIES THE FOLDED WORD**, which is what keeps `Eq` and `Hash` about NAMES rather
/// than about spellings for a kind nobody here has met.
#[test]
fn an_unnamed_kind_is_carried_folded_rather_than_refused() {
  let seen = BarcodePayloadKind::new("Boarding Pass");

  assert!(seen.is_other());
  assert!(!seen.is_registered());
  assert_eq!(seen.as_str(), "boardingpass");
  assert_eq!(
    seen,
    BarcodePayloadKind::new("BOARDING-PASS"),
    "two producers' spellings of one unknown kind are ONE value"
  );

  assert!(
    !BarcodePayloadKind::VARIANTS.contains(&seen.as_str()),
    "the escape is not a member of the roster"
  );
}

/// **THE CURSOR POSITION IS THE SLUG, and a forged one is CANONICALISED rather than refused** — the
/// posture an open vocabulary has where a validated newtype has a refusal.
#[test]
fn a_payload_kind_round_trips_through_a_cursor_and_canonicalises_a_forged_one() {
  for member in [
    BarcodePayloadKind::Wifi,
    BarcodePayloadKind::Product,
    BarcodePayloadKind::new("boarding pass"),
  ] {
    let mut bytes = Vec::new();
    CursorValue::write_cursor(&member, &mut bytes);
    assert_eq!(
      <BarcodePayloadKind as CursorValue>::read_cursor(&bytes),
      Some(member)
    );
  }

  assert_eq!(
    <BarcodePayloadKind as CursorValue>::read_cursor(b"WI-FI"),
    Some(BarcodePayloadKind::Wifi),
    "a client's spelling becomes the named member rather than a second value beside it"
  );
  assert_eq!(
    <BarcodePayloadKind as CursorValue>::read_cursor(&[0xff, 0xfe]),
    None,
    "…and bytes that are not text at all are the one refusal left"
  );
}