import sys

import pytest

from clarabot_nano.utility.path.java import java_compatible_absolute_path
from clarabot_nano.utility.path.validate import ValidationError
from clarabot_nano_tests.utility.path.validate.test_denormalize_absolute import (
    DENORMALIZE_INVALID_PATHS_ALL_,
    DENORMALIZE_ABSOLUTE_PATHS_ROOT_NT_,
    DENORMALIZE_ABSOLUTE_PATHS_NT_,
    DENORMALIZE_ABSOLUTE_PATHS_POSIX_,
)


@pytest.mark.skipif(sys.platform.startswith("win"), reason="for posix only")
def test_utility_path_java_compatible_absolute_path_posix():
    for p in (
        DENORMALIZE_INVALID_PATHS_ALL_
        + DENORMALIZE_ABSOLUTE_PATHS_ROOT_NT_
        + DENORMALIZE_ABSOLUTE_PATHS_NT_
        + DENORMALIZE_ABSOLUTE_PATHS_POSIX_
    ):
        assert java_compatible_absolute_path(p) == str(p)


@pytest.mark.skipif(not sys.platform.startswith("win"), reason="for windows only")
def test_utility_path_java_compatible_absolute_path_nt():
    for p in DENORMALIZE_ABSOLUTE_PATHS_ROOT_NT_:
        assert java_compatible_absolute_path(p) == "C:\\"
    for p in DENORMALIZE_ABSOLUTE_PATHS_NT_:
        assert java_compatible_absolute_path(p) == "C:\\x\\y"
    for p in DENORMALIZE_ABSOLUTE_PATHS_POSIX_ + DENORMALIZE_INVALID_PATHS_ALL_:
        with pytest.raises(ValidationError):
            java_compatible_absolute_path(p)
