Skip to main content

max / quasi

2.1 KB · 63 lines History Blame Raw
1 //! A staged include of a constant shape is evaluated where it stands.
2 //!
3 //! The boundary this is about: `symbolic::stage` gives a twin one parameter,
4 //! the plan, and a staged `include` drops the caller's arguments. So a shape
5 //! reached through an include put a sentinel where its own parameter was,
6 //! however literal the caller's argument was, and the real call happened per
7 //! request through the filler. `#[constant]` is the promise that lets the call
8 //! be made once instead (quasicoherent `793d99dd`).
9
10 use quasi_declare::declare;
11 use quasi_router::stage::Plan;
12
13 declare! {
14 /// A shape whose answer is decided entirely by what it is handed.
15 #[constant]
16 pub shape label(text: &str) -> Node;
17
18 text text;
19 }
20
21 declare! {
22 /// The caller, which reaches `label` with a literal.
23 #[staged]
24 pub shape panel() -> Node;
25
26 region "panel" as Pane {
27 include label("written down");
28 }
29 }
30
31 #[test]
32 fn a_constant_include_of_a_literal_lands_in_the_staged_twin() {
33 // The twin is what a residual is derived from, so what it holds is what
34 // gets baked in. The words being there mean the call was made while
35 // staging; a sentinel there would mean it was deferred to a request.
36 let rendered = format!("{:?}", panel_staged(&Plan::full(1)));
37
38 assert!(
39 rendered.contains("written down"),
40 "the literal did not survive the include boundary: {rendered}"
41 );
42 assert!(
43 !rendered.contains("ZQH"),
44 "a sentinel stood in for a value nothing varies: {rendered}"
45 );
46 }
47
48 #[test]
49 fn the_promise_leaves_the_shape_itself_alone() {
50 // The shim is the shape under a second name and nothing else, so the two
51 // cannot answer differently.
52 assert_eq!(label("same"), label_constant("same"));
53 }
54
55 #[test]
56 fn a_staged_shape_answers_for_nothing_when_every_include_is_constant() {
57 // No scope was opened, so the plan has nothing to enter and the shape's
58 // counts say so. A site here would be a residual carrying a gap that no
59 // request ever fills.
60 assert_eq!(PANEL_STAGED.sites, 0);
61 assert_eq!(PANEL_STAGED.holes, 0);
62 }
63