//! A staged include of a constant shape is evaluated where it stands. //! //! The boundary this is about: `symbolic::stage` gives a twin one parameter, //! the plan, and a staged `include` drops the caller's arguments. So a shape //! reached through an include put a sentinel where its own parameter was, //! however literal the caller's argument was, and the real call happened per //! request through the filler. `#[constant]` is the promise that lets the call //! be made once instead (quasicoherent `793d99dd`). use quasi_declare::declare; use quasi_router::stage::Plan; declare! { /// A shape whose answer is decided entirely by what it is handed. #[constant] pub shape label(text: &str) -> Node; text text; } declare! { /// The caller, which reaches `label` with a literal. #[staged] pub shape panel() -> Node; region "panel" as Pane { include label("written down"); } } #[test] fn a_constant_include_of_a_literal_lands_in_the_staged_twin() { // The twin is what a residual is derived from, so what it holds is what // gets baked in. The words being there mean the call was made while // staging; a sentinel there would mean it was deferred to a request. let rendered = format!("{:?}", panel_staged(&Plan::full(1))); assert!( rendered.contains("written down"), "the literal did not survive the include boundary: {rendered}" ); assert!( !rendered.contains("ZQH"), "a sentinel stood in for a value nothing varies: {rendered}" ); } #[test] fn the_promise_leaves_the_shape_itself_alone() { // The shim is the shape under a second name and nothing else, so the two // cannot answer differently. assert_eq!(label("same"), label_constant("same")); } #[test] fn a_staged_shape_answers_for_nothing_when_every_include_is_constant() { // No scope was opened, so the plan has nothing to enter and the shape's // counts say so. A site here would be a residual carrying a gap that no // request ever fills. assert_eq!(PANEL_STAGED.sites, 0); assert_eq!(PANEL_STAGED.holes, 0); }