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 standard, however a producer spelled it.
#[test]
fn every_spelling_of_a_named_member_reaches_that_member() {
  for spelling in [
    "data_matrix",
    "dataMatrix",
    "DATA_MATRIX",
    "data matrix",
    "Data-Matrix",
    "DATAMATRIX",
  ] {
    assert_eq!(
      Symbology::new(spelling),
      Symbology::DataMatrix,
      "`{spelling}` names one standard"
    );
  }
}

/// **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, Symbology::VARIANTS);
  assert_eq!(Symbology::VARIANTS.len(), 24);

  for (member, canonical) in ROSTER {
    assert_eq!(member.as_str(), *canonical);
    assert_eq!(Symbology::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 standard nobody here has met.
#[test]
fn an_unnamed_standard_is_carried_folded_rather_than_refused() {
  let seen = Symbology::new("Han Xin");

  assert!(seen.is_other());
  assert!(!seen.is_registered());
  assert_eq!(seen.as_str(), "hanxin");
  assert_eq!(
    seen,
    Symbology::new("HAN-XIN"),
    "two producers' spellings of one unknown standard are ONE value"
  );

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

/// **APPLE'S TYPE PREFIX IS THE INTEROP ENTRY'S BUSINESS AND NOT THE DOOR'S.**
///
/// The plain door carries the whole vendor string, which is the honest reading of a word it was
/// never told is a namespace; `from_vision` is where a producer's genealogy is spent.
#[test]
fn the_vision_prefix_is_removed_only_where_a_caller_says_it_is_one() {
  assert_eq!(
    Symbology::from_vision("VNBarcodeSymbologyQR"),
    Symbology::Qr
  );
  assert_eq!(
    Symbology::from_vision("vn_barcode_symbology_qr"),
    Symbology::Qr
  );
  assert_eq!(
    Symbology::from_vision("VNBARCODESYMBOLOGY-DATA-MATRIX"),
    Symbology::DataMatrix
  );

  assert_eq!(
    Symbology::from_vision("qr"),
    Symbology::Qr,
    "a word with no prefix reaches the same member, so an adapter may call this unconditionally"
  );
  assert!(Symbology::new("VNBarcodeSymbologyQR").is_other());
}

/// A string that is NOTHING BUT the prefix is left alone — stripping it would leave an empty word,
/// which names nothing and would ride the escape carrying nothing.
#[test]
fn a_bare_prefix_is_carried_rather_than_stripped_to_nothing() {
  let bare = Symbology::from_vision("VNBarcodeSymbology");

  assert!(bare.is_other());
  assert_eq!(bare.as_str(), "vnbarcodesymbology");
  assert!(!bare.as_str().is_empty());
}

/// **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_symbology_round_trips_through_a_cursor_and_canonicalises_a_forged_one() {
  for member in [Symbology::Qr, Symbology::Code93i, Symbology::new("han xin")] {
    let mut bytes = Vec::new();
    CursorValue::write_cursor(&member, &mut bytes);
    assert_eq!(
      <Symbology as CursorValue>::read_cursor(&bytes),
      Some(member)
    );
  }

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