import re

import pytest

from a11yviz import simulate_cvd


def test_returns_same_length_valid_hex():
    out = simulate_cvd(["#1B9E77", "#D95F02"])
    assert len(out) == 2
    assert all(re.match(r"^#[0-9A-Fa-f]{6}$", c) for c in out)


def test_greyscale_collapses_rgb_channels():
    (out,) = simulate_cvd(["#FF0000"], type="greyscale")
    r, g, b = int(out[1:3], 16), int(out[3:5], 16), int(out[5:7], 16)
    assert r == g == b


def test_invalid_type_raises():
    with pytest.raises(ValueError, match="type must be"):
        simulate_cvd(["#000000"], type="purple")


def test_each_named_type_returns_hex():
    for t in ("protan", "deutan", "tritan", "greyscale"):
        assert len(simulate_cvd(["#1B9E77", "#D95F02"], type=t)) == 2
