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 AUDIO citizen's own claims: its roster, and the separation that is the reason it is a type
//! rather than a value of the video one.
//!
//! The shared grammar — the fold, the totality, the re-canonicalisation, the order/equality
//! agreement — is asserted once in [`video::tests`](super::super::video), the three citizens being
//! one macro over three rosters. What is HERE is what would be untrue if this file were a copy.

use mediaframe::codec::AudioCodec as Foreign;

use super::AudioCodec;
use crate::primitives::mediaframe::VideoCodec;

/// **EVERY ROSTER MEMBER IS A FIXPOINT OF THE DOOR** — this table, walked, as the video citizen
/// walks its own.
#[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 = AudioCodec::from(member.clone());

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

/// **THE ROSTERS ARE SEPARATE, AND THAT IS THE WHOLE REASON FOR THREE TYPES.**
///
/// `aac` is a name this vocabulary carries and `h264` is not — it reaches the escape arm here, which
/// is exactly what a single shared codec type could not have said. The claim is about the ROSTERS
/// rather than about the type system: the types cannot be confused for one another either way, and
/// what this asserts is that the separation means something at the value level too.
#[test]
fn a_video_codec_name_is_not_a_member_of_this_roster() {
  assert!(AudioCodec::new("aac").is_registered());
  assert!(AudioCodec::new("opus").is_registered());

  assert!(
    !AudioCodec::new("h264").is_registered(),
    "a video codec name reaches this roster's ESCAPE and not a member of it",
  );
  assert!(
    !VideoCodec::new("aac").is_registered(),
    "and the reading holds in the other direction",
  );

  // The escape is still lossless, so a mis-tagged stream keeps the name it was tagged with.
  assert_eq!(AudioCodec::new("h264").as_str(), "h264");
}

/// **THE DOOR FOLDS AND IS TOTAL**, over this roster's own spellings.
#[test]
fn the_door_folds_and_admits_every_string() {
  assert_eq!(AudioCodec::new("AAC"), AudioCodec::new("aac"));
  assert_eq!(AudioCodec::new("Opus"), AudioCodec::new("opus"));

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

/// **THE FOREIGN VALUE IS RE-CANONICALISED ON THE WAY IN** — the video citizen's key claim, checked
/// here too because it is the macro's row rather than one type's.
#[test]
fn the_foreign_value_is_recanonicalised_on_the_way_in() {
  let sideways = Foreign::other("aac");
  assert_ne!(sideways, Foreign::Aac, "upstream holds these apart");

  assert_eq!(AudioCodec::from(sideways).into_inner(), Foreign::Aac);
}

/// **THE TEXT FACES ARE THE CANONICAL SLUG**, through `Display`, `Debug` and the text seat.
#[test]
fn the_text_faces_are_the_canonical_slug() {
  let codec = AudioCodec::new("AAC");

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

/// **ORDERING IS ALPHABETICAL OVER THE CANONICAL SPELLING.**
#[test]
fn ordering_is_alphabetical_over_the_canonical_spelling() {
  let mut codecs = [
    AudioCodec::new("opus"),
    AudioCodec::new("aac"),
    AudioCodec::new("flac"),
  ];
  codecs.sort();

  let order: Vec<&str> = codecs.iter().map(AudioCodec::as_str).collect();
  assert_eq!(order, ["aac", "flac", "opus"]);
}