lib: fix overflowing fromHexString tests and example (#433710)

This commit is contained in:
Emily
2025-08-16 13:25:31 +01:00
committed by GitHub
2 changed files with 28 additions and 3 deletions

View File

@@ -386,8 +386,9 @@ runTests {
expected = 255;
};
testFromHexStringSecondExample = {
expr = fromHexString (builtins.hashString "sha256" "test");
# Highest supported integer value in Nix.
testFromHexStringMaximum = {
expr = fromHexString "7fffffffffffffff";
expected = 9223372036854775807;
};
@@ -396,6 +397,30 @@ runTests {
expected = 15;
};
# FIXME: This might be bad and should potentially be deprecated.
testFromHexStringQuestionableMixedCase = {
expr = fromHexString "eEeEe";
expected = 978670;
};
# FIXME: This is probably bad and should potentially be deprecated.
testFromHexStringQuestionableUnderscore = {
expr = fromHexString "F_f";
expected = 255;
};
# FIXME: This is definitely bad and should be deprecated.
testFromHexStringBadComment = {
expr = fromHexString "0 # oops";
expected = 0;
};
# FIXME: Oh my god.
testFromHexStringAwfulInjection = {
expr = fromHexString "1\nwhoops = {}";
expected = 1;
};
testToBaseDigits = {
expr = toBaseDigits 2 6;
expected = [

View File

@@ -1114,7 +1114,7 @@ in
fromHexString "FF"
=> 255
fromHexString (builtins.hashString "sha256" "test")
fromHexString "0x7fffffffffffffff"
=> 9223372036854775807
```
*/