ingraph-derive 0.1.0

The attribute and derive macros for ingraph: the words a record, node, key, filter and vocabulary declaration is written in.
Documentation
//! **B-27 — THE INTERFACE TIER's word**, and the two rules it composes under.
//!
//! Beside the source suite rather than inside it, for [`super::goodbye_tests`]'s reason: a word that
//! arrives after a grammar has been proven reads as one file, and the roster stays the one it was.

use super::tests::{accepted, refused};

/// **THE TIER WORD PUTS THE FIELD ON ITS OWN LIST**, and off the node one — which is the whole of
/// what it buys: the storage walk, the create pass and the options spine are each written about a
/// member an interface is not.
#[test]
fn an_interface_field_is_no_node_and_no_resource() {
  let model = accepted(quote::quote! {
    pub struct App {
      videos: media::Video,
      #[ingraph(interface, query)]
      screened: media::Screened,
    }
  });

  assert_eq!(model.nodes.len(), 1, "one field of two is a node");
  assert_eq!(model.mounts.len(), 1);
  assert!(model.resources.is_empty());
  assert_eq!(model.interfaces.len(), 1);
  assert_eq!(model.interfaces[0].mount, "screened");
  assert_eq!(
    quote::ToTokens::to_token_stream(&model.interfaces[0].ty).to_string(),
    "media :: Screened"
  );
  assert!(model.interfaces[0].queried);
}

/// **D-2: `query` IS THE MOUNT AND `interface` IS THE TIER**, and the two are independent — an
/// interface declared without the mount word is a citizen of the catalog that publishes nothing,
/// exactly as a node without it is.
#[test]
fn the_tier_word_alone_declares_without_mounting() {
  let model = accepted(quote::quote! {
    pub struct App {
      #[ingraph(interface)]
      screened: media::Screened,
    }
  });

  assert_eq!(model.interfaces.len(), 1);
  assert!(
    !model.interfaces[0].queried,
    "presence is the enablement, and nothing was written"
  );
  assert!(model.queried.is_empty());
}

/// **MOUNTING A MEMBER MOUNTS NO INTERFACE**, which is 乙 refused at the front end: the two words
/// are on two fields and neither reads the other.
#[test]
fn a_mounted_member_leaves_the_interface_unmounted() {
  let model = accepted(quote::quote! {
    pub struct App {
      #[ingraph(query)]
      videos: media::Video,
      #[ingraph(interface)]
      screened: media::Screened,
    }
  });

  assert_eq!(model.queried.len(), 1);
  assert!(!model.interfaces[0].queried);
}

/// **THE TWO TIER WORDS TOGETHER ARE REFUSED** — a member on two tiers of one list is a member
/// saying it is two things.
#[test]
fn a_field_is_on_one_tier() {
  let refusal = refused(quote::quote! {
    pub struct App {
      #[ingraph(interface, resource)]
      screened: media::Screened,
    }
  });

  assert!(refusal.contains("ONE tier"), "{refusal}");
}

/// **THE WORD IS BARE** — WHICH interface a field names is the field's own type, so an assigned form
/// would be a second spelling of something the type already says.
#[test]
fn the_tier_word_takes_no_value() {
  let refusal = refused(quote::quote! {
    pub struct App {
      #[ingraph(interface = "media::Screened")]
      screened: media::Screened,
    }
  });

  assert!(refusal.contains("bare word"), "{refusal}");
}

/// **AND IT IS WRITTEN ONCE**, for the reason every set-once word in this grammar is.
#[test]
fn the_tier_word_is_declared_once() {
  let refusal = refused(quote::quote! {
    pub struct App {
      #[ingraph(interface, interface)]
      screened: media::Screened,
    }
  });

  assert!(refusal.contains("more than once"), "{refusal}");
}

/// The UNKNOWN sentence names the word, so a reader who misspells it is told the spelling that
/// exists rather than only that theirs does not.
#[test]
fn the_unknown_refusal_names_the_tier_word() {
  let refusal = refused(quote::quote! {
    pub struct App {
      #[ingraph(interfaces)]
      screened: media::Screened,
    }
  });

  assert!(refusal.contains("`interface`"), "{refusal}");
}