from uuid import UUID

from slices_typeid import TypeID


def test_from_str_1():
    actual = TypeID.from_string("r_example.com_01kjsxktfrf70agz88x0k1vzy5")
    expected = TypeID(type="r", domain="example.com", suffix="01kjsxktfrf70agz88x0k1vzy5")
    assert actual == expected

    assert actual.uuid == UUID("019cb3d9-e9f8-79c0-a87d-08e8261dffc5")
    assert str(actual) == "r_example.com_01kjsxktfrf70agz88x0k1vzy5"
    assert actual.type == "r"
    assert actual.domain == "example.com"
    assert actual.suffix == "01kjsxktfrf70agz88x0k1vzy5"


def test_from_str_2():
    # type of max length, domain of max length
    actual = TypeID.from_string(
        "abcdef_a.domain.with.the.maximum.length.of.56.char.example.com_53ybemfd0z9nmrbamprmd2gdym"
    )
    expected = TypeID(
        type="abcdef",
        domain="a.domain.with.the.maximum.length.of.56.char.example.com",
        suffix="53ybemfd0z9nmrbamprmd2gdym",
    )
    assert actual == expected

    assert actual.uuid == UUID("a3f2dd47-b41f-4d69-85aa-96c51a2837d4")
    assert str(actual) == "abcdef_a.domain.with.the.maximum.length.of.56.char.example.com_53ybemfd0z9nmrbamprmd2gdym"
    assert actual.type == "abcdef"
    assert actual.domain == "a.domain.with.the.maximum.length.of.56.char.example.com"
    assert actual.suffix == "53ybemfd0z9nmrbamprmd2gdym"


def test_from_str_3():
    # domain of minimal length, nil UUID
    actual = TypeID.from_string("n_ex_00000000000000000000000000")
    expected = TypeID(type="n", domain="ex", suffix="00000000000000000000000000")
    assert actual == expected

    assert actual.uuid == UUID("00000000-0000-0000-0000-000000000000")
    assert str(actual) == "n_ex_00000000000000000000000000"
    assert actual.type == "n"
    assert actual.domain == "ex"
    assert actual.suffix == "00000000000000000000000000"
