ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
//! The one naming act this file performs, measured as the pure function it is.

use super::root_field;

/// **THE SINGLE IS THE PUBLISHED TYPE, LOWERED** — the ruled `<camel>(id:)` spelling, with no `ById`
/// anywhere and nothing else moved.
///
/// The PAGE is this same one act over the published name's PLURAL, the suffix spelling
/// `<camel>List` having died with the plural round. The WORD is [`crate::plural`]'s and is asserted
/// there; what this file is about is the one character, and that it is the same character on both
/// legs.
#[test]
fn a_root_field_is_the_published_type_with_a_lower_initial() {
  assert_eq!(root_field("Reel"), "reel");
  assert_eq!(root_field("VideoTrack"), "videoTrack");
  assert_eq!(root_field(&crate::plural::of("VideoTrack")), "videoTracks");
}

/// **A DECLARED RENAME REACHES THE FIELD**, because the field is built from the PUBLISHED name
/// rather than from the record's: `output(rename = "Track")` moves the object a client reads and the
/// field it reads it through, together.
#[test]
fn a_renamed_output_moves_the_field_that_returns_it() {
  assert_eq!(root_field("Track"), "track");
  // …and a rename whose spelling is not upper camel case is lowered at its initial and left alone
  // after it. The declaration chose the word; this changes exactly the one character GraphQL's own
  // convention is about.
  assert_eq!(root_field("Video_Track"), "video_Track");
}

/// 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_no_initial_to_lower_is_answered_unchanged() {
  assert_eq!(root_field(""), "");
  assert_eq!(root_field("reel"), "reel");
  // A multi-character lowering — `İ` lowercases to two scalars — is carried whole rather than
  // truncated, which is what `to_lowercase` over a `char` answers and `chars().next()` alone would
  // have lost.
  assert_eq!(root_field("İzmir"), "i\u{307}zmir");
}