Debian Codegraph @

tests/test_base32_decode.py

raw symbols SCIP
1 """Tests for Crockford base32 decoding edge cases (case + aliases)."""
2
3 import pytest
4
5 _REF_ULID = "01GTCKZT7K26YEVVW6AMQ3J0VT"
6 _REF_BYTES = b"\x01\x86\x99?\xe8\xf3\x11\xbc\xed\xef\x86U.9\x03z"
7
8
9 def test_lowercase_decodes_same_as_uppercase(impl):
10 assert impl.ulid_to_bytes(_REF_ULID.lower()) == _REF_BYTES
11
12
13 @pytest.mark.parametrize(
14 "ulid",
15 [
16 "01gtCKZT7K26YEVVW6AMQ3J0VT",
17 "01GtCkZt7k26yEvVw6amq3j0vt",
18 "01GTCKZT7K26YEVVW6AMQ3J0vt",
19 ],
20 )
21 def test_mixed_case_decodes(impl, ulid):
22 assert impl.ulid_to_bytes(ulid) == _REF_BYTES
23
24
25 @pytest.mark.parametrize(
26 ("alias", "canon"),
27 [("I", "1"), ("i", "1"), ("L", "1"), ("l", "1"), ("O", "0"), ("o", "0")],
28 )
29 def test_crockford_aliases(impl, alias, canon):
30 """I/L (any case) decode as 1, O (any case) decodes as 0."""
31 aliased = alias + _REF_ULID[1:]
32 canonical = canon + _REF_ULID[1:]
33 assert impl.ulid_to_bytes(aliased) == impl.ulid_to_bytes(canonical)
34
35
36 @pytest.mark.parametrize("char", ["U", "u"])
37 def test_u_remains_excluded(impl, char):
38 """Crockford excludes U from the alphabet entirely.
39
40 Both implementations treat U the same (invalid -> 0xFF lookup),
41 so decoding does not raise but the result is implementation-defined.
42 The contract is that C and Python produce identical output.
43 """
44 candidate = char + _REF_ULID[1:]
45 # No exception, and length is preserved
46 assert len(impl.ulid_to_bytes(candidate)) == 16