|
| 1 | +#include "common/format.h" |
| 2 | +#include "util/textModifier.h" |
| 3 | +#include "fastfetch.h" |
| 4 | + |
| 5 | +#include <stdlib.h> |
| 6 | + |
| 7 | +static void verify(const char* color, const char* expected, int lineNo) |
| 8 | +{ |
| 9 | + FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate(); |
| 10 | + ffOptionParseColorNoClear(color, &result); |
| 11 | + if (!ffStrbufEqualS(&result, expected)) |
| 12 | + { |
| 13 | + fprintf(stderr, FASTFETCH_TEXT_MODIFIER_ERROR "[%d] %s: expected \"%s\", got \"%s\"\n" FASTFETCH_TEXT_MODIFIER_RESET, lineNo, color, expected, result.chars); |
| 14 | + exit(1); |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +#define VERIFY(color, expected) verify((color), (expected), __LINE__) |
| 19 | + |
| 20 | +int main(void) |
| 21 | +{ |
| 22 | + instance.config.display.pipe = true; |
| 23 | + // Initialize dummy config colors for property tests |
| 24 | + ffStrbufInitS(&instance.config.display.colorKeys, "94"); // light_blue |
| 25 | + ffStrbufInitS(&instance.config.display.colorTitle, "95"); // light_magenta |
| 26 | + |
| 27 | + { |
| 28 | + VERIFY("", ""); |
| 29 | + VERIFY("1", "1"); |
| 30 | + |
| 31 | + VERIFY("red", "31"); |
| 32 | + VERIFY("light_green", "92"); |
| 33 | + VERIFY("default", "39"); |
| 34 | + VERIFY("blue", "34"); |
| 35 | + VERIFY("light_cyan", "96"); |
| 36 | + |
| 37 | + VERIFY("bold_red", "1;31"); |
| 38 | + VERIFY("dim_light_yellow", "2;93"); |
| 39 | + VERIFY("italic_underline_green", "3;4;32"); |
| 40 | + VERIFY("reset_blue", "0;34"); // Reset followed by color |
| 41 | + |
| 42 | + VERIFY("#ff0000", "38;2;255;0;0"); // RRGGBB |
| 43 | + VERIFY("#0f0", "38;2;0;255;0"); // RGB |
| 44 | + VERIFY("#123456", "38;2;18;52;86"); |
| 45 | + VERIFY("#abc", "38;2;170;187;204"); |
| 46 | + |
| 47 | + VERIFY("bold_#ff00ff", "1;38;2;255;0;255"); |
| 48 | + VERIFY("underline_#123", "4;38;2;17;34;51"); |
| 49 | + |
| 50 | + VERIFY("\e[32m", "32"); // Direct ANSI code |
| 51 | + VERIFY("\e[1;94m", "1;94"); // Direct ANSI code with mode |
| 52 | + |
| 53 | + // Property colors (ensure dummy config colors are set) |
| 54 | + VERIFY("keys", "94"); |
| 55 | + VERIFY("title", "95"); |
| 56 | + VERIFY("bold_keys", "1;94"); |
| 57 | + } |
| 58 | + |
| 59 | + // Clean up dummy config colors |
| 60 | + ffStrbufDestroy(&instance.config.display.colorKeys); |
| 61 | + ffStrbufDestroy(&instance.config.display.colorTitle); |
| 62 | + |
| 63 | + //Success |
| 64 | + puts("\033[32mAll tests passed!" FASTFETCH_TEXT_MODIFIER_RESET); |
| 65 | +} |
0 commit comments