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 boolean kind, and the `V` it has where the filter has none.

use bson::doc;

use super::MongoBooleanComparison;
use crate::{
  At, BooleanFilter, ComplexComparison, FieldName, Mongo, RecordAddress, ToDatabaseComparison,
  TryFromFilter, comparison::mongo::MongoConjunction,
};

const ROW: RecordAddress = RecordAddress::new(FieldName::new("media"), &[FieldName::new("id")]);

/// Stored as BSON's own `Boolean`, which is the identity crossing and the common case.
#[test]
fn a_native_boolean_field_carries_as_a_bson_boolean() {
  let comparison =
    MongoBooleanComparison::<bool>::try_from_filter(BooleanFilter::new().with_eq(true))
      .expect("the identity crossing cannot fail");

  let frame = At::new(&ROW).frame(FieldName::new("hdr"));
  let filter = comparison
    .apply(frame.at(), MongoConjunction::new())
    .expect("a MongoDB lowering cannot refuse")
    .into_document();

  assert_eq!(filter, doc! { "hdr": { "$eq": true } });
}

/// The same filter over a field DECLARED as `0`/`1`, which is the whole reason this kind carries a
/// `V` the filter does not: what a boolean is stored as is a declaration, not a law.
#[test]
fn a_field_declared_as_an_integer_carries_as_one() {
  let comparison = MongoBooleanComparison::<i32>::try_from_filter_with(
    BooleanFilter::new().with_ne(false).with_in_(vec![true]),
    |set: bool| Ok::<_, core::convert::Infallible>(i32::from(set)),
  )
  .expect("the converter above cannot fail");

  assert_eq!(comparison.conjuncts(), 2);

  let frame = At::new(&ROW).frame(FieldName::new("hdr"));
  let filter = comparison
    .apply(frame.at(), MongoConjunction::new())
    .expect("a MongoDB lowering cannot refuse")
    .into_document();

  assert_eq!(filter, doc! { "hdr": { "$ne": 0, "$in": [1] } });
}

/// The projection an expansion writes for a boolean field, resolved.
#[test]
fn the_codegen_projection_resolves_for_a_boolean_field() {
  type Crossed = <BooleanFilter as ToDatabaseComparison<bool, Mongo>>::Comparison;

  let comparison: Crossed = MongoBooleanComparison::<bool>::new();
  assert!(comparison.is_empty());
}