nixos-config/subprojects/bahaghari/tests/lib/hex.nix

79 lines
1.4 KiB
Nix
Raw Normal View History

{ pkgs, lib, self }:
2024-02-24 11:09:28 +00:00
lib.runTests {
testToHexString = {
expr = self.hex.fromDec 293454837;
2024-02-24 11:09:28 +00:00
expected = "117DC3F5";
};
testToHexString2 = {
expr = self.hex.fromDec 4500;
expected = "1194";
};
testToHexString3 = {
expr = self.hex.fromDec 5942819;
expected = "5AAE23";
};
testHexToDec = {
expr = self.hex.toDec "FF";
expected = 255;
};
testHexToDec2 = {
expr = self.hex.toDec "333FAB333";
expected = 13756969779;
};
testHexToDec3 = {
expr = self.hex.toDec "0FF";
expected = 255;
};
testHexToDec4 = {
expr = self.hex.toDec "0000FF";
expected = 255;
};
testHexToDec5 = {
expr = self.hex.toDec "0A05";
expected = 2565;
};
2024-02-24 11:09:28 +00:00
testCreateHexRange = {
expr = self.hex.range 10 17;
2024-02-24 11:09:28 +00:00
expected = [ "A" "B" "C" "D" "E" "F" "10" "11" ];
};
testCreateHexWithHigherStart = {
expr = self.hex.range 49 17;
2024-02-24 11:09:28 +00:00
expected = [ ];
};
2024-02-24 13:34:03 +00:00
testIsHexString = {
expr = self.hex.isHexString "ABC";
2024-02-24 13:34:03 +00:00
expected = true;
};
testIsHexStringWithInvalidHex = {
expr = self.hex.isHexString "WHAT IS THIS";
2024-02-24 13:34:03 +00:00
expected = false;
};
2024-02-24 13:36:51 +00:00
testHexPad = {
expr = self.hex.pad 5 "A";
2024-02-24 13:36:51 +00:00
expected = "0000A";
};
testHexPadWithLowerMaxDigits = {
expr = self.hex.pad 1 "9AC";
2024-02-24 13:36:51 +00:00
expected = "9AC";
};
testHexPadWithNegativeDigits = {
expr = self.hex.pad (-5) "A42C";
2024-02-24 13:36:51 +00:00
expected = "A42C";
};
2024-02-24 11:09:28 +00:00
}