"""Unit tests for the package index naming functions."""

from __future__ import annotations

from pathlib import Path

from byteb4rb1e.sphinxcontrib.h5p.utils.pkg.index import (
    derive_names,
    dir_name_to_import_name,
    dir_name_to_src_subpath,
    repo_name_to_dir_name,
    repo_name_to_pip_name,
)


# -------------------------------------------------------------------
# repo_name_to_dir_name()
# -------------------------------------------------------------------

class TestRepoNameToDirName:
    """Tests for repo_name_to_dir_name()."""

    def test_strips_h5p_prefix(self) -> None:
        assert repo_name_to_dir_name("h5p-multi-choice") == \
            "multi_choice"

    def test_no_prefix(self) -> None:
        assert repo_name_to_dir_name("font-awesome") == \
            "font_awesome"

    def test_fork_suffix(self) -> None:
        assert repo_name_to_dir_name("h5p-interactive-book") == \
            "interactive_book"

    def test_multi_hyphen_drag_n_bar(self) -> None:
        assert repo_name_to_dir_name("h5p-drag-n-bar") == \
            "drag_n_bar"

    def test_multi_hyphen_three_sixty(self) -> None:
        assert repo_name_to_dir_name("h5p-three-sixty") == \
            "three_sixty"

    def test_multi_hyphen_iv_hotspot(self) -> None:
        assert repo_name_to_dir_name("h5p-iv-hotspot") == \
            "iv_hotspot"


# -------------------------------------------------------------------
# repo_name_to_pip_name()
# -------------------------------------------------------------------

class TestRepoNameToPipName:
    """Tests for repo_name_to_pip_name()."""

    def test_standard(self) -> None:
        assert repo_name_to_pip_name("h5p-multi-choice") == \
            "byteb4rb1e.sphinxcontrib.h5p.multi_choice"

    def test_asset(self) -> None:
        assert repo_name_to_pip_name("font-awesome") == \
            "byteb4rb1e.sphinxcontrib.h5p.font_awesome"


# -------------------------------------------------------------------
# derive_names()
# -------------------------------------------------------------------

class TestDeriveNames:
    """Tests for derive_names()."""

    def test_standard(self) -> None:
        names = derive_names("h5p-multi-choice")
        assert names == {
            "dir_name": "multi_choice",
            "pip_name": "byteb4rb1e.sphinxcontrib.h5p.multi_choice",
            "vendor_name": "h5p-multi-choice",
        }

    def test_asset(self) -> None:
        names = derive_names("font-awesome")
        assert names == {
            "dir_name": "font_awesome",
            "pip_name": "byteb4rb1e.sphinxcontrib.h5p.font_awesome",
            "vendor_name": "font-awesome",
        }

    def test_vendor_name_is_repo_name(self) -> None:
        names = derive_names("h5p-joubel-ui")
        assert names["vendor_name"] == "h5p-joubel-ui"


# -------------------------------------------------------------------
# dir_name_to_src_subpath() + dir_name_to_import_name()
# -------------------------------------------------------------------

class TestDirNameDerivations:
    """Tests for the namespace-layout helpers."""

    def test_src_subpath(self) -> None:
        assert dir_name_to_src_subpath("true_false") == \
            Path("byteb4rb1e") / "sphinxcontrib" / "h5p" / "true_false"

    def test_src_subpath_asset(self) -> None:
        assert dir_name_to_src_subpath("font_awesome") == \
            Path("byteb4rb1e") / "sphinxcontrib" / "h5p" / "font_awesome"

    def test_import_name(self) -> None:
        assert dir_name_to_import_name("true_false") == \
            "byteb4rb1e.sphinxcontrib.h5p.true_false"

    def test_import_name_matches_pip_name(self) -> None:
        # By convention for these packages, import_name == pip_name.
        assert dir_name_to_import_name("multi_choice") == \
            repo_name_to_pip_name("h5p-multi-choice")
