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
//! **THE `fuse` WORD** — the root's INDEX TIER word, and every refusal it carries.
//!
//! Beside the source suite rather than inside it, for [`super::goodbye_tests`]' reason: a word that
//! arrives after a grammar has been proven reads as one file, and the roster stays the one it was.
//!
//! # WHAT THIS SUITE LOST, and where it went
//!
//! The word carried a MODALITY — bare, `fuse(vector)`, `fuse(fulltext)` — and half of this file was
//! about the trims: which one a spelling read, that a block names one, that a modality tunes
//! nothing. Those doors are `#[ingraph::search]`'s now and a recipe LISTS its members, so there is
//! no door for a trim to select. The claims are retired, and one refusal stands in their place.

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

/// **THE TIER WORD PUTS THE FIELD ON ITS OWN LIST**, and off the node one — which is forced rather
/// than chosen: a `#[ingraph::vector(…)]` declaration implements neither `Declared` nor
/// `AsyncConstructor`, so a field naming one on the node tier is `E0277` at the root before anything
/// else is reached.
#[test]
fn a_fused_field_is_no_node_and_no_resource() {
  let model = accepted(quote::quote! {
    pub struct Media {
      videos: media::Video,
      #[ingraph(fuse)]
      shots: index::Shots,
    }
  });

  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!(model.interfaces.is_empty());
  assert_eq!(model.fused.len(), 1);
  assert_eq!(model.fused[0].mount, "shots");
  assert_eq!(
    quote::ToTokens::to_token_stream(&model.fused[0].ty).to_string(),
    "index :: Shots"
  );
}

/// **THE WORD IS BARE, IN EVERY SHAPE IT USED TO TAKE** — and the sentence says where the fusion
/// went rather than only that the block is gone, which is what a reader with a working declaration
/// from the round before needs to be told.
#[test]
fn every_retired_spelling_is_refused_by_name() {
  for written in [
    "fuse(vector)",
    "fuse(fulltext)",
    "fuse()",
    "fuse(hybrid)",
    "fuse(vector, fulltext)",
  ] {
    let written: proc_macro2::TokenStream = written.parse().expect("a marker list");
    let refusal = refused(quote::quote! {
      pub struct Media {
        #[ingraph(#written)]
        shots: Shots,
      }
    });
    assert!(refusal.contains("`fuse` is a BARE word"), "{refusal}");
    assert!(
      refusal.contains("`#[ingraph::search]`"),
      "the refusal does not say where a fused read is declared now: {refusal}",
    );
  }
}

/// **THE WORD IS NOT AN OPTION EITHER** — `fuse = …` reads as a value of this grammar's, and the
/// word states a TIER rather than a value.
#[test]
fn the_word_takes_no_value() {
  let refusal = refused(quote::quote! {
    pub struct Media {
      #[ingraph(fuse = "vector")]
      shots: Shots,
    }
  });
  assert!(refusal.contains("`fuse` is a BARE word"), "{refusal}");
}

/// **ONE TIER PER FIELD** — declared twice is a refusal rather than a precedence.
#[test]
fn a_field_claims_once() {
  let refusal = refused(quote::quote! {
    pub struct Media {
      #[ingraph(fuse, fuse)]
      shots: Shots,
    }
  });
  assert!(refusal.contains("declared more than once"), "{refusal}");
}

/// **A RESOURCE IS NO INDEX**, for the reason it queries nothing: it is a shared citizen the launch
/// builds and hands out, where the index tier is for members that RETRIEVE.
#[test]
fn a_resource_takes_no_fuse() {
  let refusal = refused(quote::quote! {
    pub struct Media {
      #[ingraph(resource, fuse)]
      egemma: Egemma,
    }
  });
  assert!(refusal.contains("takes no `fuse`"), "{refusal}");
  assert!(refusal.contains("shared citizen"), "{refusal}");
}

/// **AN INTERFACE IS NO INDEX EITHER**, and the reason is one hop deeper: a contract over members
/// owns no slot, so it has no ranking of its own for a fold to read.
#[test]
fn an_interface_takes_no_fuse() {
  let refusal = refused(quote::quote! {
    pub struct Media {
      #[ingraph(interface, fuse)]
      screened: Screened,
    }
  });
  assert!(refusal.contains("owns no slot"), "{refusal}");
  assert!(refusal.contains("The MEMBERS fuse"), "{refusal}");
}

/// **THE MOUNT IS ORTHOGONAL TO THE TIER**, exactly as it is for an interface: `query` says whether
/// this deployment publishes a member's root fields and `fuse` says which tier it is on, and a
/// member may write either, both or neither.
#[test]
fn the_two_membership_words_compose() {
  let model = accepted(quote::quote! {
    pub struct Media {
      #[ingraph(fuse)]
      shots: Shots,
      #[ingraph(query)]
      videos: media::Video,
    }
  });

  assert_eq!(model.fused.len(), 1);
  assert_eq!(model.queried.len(), 1, "the query membership is untouched");
  assert!(
    model.fused[0].mount == "shots",
    "the fused member is the one that wrote the word",
  );
}

/// **AND THE UNKNOWN-ENTRY SENTENCE NAMES IT**, so a near miss on a graph field's word offers the
/// spellings that do exist — and offers none that no longer do.
#[test]
fn the_words_roster_offers_the_new_one() {
  let refusal = refused(quote::quote! {
    pub struct Media {
      #[ingraph(fyse)]
      shots: Shots,
    }
  });
  assert!(refusal.contains("`fuse`"), "{refusal}");
  assert!(
    !refusal.contains("fuse(vector)"),
    "the roster still offers a retired spelling: {refusal}",
  );
}