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
//! The classification with no geometry: its two halves, its two columns, and its filter's two
//! facets.

use crate::{ConfidenceFilter, GraphqlFilter, TextFilter};

use super::{
  super::tests::{detection, label, score},
  CONFIDENCE, Detection, DetectionFilter, LABEL,
};

/// Both halves survive the pairing, and neither is rewritten on the way in.
#[test]
fn it_holds_the_word_and_the_number() {
  let seen = detection("golden retriever", 0.87);

  assert_eq!(seen.label().as_str(), "golden retriever");
  assert_eq!(seen.confidence().get(), 0.87);
}

/// The constructor is TOTAL — both halves arrive validated, so there is nothing left to check.
#[test]
fn the_constructor_checks_nothing_because_its_parts_already_did() {
  const SEEN: fn(super::Label, crate::Score) -> Detection = Detection::new;

  let _ = SEEN(label("cat"), score(1.0));
}

/// The two column names, pinned: a change here moves every `CREATE TABLE`, `SELECT` and `WHERE` a
/// declaration holding one emits.
#[test]
fn it_spans_two_named_columns() {
  assert_eq!(LABEL.as_str(), "label");
  assert_eq!(
    CONFIDENCE.as_str(),
    "confidence",
    "a detector's degree column is a CONFIDENCE — the word the sibling house left open, settled \
     here on the type's own name"
  );

  let [word, degree] = <Detection as crate::ColumnKind>::SEGMENTS else {
    panic!("a detection is a word and a number");
  };

  assert!(matches!(word, crate::ColumnShape::Plain(named) if named.declared().as_str() == "label"));
  assert!(
    matches!(degree, crate::ColumnShape::Plain(named) if named.declared().as_str() == "confidence")
  );
}

/// The renderings: the fields under their own names, and the pair in brackets.
#[test]
fn it_renders_the_pair() {
  let seen = detection("cat", 0.5);

  assert_eq!(seen.to_string(), "cat (0.5)");
  assert_eq!(
    format!("{seen:?}"),
    r#"Detection { label: "cat", confidence: 0.5 }"#
  );
}

/// **The EMPTY filter asks nothing**, and each facet's own emptiness is what says so.
#[test]
fn an_unset_filter_is_empty() {
  assert!(DetectionFilter::new().is_empty());
  assert!(GraphqlFilter::is_empty(&DetectionFilter::default()));

  assert!(
    DetectionFilter::new()
      .with_label(TextFilter::new())
      .is_empty(),
    "a PRESENT facet with no operator set still asks nothing"
  );
}

/// A facet with an operator set is not empty, at either seat.
#[test]
fn a_set_facet_is_not_empty() {
  let by_word = DetectionFilter::new().with_label(TextFilter::new().with_eq(label("cat")));
  assert!(!by_word.is_empty());

  let by_degree = DetectionFilter::new().with_confidence(
    ConfidenceFilter::new()
      .with_gte(crate::ConfidenceOperand::number(0.8).expect("a confidence operand")),
  );
  assert!(!by_degree.is_empty());
}

/// The four accessor shapes the framework's own macro gives every facet — read, consuming set,
/// in-place set, and the option assignment.
#[test]
fn the_facets_are_reachable_four_ways() {
  let mut filter = DetectionFilter::new();
  assert!(filter.label().is_none());

  filter.set_label(TextFilter::new().with_eq(label("cat")));
  assert!(filter.label().is_some());

  let cleared = filter.clone().maybe_label(None::<TextFilter<_, _>>);
  assert!(cleared.label().is_none());

  filter.update_label(None::<TextFilter<_, _>>);
  assert!(filter.label().is_none());
}

/// **The COMPOSITE reading and the QUANTIFIED one**, pinned as type equalities: a detection occupies
/// columns of its own, and a `Vec` of them is asked through `any` and `count` alone.
#[test]
fn the_readings_are_the_composite_and_the_quantified() {
  use core::marker::PhantomData as P;

  let _: P<crate::CompositeMarker<Detection>> = P::<<Detection as crate::DefaultMarker>::Marker>;
  let _: P<crate::QuantifiedMarker<Vec<Detection>>> =
    P::<<Detection as crate::DefaultVecMarker>::Marker>;
  let _: P<DetectionFilter> = P::<<Detection as crate::CompositeFilterMarker>::Filter>;
}