from cargo2rpm.rpm import devel_subpackage_names
from cargo2rpm.utils import load_metadata_from_resource, short_repr

import pytest


@pytest.mark.parametrize(
    "filename,expected",
    [
        (
            "ahash-0.8.3.json",
            {"default", "atomic-polyfill", "compile-time-rng", "const-random", "getrandom", "no-rng", "runtime-rng", "serde", "std"},
        ),
        (
            "assert_cmd-2.0.8.json",
            {"default", "color", "color-auto"},
        ),
        (
            "assert_fs-1.0.10.json",
            {"default", "color", "color-auto"},
        ),
        (
            "autocfg-1.1.0.json",
            {"default"},
        ),
        (
            "bstr-1.2.0.json",
            {"default", "alloc", "serde", "std", "unicode"},
        ),
        (
            "cfg-if-1.0.0.json",
            {"default", "compiler_builtins", "core", "rustc-dep-of-std"},
        ),
        (
            "clap-4.1.4.json",
            {
                "default",
                "cargo",
                "color",
                "debug",
                "deprecated",
                "derive",
                "env",
                "error-context",
                "help",
                "std",
                "string",
                "suggestions",
                "unicode",
                "unstable-doc",
                "unstable-grouped",
                "unstable-replace",
                "unstable-v5",
                "usage",
                "wrap_help",
            },
        ),
        (
            "gstreamer-0.19.7.json",
            {"default", "dox", "serde", "serde_bytes", "v1_16", "v1_18", "v1_20", "v1_22"},
        ),
        (
            "human-panic-1.1.0.json",
            {"default", "color", "nightly"},
        ),
        (
            "hyperfine-1.15.0.json",
            set(),
        ),
        (
            "libc-0.2.139.json",
            {"default", "align", "const-extern-fn", "extra_traits", "rustc-dep-of-std", "rustc-std-workspace-core", "std", "use_std"},
        ),
        (
            "predicates-2.1.5.json",
            {"default", "color", "color-auto", "diff", "float-cmp", "normalize-line-endings", "regex", "unstable"},
        ),
        (
            "proc-macro2-1.0.50.json",
            {"default", "nightly", "proc-macro", "span-locations"},
        ),
        (
            "quote-1.0.23.json",
            {"default", "proc-macro"},
        ),
        (
            "rand-0.8.5.json",
            {
                "default",
                "alloc",
                "getrandom",
                "libc",
                "log",
                "min_const_gen",
                "nightly",
                "packed_simd",
                "rand_chacha",
                "serde",
                "serde1",
                "simd_support",
                "small_rng",
                "std",
                "std_rng",
            },
        ),
        (
            "rand_core-0.6.4.json",
            {"default", "alloc", "getrandom", "serde", "serde1", "std"},
        ),
        (
            "rpm-sequoia-1.2.0.json",
            set(),
        ),
        (
            "rust_decimal-1.28.0.json",
            {
                "default",
                "arbitrary",
                "borsh",
                "bytecheck",
                "byteorder",
                "bytes",
                "c-repr",
                "db-diesel-mysql",
                "db-diesel-postgres",
                "db-diesel1-mysql",
                "db-diesel1-postgres",
                "db-diesel2-mysql",
                "db-diesel2-postgres",
                "db-postgres",
                "db-tokio-postgres",
                "diesel1",
                "diesel2",
                "legacy-ops",
                "maths",
                "maths-nopanic",
                "postgres",
                "rand",
                "rkyv",
                "rkyv-safe",
                "rocket",
                "rocket-traits",
                "rust-fuzz",
                "serde",
                "serde-arbitrary-precision",
                "serde-bincode",
                "serde-float",
                "serde-str",
                "serde-with-arbitrary-precision",
                "serde-with-float",
                "serde-with-str",
                "serde_json",
                "std",
                "tokio-pg",
                "tokio-postgres",
            },
        ),
        (
            "rustix-0.36.8.json",
            {
                "default",
                "all-apis",
                "all-impls",
                "alloc",
                "cc",
                "compiler_builtins",
                "core",
                "fs",
                "fs-err",
                "io-lifetimes",
                "io_uring",
                "itoa",
                "libc",
                "libc_errno",
                "mm",
                "net",
                "once_cell",
                "os_pipe",
                "param",
                "process",
                "procfs",
                "rand",
                "runtime",
                "rustc-dep-of-std",
                "std",
                "termios",
                "thread",
                "time",
                "use-libc",
                "use-libc-auxv",
            },
        ),
        (
            "serde-1.0.152.json",
            {"default", "alloc", "derive", "rc", "serde_derive", "std", "unstable"},
        ),
        (
            "serde_derive-1.0.152.json",
            {"default", "deserialize_in_place"},
        ),
        (
            "sha1collisiondetection-0.3.1.json",
            {"default", "digest-trait", "oid", "std", "clap", "clap_mangen", "const-oid", "digest"},
        ),
        (
            "syn-1.0.107.json",
            {
                "default",
                "clone-impls",
                "derive",
                "extra-traits",
                "fold",
                "full",
                "parsing",
                "printing",
                "proc-macro",
                "quote",
                "test",
                "visit",
                "visit-mut",
            },
        ),
        (
            "time-0.3.17.json",
            {
                "default",
                "alloc",
                "formatting",
                "large-dates",
                "local-offset",
                "macros",
                "parsing",
                "quickcheck",
                "rand",
                "serde",
                "serde-human-readable",
                "serde-well-known",
                "std",
                "wasm-bindgen",
            },
        ),
        (
            "tokio-1.25.0.json",
            {
                "default",
                "bytes",
                "fs",
                "full",
                "io-std",
                "io-util",
                "libc",
                "macros",
                "memchr",
                "mio",
                "net",
                "num_cpus",
                "parking_lot",
                "process",
                "rt",
                "rt-multi-thread",
                "signal",
                "signal-hook-registry",
                "socket2",
                "stats",
                "sync",
                "test-util",
                "time",
                "tokio-macros",
                "tracing",
                "windows-sys",
            },
        ),
        (
            "unicode-xid-0.2.4.json",
            {"default", "bench", "no_std"},
        ),
        (
            "zbus-3.8.0.json",
            {
                "default",
                "async-executor",
                "async-io",
                "async-lock",
                "async-task",
                "chrono",
                "gvariant",
                "lazy_static",
                "quick-xml",
                "serde-xml-rs",
                "time",
                "tokio",
                "tokio-vsock",
                "url",
                "uuid",
                "vsock",
                "windows-gdbus",
                "xml",
            },
        ),
        (
            "zoxide-0.9.0.json",
            set(),
        ),
    ],
    ids=short_repr,
)
def test_devel_subpackage_names(filename: str, expected: set[str]):
    metadata = load_metadata_from_resource(filename)
    assert devel_subpackage_names(metadata.packages[0]) == expected
