ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
use super::ChannelOptions;

#[test]
fn a_bounded_spec_names_its_depth_and_an_unbounded_one_has_none() {
  assert_eq!(ChannelOptions::Bounded(512).capacity(), Some(512));
  assert!(ChannelOptions::Bounded(512).is_bounded());
  assert_eq!(ChannelOptions::Unbounded.capacity(), None);
  assert!(ChannelOptions::Unbounded.is_unbounded());
}

#[test]
fn a_spec_reads_back_as_the_word_an_author_writes() {
  assert_eq!(ChannelOptions::Bounded(4).to_string(), "bounded(4)");
  assert_eq!(ChannelOptions::Unbounded.to_string(), "unbounded");
}

/// ZERO is the rendezvous the constructor has always documented, and it is admitted rather than
/// refused: the sender waits until the consumer takes it, which is a real posture and not a
/// degenerate one.
#[test]
fn zero_is_a_rendezvous_and_not_a_refusal() {
  assert_eq!(ChannelOptions::Bounded(0).capacity(), Some(0));
}

#[cfg(feature = "serde")]
mod wire {
  use super::ChannelOptions;

  fn read(document: &str) -> Result<ChannelOptions, serde_json::Error> {
    serde_json::from_str(document)
  }

  /// THE TWO FORMS: an integer is a depth, and one word is the other kind.
  #[test]
  fn an_integer_is_a_capacity_and_the_word_is_the_other_kind() {
    assert_eq!(
      read("512").expect("an integer is a depth"),
      ChannelOptions::Bounded(512)
    );
    assert_eq!(
      read("0").expect("zero is a rendezvous"),
      ChannelOptions::Bounded(0)
    );
    assert_eq!(
      read(r#""unbounded""#).expect("the word is the other kind"),
      ChannelOptions::Unbounded
    );
  }

  /// A neighbouring word is refused NAMING BOTH FORMS, where the reader is looking at the file.
  #[test]
  fn another_word_is_refused_naming_the_two_forms() {
    let refusal = read(r#""bounded""#)
      .expect_err("only one word is a channel")
      .to_string();
    assert!(refusal.contains("bounded"), "{refusal}");
    assert!(refusal.contains("unbounded"), "{refusal}");
  }

  /// A negative depth is a value the grammar HAS and the type does not — so the sentence is the
  /// grammar's rather than serde's.
  #[test]
  fn a_negative_depth_is_refused_in_the_grammars_own_words() {
    let refusal = read("-1")
      .expect_err("a channel is not minus one deep")
      .to_string();
    assert!(refusal.contains("unbounded"), "{refusal}");
  }
}