ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
//! **THE ORIGIN TIER'S SECTION**, read off the spine's tokens.
//!
//! Beside the node suite rather than inside it, for the shape this workspace keeps: a tier that
//! arrives after a spine has been proven reads as one file, and the roster stays the one it was.

use crate::graph::{GraphModel, OriginMount};

use super::tests::{app, compact, rendered};

/// The same root with one origin field beside its three nodes.
fn watched() -> GraphModel {
  GraphModel {
    origins: vec![OriginMount {
      mount: syn::parse_quote!(watch),
      ty: syn::parse_quote!(app::Watch),
    }],
    ..app()
  }
}

/// **ONE SECTION PER ORIGIN, AT THE TOP LEVEL AND UNDER NO BLOCK** — because presence is enablement
/// here exactly as it is for a node, where a resource is DEMAND-SCANNED and grouped instead. So a
/// document names its origins beside its nodes, in one flat list of who runs.
#[test]
fn an_origin_gets_a_section_beside_the_nodes() {
  let emitted = compact(&watched());

  assert!(
    emitted.contains(
      "pub(crate)watch:::core::option::Option<::ingraph::__private::drive::NodeSection<::ingraph::__private::drive::Tuned<app::Watch>>>"
    ),
    "{}",
    rendered(&watched())
  );
}

/// **AND THE SEAT IT HOLDS IS THE FACE'S OWN**, projected through the mode row rather than through
/// `AsyncConstructor`. That is the whole of the one-seat law arriving at the spine: an origin used to
/// carry a second options type because the create walk could not reach `Source::build`, and a
/// section written off the resident construction door would still be reading the seat nothing fills.
#[test]
fn an_origins_section_is_typed_by_its_own_faces_options() {
  assert!(
    !compact(&watched()).contains("<app::Watchas::ingraph::__private::drive::AsyncConstructor>"),
    "{}",
    rendered(&watched())
  );
}

/// **AND NO `channels` SHELF UNDER IT.** A node's section is typed by `<N as Declared>::Channels`
/// because a node has inbound edges to tune; an origin declares no upstream, so its section takes
/// the parameter's own default and its ONE out-edge is tuned in the CONSUMER's section.
#[test]
fn an_origins_section_carries_no_channel_shelf() {
  assert!(
    !compact(&watched()).contains("<app::Watchas::ingraph::__private::drive::Declared>::Channels"),
    "{}",
    rendered(&watched())
  );
}

/// **THE BUILDER AND THE BORROW**, exactly as a node's mount has them — the door a deployment states
/// in code rather than in a document.
#[test]
fn an_origin_takes_the_same_two_accessors_a_node_does() {
  let emitted = compact(&watched());

  assert!(
    emitted.contains("pubfnwith_watch(mutself,"),
    "{}",
    rendered(&watched())
  );
  assert!(
    emitted.contains("pubfnwatch(&self,)"),
    "{}",
    rendered(&watched())
  );
}

/// **ENABLEMENT READS BOTH TIERS UNDER ONE CALL EACH.** A mount is a mount to the launch floor,
/// which asks about NAMES and never about which door declared one — so an origin's absence starves
/// its consumer exactly as an unmounted node's does.
#[test]
fn the_enablement_bridge_names_the_origins_beside_the_nodes() {
  let emitted = compact(&watched());

  for mount in ["videos", "scenes", "search", "watch"] {
    assert!(
      emitted.contains(&format!(
        ".mounted(\"{mount}\",::core::option::Option::as_ref(&self.{mount}))"
      )),
      "{mount}: {}",
      rendered(&watched())
    );
  }
}

/// And a start-up log reports an origin's PRESENCE beside every node's — which is the same trade the
/// node rows make: what a reader wants is which members this deployment runs, never what is in a
/// section.
#[test]
fn the_debug_reports_an_origins_presence_too() {
  assert!(
    compact(&watched()).contains(".field(\"watch\",&::core::option::Option::is_some(&self.watch))"),
    "{}",
    rendered(&watched())
  );
}

/// **A ROOT WITH NO ORIGIN CARRIES NO LINE OF THIS TIER**, which is what keeps the word free.
#[test]
fn a_root_that_mounts_no_origin_grows_no_section() {
  assert!(!compact(&app()).contains("watch"), "{}", rendered(&app()));
}