| 11 | #include "fl/stl/string.h" |
| 12 | |
| 13 | FL_TEST_FILE(FL_FILEPATH) { |
| 14 | |
| 15 | using namespace fl; |
| 16 | |
| 17 | // ============================================================================ |
| 18 | // Hexadecimal Conversion Tests |
| 19 | // ============================================================================ |
| 20 | |
| 21 | FL_TEST_CASE("fl::to_hex - zero value") { |
| 22 | FL_SUBCASE("zero") { |
| 23 | // Default behavior is minimal representation |
| 24 | FL_CHECK_EQ(to_hex(0), "0"); |
| 25 | FL_CHECK_EQ(to_hex(0, false), "0"); |
| 26 | FL_CHECK_EQ(to_hex(0, true), "0"); |
| 27 | // With padding enabled |
| 28 | FL_CHECK_EQ(to_hex(0, false, true), "00000000"); |
| 29 | FL_CHECK_EQ(to_hex(0, true, true), "00000000"); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | FL_TEST_CASE("fl::to_hex - positive integers") { |
| 34 | FL_SUBCASE("single digit") { |
| 35 | // Default behavior is minimal representation |
| 36 | FL_CHECK_EQ(to_hex(1), "1"); |
| 37 | FL_CHECK_EQ(to_hex(9), "9"); |
| 38 | FL_CHECK_EQ(to_hex(15), "f"); |
| 39 | FL_CHECK_EQ(to_hex(15, true), "F"); |
| 40 | // With padding enabled (int is 32-bit = 8 hex chars) |
| 41 | FL_CHECK_EQ(to_hex(1, false, true), "00000001"); |
| 42 | FL_CHECK_EQ(to_hex(15, true, true), "0000000F"); |
| 43 | } |
| 44 | |
| 45 | FL_SUBCASE("multiple digits") { |
| 46 | // Minimal representation |
| 47 | FL_CHECK_EQ(to_hex(16), "10"); |
| 48 | FL_CHECK_EQ(to_hex(255), "ff"); |
| 49 | FL_CHECK_EQ(to_hex(255, true), "FF"); |
| 50 | FL_CHECK_EQ(to_hex(256), "100"); |
| 51 | FL_CHECK_EQ(to_hex(4095), "fff"); |
| 52 | FL_CHECK_EQ(to_hex(4095, true), "FFF"); |
| 53 | // With padding enabled |
| 54 | FL_CHECK_EQ(to_hex(255, false, true), "000000ff"); |
| 55 | FL_CHECK_EQ(to_hex(4095, true, true), "00000FFF"); |
| 56 | } |
| 57 | |
| 58 | FL_SUBCASE("large values") { |
| 59 | FL_CHECK_EQ(to_hex(65535), "ffff"); |
| 60 | FL_CHECK_EQ(to_hex(65535, true), "FFFF"); |
| 61 | FL_CHECK_EQ(to_hex(0xDEADBEEF), "deadbeef"); |
| 62 | FL_CHECK_EQ(to_hex(0xDEADBEEF, true), "DEADBEEF"); |
| 63 | // With padding enabled |
| 64 | FL_CHECK_EQ(to_hex(65535, false, true), "0000ffff"); |
| 65 | FL_CHECK_EQ(to_hex(0xDEADBEEF, true, true), "DEADBEEF"); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | FL_TEST_CASE("fl::to_hex - negative integers") { |
| 70 | FL_SUBCASE("negative values") { |