mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-03 03:41:04 +01:00
Global: add new unit related options
1. `--<module>-space-before-unit` 2. `--duration-abbreviation` 3. various code refactoring and cleanups
This commit is contained in:
+51
-2
@@ -1,4 +1,4 @@
|
||||
#include "common/parsing.h"
|
||||
#include "common/duration.h"
|
||||
#include "util/textModifier.h"
|
||||
#include "fastfetch.h"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
static void verify(uint64_t totalSeconds, const char* expected, int lineNo)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate();
|
||||
ffParseDuration(totalSeconds, &result);
|
||||
ffDurationAppendNum(totalSeconds, &result);
|
||||
if (!ffStrbufEqualS(&result, expected))
|
||||
{
|
||||
fprintf(stderr, FASTFETCH_TEXT_MODIFIER_ERROR "[%d] %llu: expected \"%s\", got \"%s\"\n" FASTFETCH_TEXT_MODIFIER_RESET, lineNo, (unsigned long long) totalSeconds, expected, result.chars);
|
||||
@@ -66,6 +66,55 @@ int main(void)
|
||||
VERIFY(60 * 60 * 24 * 100, "100 days(!)");
|
||||
VERIFY(60 * 60 * 24 * 200, "200 days(!)");
|
||||
|
||||
instance.config.display.durationAbbreviation = true;
|
||||
instance.config.display.durationSpaceBeforeUnit = FF_SPACE_BEFORE_UNIT_NEVER;
|
||||
// Test seconds less than 60
|
||||
VERIFY(0, "0secs");
|
||||
VERIFY(1, "1sec");
|
||||
VERIFY(2, "2secs");
|
||||
VERIFY(59, "59secs");
|
||||
|
||||
// Test minute rounding (when seconds >= 30)
|
||||
VERIFY(60, "1m");
|
||||
VERIFY(60 + 29, "1m");
|
||||
VERIFY(60 + 30, "2m");
|
||||
|
||||
// Test only minutes
|
||||
VERIFY(60 * 2 - 1, "2m");
|
||||
VERIFY(60 * 2, "2m");
|
||||
VERIFY(60 * 59 + 29, "59m");
|
||||
|
||||
// Test only hours (no minutes)
|
||||
VERIFY(60 * 59 + 30, "1h");
|
||||
VERIFY(60 * 60, "1h");
|
||||
VERIFY(2 * 60 * 60, "2h");
|
||||
VERIFY(23 * 60 * 60, "23h");
|
||||
|
||||
// Test combination of hours and minutes
|
||||
VERIFY(60 * 60 + 60, "1h 1m");
|
||||
VERIFY(60 * 60 + 60 * 2, "1h 2m");
|
||||
VERIFY(60 * 60 * 2 + 60 + 29, "2h 1m");
|
||||
VERIFY(60 * 60 * 2 + 60 + 30, "2h 2m");
|
||||
|
||||
// Test days
|
||||
VERIFY(60 * 60 * 24, "1d");
|
||||
VERIFY(60 * 60 * 24 - 1, "1d");
|
||||
VERIFY(60 * 60 * 24 * 2, "2d");
|
||||
|
||||
// Test combination of days and hours
|
||||
VERIFY(60 * 60 * 24 + 60 * 60, "1d 1h");
|
||||
VERIFY(60 * 60 * 24 * 2 + 60 * 60, "2d 1h");
|
||||
VERIFY(60 * 60 * 24 * 2 + 60 * 60 * 2, "2d 2h");
|
||||
|
||||
// Test combination of days, hours, and minutes
|
||||
VERIFY(60 * 60 * 24 + 60 * 60 + 60, "1d 1h 1m");
|
||||
VERIFY(60 * 60 * 24 * 2 + 60 * 60 + 60 * 2, "2d 1h 2m");
|
||||
VERIFY(60 * 60 * 24 * 2 + 60 * 2, "2d 2m");
|
||||
|
||||
// Test very large number of days
|
||||
VERIFY(60 * 60 * 24 * 100, "100d");
|
||||
VERIFY(60 * 60 * 24 * 200, "200d");
|
||||
|
||||
//Success
|
||||
puts("\033[32mAll tests passed!" FASTFETCH_TEXT_MODIFIER_RESET);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user