src/render/ansi/hash/source_color_test.rs

#[cfg(test)]
mod tests {
    use crate::render::ansi::hash::source_color::{distinct_colors, pick_color};

    #[test]
    fn deterministic() {
        assert_eq!(pick_color("app.log"), pick_color("app.log"));
        assert_eq!(pick_color("worker"), pick_color("worker"));
    }

    #[test]
    fn different_inputs_pick_different_colors() {
        let a = pick_color("app.log");
        let b = pick_color("worker.log");
        assert_ne!(a, b, "pick_color should disperse common names");
    }

    #[test]
    fn empty_origin_is_stable() {
        let a = pick_color("");
        let b = pick_color("");
        assert_eq!(a, b);
    }

    #[test]
    fn distinct_colors_unique_when_palette_allows() {
        let origins = vec!["a".into(), "b".into(), "c".into(), "d".into()];
        let colors = distinct_colors(&origins);
        let unique: std::collections::HashSet<_> = colors.iter().collect();
        assert_eq!(unique.len(), origins.len());
    }

    #[test]
    fn distinct_colors_handles_over_subscription() {
        let mut origins = Vec::new();
        for i in 0..50 {
            origins.push(format!("origin-{}", i));
        }
        let colors = distinct_colors(&origins);
        assert_eq!(colors.len(), origins.len());
    }

    #[test]
    fn unicode_origin() {
        let a = pick_color("服务-a");
        let b = pick_color("服务-b");
        assert_ne!(a, b);
    }
}