-
Notifications
You must be signed in to change notification settings - Fork 15
Fix hardcoded zeros for encode(0, ...) and padding
#27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| import base62 | ||
|
|
||
|
|
||
| CHARSET_QWERTY = "1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm" | ||
|
|
||
| bytes_int_pairs = [ | ||
| (b"\x01", 1), | ||
| (b"\x01\x01", 0x0101), | ||
|
|
@@ -39,6 +41,18 @@ def test_basic_inverted(): | |
| assert base62.decode("base62", **kwargs) == 10231951886 | ||
|
|
||
|
|
||
| def test_basic_qwerty(): | ||
| kwargs = {"charset": CHARSET_QWERTY} | ||
|
|
||
| assert base62.encode(0, **kwargs) == "1" | ||
| assert base62.decode("1", **kwargs) == 0 | ||
| assert base62.decode("1111", **kwargs) == 0 | ||
| assert base62.decode("111112", **kwargs) == 1 | ||
|
Comment on lines
+44
to
+50
|
||
|
|
||
| assert base62.encode(54742896343, **kwargs) == "base62" | ||
| assert base62.decode("base62", **kwargs) == 54742896343 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("b, i", bytes_int_pairs) | ||
| def test_bytes_to_int(b, i): | ||
| assert int.from_bytes(b, "big") == i | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment describing leading-zero padding is now inaccurate: the marker is no longer the literal string "0", but
charset[0]. Please update the comment so it matches the new behavior (and avoids confusing readers when using non-default charsets).