from server.utils.unix_ls import format_owner_label, parse_ls_la_line, perms_to_mode_octal


def test_perms_to_mode_octal_file():
    assert perms_to_mode_octal("-rw-r--r--") == "644"


def test_perms_to_mode_octal_dir():
    assert perms_to_mode_octal("drwxr-xr-x") == "755"


def test_format_owner_label():
    assert format_owner_label("www", "www") == "www"
    assert format_owner_label("www", "nogroup") == "www:nogroup"


def test_parse_ls_la_line_directory():
    row = parse_ls_la_line("drwxr-xr-x 3 www www 4096 Jun  1 2025 public")
    assert row is not None
    assert row["is_dir"] is True
    assert row["name"] == "public"
