ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
//! **THE POLL BODY'S TWO ARMS** — the vocabulary the `Option<syn::Path>` this replaced could only
//! describe in a paragraph.
//!
//! What the respell buys is not behaviour, and this suite is not trying to prove that it is: the
//! emission is byte-identical, which is a `cargo expand` claim rather than an assertion. What it
//! buys is that the LIGHT road has a NAME. A caller reading `Option<syn::Path>` had to be told which
//! of two meanings the empty case carried; a caller reading [`PollBody`] writes `Light`, and a
//! reader of that line needs nothing else.

use super::{PollBody, PollCadence, PollEntry, PollMode};

/// One entry with the given body, at the settings every fixture in this crate defaults to.
fn entry(body: PollBody) -> PollEntry {
  PollEntry {
    name: quote::format_ident!("orphans"),
    variant: quote::format_ident!("Orphans"),
    cadence: PollCadence::Every(core::time::Duration::new(600, 0)),
    grants: None,
    body,
    mode: PollMode::AsyncInline,
    concurrent: false,
  }
}

/// **`Light` NAMES A ROAD AND NOT AN ABSENCE.** It carries nothing because the operator's own sweep
/// method needs nothing carried — the driver lends the value — and it answers both questions a
/// consumer asks of a body.
#[test]
fn the_light_arm_mounts_nothing_and_says_so() {
  let body = PollBody::Light;

  assert!(body.citizen().is_none(), "a light body mounts no citizen");
  assert!(!body.mounted(), "and the presence split reads it as light");
}

/// **`Citizen` CARRIES THE PATH, AND IT IS THE PATH THE DECLARATION WROTE** — unresolved, because
/// the type is the application's and the compiler resolves it where the expansion lands.
#[test]
fn the_citizen_arm_carries_the_path_it_was_given() {
  let path: syn::Path = syn::parse_quote!(app::PromScraper);
  let body = PollBody::Citizen(path.clone());

  assert_eq!(body.citizen(), Some(&path));
  assert!(body.mounted(), "and the presence split reads it as mounted");
}

/// **THE ENTRY ASKS ITS BODY**, so the presence split has ONE answer rather than an entry's opinion
/// beside a body's.
#[test]
fn an_entrys_presence_split_reads_through_to_its_body() {
  assert!(!entry(PollBody::Light).mounted());
  assert!(entry(PollBody::Citizen(syn::parse_quote!(app::Pusher))).mounted());
}

/// **THE TWO ARMS ARE THE WHOLE VOCABULARY**, stated as an exhaustive match with no wildcard: a
/// third road added later is a compile error at every seat that reads one, which is the half an
/// `Option` could never give.
#[test]
fn the_vocabulary_is_closed_at_two() {
  fn road(body: &PollBody) -> &'static str {
    match body {
      PollBody::Light => "light",
      PollBody::Citizen(_) => "handler",
    }
  }

  assert_eq!(road(&PollBody::Light), "light");
  assert_eq!(
    road(&PollBody::Citizen(syn::parse_quote!(app::PromScraper))),
    "handler"
  );
}