ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
//! The pluraliser's answers, pinned as the FACTS the list face rests on.
//!
//! Not a test of `pluralizer`'s own suite. What is pinned here is the set of answers this framework
//! reads: the corpus's own entity names, the tail rule multi-word names ride, and — the load-bearing
//! one — exactly which words come back unchanged, because those are the ones the emission refuses by
//! name. A crate swap that moved any row here would move a schema, so a row here is what makes that
//! visible.

use super::of;

/// **THE CORPUS'S OWN NAMES** — every record in this repository that reaches a list face, plus the
/// neighbours it is declared beside. Regular English, and the pluraliser answers regularly.
#[test]
fn the_corpus_entity_names_pluralise_regularly() {
  for (singular, plural) in [
    ("Reel", "Reels"),
    ("Take", "Takes"),
    ("Clip", "Clips"),
    ("Cue", "Cues"),
    ("Slate", "Slates"),
    ("Shot", "Shots"),
    ("Cut", "Cuts"),
    ("Mix", "Mixes"),
    ("Roll", "Rolls"),
    ("Strip", "Strips"),
    ("Sheet", "Sheets"),
    ("Mark", "Marks"),
    ("Marquee", "Marquees"),
    ("Billboard", "Billboards"),
    ("Keyframe", "Keyframes"),
    ("Pipeline", "Pipelines"),
    ("Transcript", "Transcripts"),
    ("Video", "Videos"),
    // The one the crate choice turned on: `cruet` answers `Splice` here, which would have demanded a
    // declared plural for a perfectly regular word.
    ("Splice", "Splices"),
  ] {
    assert_eq!(of(singular), plural, "{singular}");
  }
}

/// **MULTI-WORD NAMES PLURALISE THEIR LAST WORD**, and nothing here splits one: the rules are
/// anchored at the end of the word, so a camel-cased name inflects its tail by construction —
/// including when that tail is irregular.
#[test]
fn a_multi_word_name_inflects_its_tail() {
  for (singular, plural) in [
    ("VideoTrack", "VideoTracks"),
    ("SpeakerTurn", "SpeakerTurns"),
    ("SearchDocument", "SearchDocuments"),
    ("MediaAsset", "MediaAssets"),
    // The tail carries its own irregularity with it.
    ("VideoChild", "VideoChildren"),
    ("MediaPerson", "MediaPeople"),
    ("KeyframeAnalysis", "KeyframeAnalyses"),
  ] {
    assert_eq!(of(singular), plural, "{singular}");
  }
}

/// **THE IRREGULARS**, which are the whole reason this is a dependency rather than an appended `s`.
#[test]
fn the_irregulars_are_english_rather_than_an_appended_s() {
  for (singular, plural) in [
    ("Person", "People"),
    ("Child", "Children"),
    ("Analysis", "Analyses"),
    ("Datum", "Data"),
    ("Index", "Indices"),
    ("Matrix", "Matrices"),
    ("Vertex", "Vertices"),
    ("Life", "Lives"),
    ("Knife", "Knives"),
    ("Hero", "Heroes"),
    ("Half", "Halves"),
    ("City", "Cities"),
    ("Box", "Boxes"),
    ("Bus", "Buses"),
    ("Church", "Churches"),
  ] {
    assert_eq!(of(singular), plural, "{singular}");
  }
}

/// **THE DEGENERATE ANSWERS, WHICH ARE THE POINT** — a word with no distinct plural comes back
/// VERBATIM, and a word that already IS one is left alone.
///
/// This is the fact the list face's refusal is built on: silence here is loud downstream, where a
/// derived plural equal to the singular is refused by name and answered with
/// `graphql(plural = "…")`. A pluraliser that guessed `Medias` instead would be silent, and no rule
/// could catch it.
#[test]
fn a_word_with_no_distinct_plural_is_answered_unchanged() {
  for word in [
    "Media",
    "Audio",
    "Series",
    "Dimensions",
    "News",
    "Equipment",
  ] {
    assert_eq!(of(word), word, "{word}");
  }
}

/// **CASE IS NOT THIS LAYER'S BUSINESS**, and the one place that shows is harmless: a handful of
/// irregulars are stored in lower case and come back that way.
///
/// Measured rather than assumed, and it never reaches a schema — a root field is spelled with a
/// lower initial anyway, so `Foot` names the field `feet` through either path. If a future crate
/// swap fixed the case, no schema would move; if one broke a word here into a DIFFERENT word, this
/// row is what would say so.
#[test]
fn an_irregular_may_come_back_lower_cased_and_the_field_spelling_absorbs_it() {
  assert_eq!(of("Foot"), "feet");
  assert_eq!(of("Man"), "men");
  // …while the rest of the irregular table keeps the case it was given.
  assert_eq!(of("Mouse"), "Mice");
  assert_eq!(of("Woman"), "Women");
}

/// The degenerate INPUTS, answered rather than panicked on — a name is a string, and the emitter
/// carries whatever a declaration wrote.
#[test]
fn a_name_with_nothing_to_inflect_is_answered_rather_than_refused() {
  assert_eq!(of(""), "");
  // A single letter is a fixture's name rather than a word, and the crate has no rule that fits it.
  // Whatever it answers, the emission's own degeneracy rule is what decides whether it is usable.
  assert!(!of("S").is_empty());
}