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
//! The fold's own relation, checked in both of its shapes and at the line it declines to cross.

use super::{folded, folds_to};

/// **THE FOUR LANGUAGES ARE ONE WORD** — which is the whole reason the separators go and not just
/// the case.
#[test]
fn every_spelling_a_producer_writes_folds_onto_one_word() {
  for spelling in [
    "left_shoulder",
    "leftShoulder",
    "LeftShoulder",
    "LEFT_SHOULDER",
    "LEFT-SHOULDER",
    "Left Shoulder",
    "left-shoulder",
    "l e f t s h o u l d e r",
  ] {
    assert!(folds_to(spelling, "left_shoulder"), "{spelling}");
  }
}

/// **IT IS NOT A SYNONYM TABLE.** Two words somebody decided meant the same thing stay two words.
#[test]
fn a_synonym_is_not_a_spelling() {
  assert!(!folds_to("little_mcp", "pinky_mcp"));
  assert!(!folds_to("right_shoulder", "left_shoulder"));
  assert!(!folds_to("shoulder", "left_shoulder"));
  assert!(!folds_to("left_shoulders", "left_shoulder"));
}

/// A word that is nothing but separators folds onto the empty word and onto nothing else.
#[test]
fn separators_alone_name_the_empty_word() {
  assert!(folds_to("___", ""));
  assert!(folds_to("", "- -"));
  assert!(!folds_to("___", "a"));
}

/// **THE TWO HALVES AGREE**, which is what lets one of them decide membership and the other decide
/// identity: two spellings fold to one [`String`] exactly when [`folds_to`] answers for either
/// against the other.
#[test]
fn a_folded_copy_and_a_folded_comparison_answer_alike() {
  for (left, right) in [
    ("left_paw_extra", "leftPawExtra"),
    ("VN-Barcode", "vn barcode"),
    ("Code39", "code_39"),
  ] {
    assert_eq!(folded(left), folded(right), "{left} / {right}");
    assert!(folds_to(left, right), "{left} / {right}");
    assert!(folds_to(right, left), "{right} / {left}");
  }

  assert_ne!(folded("pinky_mcp"), folded("little_mcp"));
}

/// The materialised fold is LOWER-CASE and separator-free, which is what an escape carries.
#[test]
fn the_materialised_fold_drops_the_three_and_lowers_the_rest() {
  assert_eq!(folded("Left Shoulder"), "leftshoulder");
  assert_eq!(folded("LEFT-SHOULDER"), "leftshoulder");
  assert_eq!(folded("left_shoulder"), "leftshoulder");
  assert_eq!(folded(""), "");
}

/// **ONLY ASCII LETTERS ARE LOWERED**, and both halves draw the line in the same place — so a
/// vocabulary meeting a non-ASCII spelling gets one answer rather than two.
#[test]
fn the_ascii_line_is_the_same_in_both_halves() {
  assert_eq!(folded("Größe"), "größe");
  assert!(!folds_to("GRÖSSE", "größe"));
  assert_ne!(folded("GRÖSSE"), folded("größe"));

  // …and the bytes a non-ASCII character is made of are never mistaken for separators.
  assert_eq!(folded("naïve-word"), "naïveword");
  assert!(folds_to("naïve_word", "naïveWord"));
}