test: split out properties test

This commit is contained in:
Nurul Huda (Apon) 2026-05-27 12:13:52 +06:00
parent 2f5da6c195
commit ba5b777de4
No known key found for this signature in database
GPG key ID: 5D3F1DE2855A2F79
2 changed files with 88 additions and 0 deletions

View file

@ -430,6 +430,43 @@ test until {
try std.testing.expectEqual(@as(i64, 6), dur.months()); try std.testing.expectEqual(@as(i64, 6), dur.months());
} }
test calendarId {
const ym = try from("2021-07-01[u-ca=gregory]");
const cal_id = try ym.calendarId(std.testing.allocator);
defer std.testing.allocator.free(cal_id);
try std.testing.expectEqualStrings("gregory", cal_id);
}
test year {
const ym = try from("2021-07");
try std.testing.expectEqual(@as(i32, 2021), ym.year());
}
test month {
const ym = try from("2021-07");
try std.testing.expectEqual(@as(u8, 7), ym.month());
}
test monthCode {
const ym = try from("2021-07");
const month_code = try ym.monthCode(std.testing.allocator);
defer std.testing.allocator.free(month_code);
try std.testing.expectEqualStrings("M07", month_code);
}
test era {
const ym = try from("2021-07-01[u-ca=gregory]");
const maybe_era = try ym.era(std.testing.allocator);
const era_value = maybe_era orelse return error.TestUnexpectedResult;
defer std.testing.allocator.free(era_value);
try std.testing.expectEqualStrings("ce", era_value);
}
test eraYear {
const ym = try from("2021-07-01[u-ca=gregory]");
try std.testing.expectEqual(@as(?i32, 2021), ym.eraYear());
}
test with { test with {
// Test modifying year // Test modifying year
const ym1 = try init(2024, 6, null); const ym1 = try init(2024, 6, null);

View file

@ -805,6 +805,12 @@ test calendarId {
try std.testing.expect(cal_id.len > 0); try std.testing.expect(cal_id.len > 0);
} }
test day {
const zdt = try from("2021-01-02T12:00:00+00:00[UTC]", null, .compatible, .reject);
defer zdt.deinit();
try std.testing.expectEqual(@as(u8, 2), zdt.day());
}
test dayOfWeek { test dayOfWeek {
const zdt = try from("2021-01-01T12:00:00+00:00[UTC]", null, .compatible, .reject); const zdt = try from("2021-01-01T12:00:00+00:00[UTC]", null, .compatible, .reject);
defer zdt.deinit(); defer zdt.deinit();
@ -872,6 +878,12 @@ test eraYear {
} }
} }
test hour {
const zdt = try from("2021-01-01T12:00:00+00:00[UTC]", null, .compatible, .reject);
defer zdt.deinit();
try std.testing.expectEqual(@as(u8, 12), zdt.hour());
}
test hoursInDay { test hoursInDay {
const zdt = try from("2021-01-01T12:00:00+00:00[UTC]", null, .compatible, .reject); const zdt = try from("2021-01-01T12:00:00+00:00[UTC]", null, .compatible, .reject);
defer zdt.deinit(); defer zdt.deinit();
@ -896,6 +908,24 @@ test microsecond {
try std.testing.expect(us >= 0 and us < 1000); try std.testing.expect(us >= 0 and us < 1000);
} }
test millisecond {
const zdt = try from("2021-01-01T12:00:00.123456789+00:00[UTC]", null, .compatible, .reject);
defer zdt.deinit();
try std.testing.expectEqual(@as(u16, 123), zdt.millisecond());
}
test minute {
const zdt = try from("2021-01-01T12:34:00+00:00[UTC]", null, .compatible, .reject);
defer zdt.deinit();
try std.testing.expectEqual(@as(u8, 34), zdt.minute());
}
test month {
const zdt = try from("2021-07-01T12:00:00+00:00[UTC]", null, .compatible, .reject);
defer zdt.deinit();
try std.testing.expectEqual(@as(u8, 7), zdt.month());
}
test monthCode { test monthCode {
const zdt = try from("2021-01-01T12:00:00+00:00[UTC]", null, .compatible, .reject); const zdt = try from("2021-01-01T12:00:00+00:00[UTC]", null, .compatible, .reject);
defer zdt.deinit(); defer zdt.deinit();
@ -933,6 +963,21 @@ test offsetNanoseconds {
try std.testing.expectEqual(@as(i64, 0), off_ns); try std.testing.expectEqual(@as(i64, 0), off_ns);
} }
test second {
const zdt = try from("2021-01-01T12:34:56+00:00[UTC]", null, .compatible, .reject);
defer zdt.deinit();
try std.testing.expectEqual(@as(u8, 56), zdt.second());
}
test timeZoneId {
const zdt = try from("2021-01-01T12:00:00+00:00[UTC]", null, .compatible, .reject);
defer zdt.deinit();
const id = try zdt.timeZoneId(std.testing.allocator);
defer std.testing.allocator.free(id);
try std.testing.expectEqualStrings("UTC", id);
}
test weekOfYear { test weekOfYear {
const zdt = try from("2021-01-01T12:00:00+00:00[UTC]", null, .compatible, .reject); const zdt = try from("2021-01-01T12:00:00+00:00[UTC]", null, .compatible, .reject);
defer zdt.deinit(); defer zdt.deinit();
@ -942,6 +987,12 @@ test weekOfYear {
} }
} }
test year {
const zdt = try from("2021-01-01T12:00:00+00:00[UTC]", null, .compatible, .reject);
defer zdt.deinit();
try std.testing.expectEqual(@as(i32, 2021), zdt.year());
}
test yearOfWeek { test yearOfWeek {
const zdt = try from("2021-01-01T12:00:00+00:00[UTC]", null, .compatible, .reject); const zdt = try from("2021-01-01T12:00:00+00:00[UTC]", null, .compatible, .reject);
defer zdt.deinit(); defer zdt.deinit();