//! Contracts for the served assets: `Latest` resolution and trailing newlines.
//!
//! Byte parity with an independent transform lives in `contract.rs` and
//! `generators.rs`, which rebuild the CSS and index assets from the sequence
//! set rather than reading the same file twice.

mod common;

use common::{golden, version_of, LATEST, VERSIONS};
use emoji_test_regex_pattern::{output, EmojiVersion, OutputKind};
use pretty_assertions::assert_eq;

#[test]
fn latest_equals_highest_version() {
    for kind in OutputKind::ALL {
        assert_eq!(
            output(EmojiVersion::Latest, kind),
            golden(LATEST, kind),
            "latest differs from {LATEST} for {}",
            kind.file_name()
        );
        assert_eq!(
            output(EmojiVersion::Latest, kind),
            output(EmojiVersion::V17_0, kind),
            "latest resolves to the wrong version for {}",
            kind.file_name()
        );
    }
}

#[test]
fn trailing_newline_contract() {
    for &dir in VERSIONS {
        let version = version_of(dir);
        for kind in OutputKind::ALL {
            let text = output(version, kind);
            if kind.has_trailing_newline() {
                assert!(
                    text.ends_with('\n'),
                    "{dir}/{} should end with a newline",
                    kind.file_name()
                );
            } else {
                assert!(
                    !text.ends_with('\n'),
                    "{dir}/{} should not end with a newline",
                    kind.file_name()
                );
            }
        }
    }
}
