Files
c3c/test/unit/stdlib/time/time.c3
Pierre Curto 7a39933c97 add NanoDuration.to_format() (#935)
* lib/std/time: avoid switch in DateTime.compare_to()
* lib/std/time: add NanoDuration.to_format()
* std/lib: fix #934
2023-08-17 10:30:20 +02:00

29 lines
960 B
Plaintext

module nanoduration_test @test;
import std::io;
import std::time;
fn void! to_format()
{
char[32] buffer;
char[] buf;
buf = io::bprintf(buffer[..], "%s", (NanoDuration)123)!;
assert(buf == "123ns", "got %s; want 123ns", buf);
buf = io::bprintf(buffer[..], "%s", (NanoDuration)123_000)!;
assert(buf == "123µs", "got %s; want 123µs", buf);
buf = io::bprintf(buffer[..], "%s", (NanoDuration)123_000_000)!;
assert(buf == "123ms", "got %s; want 123ms", buf);
buf = io::bprintf(buffer[..], "%s", (NanoDuration)13_000_000_000)!;
assert(buf == "13s", "got %s; want 13s", buf);
buf = io::bprintf(buffer[..], "%s", (NanoDuration)123_000_000_000)!;
assert(buf == "2m3s", "got %s; want 2m3s", buf);
buf = io::bprintf(buffer[..], "%s", (NanoDuration)12345_000_000_000)!;
assert(buf == "3h25m45s", "got %s; want 3h25m45s", buf);
buf = io::bprintf(buffer[..], "%s", (NanoDuration)12_100_000_000)!;
assert(buf == "12.1s", "got %s; want 12.1s", buf);
}