import pytest

from debputy.util import debian_policy_normalize_symlink_target


@pytest.mark.parametrize(
    "link_path,link_target,expected",
    [
        ("usr/share/doc/pkg/my-symlink", "/etc/foo.conf", "/etc/foo.conf"),
        ("usr/share/doc/pkg/my-symlink", "/usr/share/doc/pkg", "."),
        ("usr/share/doc/pkg/my-symlink", "/usr/share/doc/pkg/.", "."),
        ("usr/share/doc/pkg/my-symlink", "/usr/share/bar/../doc/pkg/.", "."),
        (
            "usr/share/doc/pkg/my-symlink",
            "/usr/share/bar/../doc/pkg/../other-pkg",
            "../other-pkg",
        ),
        ("usr/share/doc/pkg/my-symlink", "/usr/share/doc/other-pkg/.", "../other-pkg"),
        ("usr/share/doc/pkg/my-symlink", "../other-pkg/.", "../other-pkg"),
        ("usr/share/doc/pkg/my-symlink", "/usr/share/doc/other-pkg", "../other-pkg"),
        ("usr/share/doc/pkg/my-symlink", "../other-pkg", "../other-pkg"),
        (
            "usr/share/doc/pkg/my-symlink",
            "/usr/share/doc/pkg/../../../../etc/foo.conf",
            "/etc/foo.conf",
        ),
    ],
)
def test_generate_deb_filename(link_path, link_target, expected):
    actual = debian_policy_normalize_symlink_target(
        link_path,
        link_target,
        normalize_link_path=True,
    )
    assert actual == expected
