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 SUBTITLE citizen's own claims: its roster, and the separation from the other two.
//!
//! The shared grammar is asserted once in [`video::tests`](super::super::video); this file carries
//! what would be untrue if it were a copy.

use mediaframe::codec::SubtitleCodec as Foreign;

use super::SubtitleCodec;
use crate::primitives::mediaframe::{AudioCodec, VideoCodec};

/// **EVERY ROSTER MEMBER IS A FIXPOINT OF THE DOOR** — the third table, walked.
#[test]
fn every_roster_member_is_a_fixpoint_of_the_door() {
  assert!(
    !Foreign::ROSTER.is_empty(),
    "the vendored table is not empty"
  );

  for member in Foreign::ROSTER {
    let citizen = SubtitleCodec::from(member.clone());

    assert!(
      citizen.is_registered(),
      "`{}` is on the roster",
      member.as_str()
    );
    assert_eq!(
      SubtitleCodec::new(citizen.as_str()),
      citizen,
      "`{}` is a fixpoint of the door",
      member.as_str(),
    );
    assert_eq!(
      SubtitleCodec::new(&member.as_str().to_ascii_uppercase()),
      citizen,
      "`{}` folds from its uppercase spelling",
      member.as_str(),
    );
  }
}

/// **THE THIRD ROSTER IS ITS OWN**, and neither of the other two names reaches a member of it.
#[test]
fn the_third_roster_is_its_own() {
  assert!(SubtitleCodec::new("subrip").is_registered());
  assert!(SubtitleCodec::new("ass").is_registered());

  assert!(!SubtitleCodec::new("h264").is_registered());
  assert!(!SubtitleCodec::new("aac").is_registered());
  assert!(!VideoCodec::new("subrip").is_registered());
  assert!(!AudioCodec::new("subrip").is_registered());
}

/// **THE DOOR FOLDS AND IS TOTAL.**
#[test]
fn the_door_folds_and_admits_every_string() {
  assert_eq!(SubtitleCodec::new("SubRip"), SubtitleCodec::new("subrip"));
  assert_eq!(
    SubtitleCodec::new("DVB_SUBTITLE"),
    SubtitleCodec::new("dvb_subtitle"),
    "an underscore is part of the slug and the fold touches only case",
  );

  for sent in ["", "!!!", "not a codec at all"] {
    assert!(
      !SubtitleCodec::new(sent).is_registered(),
      "`{sent}` is admitted"
    );
  }
}

/// **THE FOREIGN VALUE IS RE-CANONICALISED ON THE WAY IN.**
#[test]
fn the_foreign_value_is_recanonicalised_on_the_way_in() {
  let sideways = Foreign::other("subrip");
  assert_ne!(sideways, Foreign::Subrip, "upstream holds these apart");

  assert_eq!(SubtitleCodec::from(sideways).into_inner(), Foreign::Subrip);
}

/// **THE TEXT FACES ARE THE CANONICAL SLUG.**
#[test]
fn the_text_faces_are_the_canonical_slug() {
  let codec = SubtitleCodec::new("SubRip");

  assert_eq!(codec.to_string(), "subrip");
  assert_eq!(format!("{codec:?}"), "\"subrip\"");
  assert_eq!(AsRef::<str>::as_ref(&codec), "subrip");
  assert_eq!(String::from(codec), String::from("subrip"));
}

/// **ORDERING IS ALPHABETICAL OVER THE CANONICAL SPELLING.**
#[test]
fn ordering_is_alphabetical_over_the_canonical_spelling() {
  let mut codecs = [
    SubtitleCodec::new("subrip"),
    SubtitleCodec::new("ass"),
    SubtitleCodec::new("dvb_subtitle"),
  ];
  codecs.sort();

  let order: Vec<&str> = codecs.iter().map(SubtitleCodec::as_str).collect();
  assert_eq!(order, ["ass", "dvb_subtitle", "subrip"]);
}