Zig 0.15.1

Depends on https://github.com/lightpanda-io/zig-v8-fork/pull/89
This commit is contained in:
Karl Seguin
2025-08-28 19:42:26 +08:00
parent 94960cc842
commit 1443f38e5f
51 changed files with 508 additions and 525 deletions

View File

@@ -67,10 +67,10 @@ pub const Date = struct {
return std.math.order(a.day, b.day);
}
pub fn format(self: Date, comptime _: []const u8, _: std.fmt.FormatOptions, out: anytype) !void {
pub fn format(self: Date, writer: *std.Io.Writer) !void {
var buf: [11]u8 = undefined;
const n = writeDate(&buf, self);
try out.writeAll(buf[0..n]);
try writer.writeAll(buf[0..n]);
}
pub fn jsonStringify(self: Date, out: anytype) !void {
@@ -167,10 +167,10 @@ pub const Time = struct {
return std.math.order(a.micros, b.micros);
}
pub fn format(self: Time, comptime _: []const u8, _: std.fmt.FormatOptions, out: anytype) !void {
pub fn format(self: Time, writer: *std.Io.Writer) !void {
var buf: [15]u8 = undefined;
const n = writeTime(&buf, self);
try out.writeAll(buf[0..n]);
try writer.writeAll(buf[0..n]);
}
pub fn jsonStringify(self: Time, out: anytype) !void {
@@ -464,10 +464,10 @@ pub const DateTime = struct {
return std.math.order(a.micros, b.micros);
}
pub fn format(self: DateTime, comptime _: []const u8, _: std.fmt.FormatOptions, out: anytype) !void {
pub fn format(self: DateTime, writer: *std.Io.Writer) !void {
var buf: [28]u8 = undefined;
const n = self.bufWrite(&buf);
try out.writeAll(buf[0..n]);
try writer.writeAll(buf[0..n]);
}
pub fn jsonStringify(self: DateTime, out: anytype) !void {
@@ -510,11 +510,11 @@ fn writeDate(into: []u8, date: Date) u8 {
// the padding (we need to do it ourselfs)
const year = date.year;
if (year < 0) {
_ = std.fmt.formatIntBuf(into[1..], @as(u16, @intCast(year * -1)), 10, .lower, .{ .width = 4, .fill = '0' });
_ = std.fmt.printInt(into[1..], @as(u16, @intCast(year * -1)), 10, .lower, .{ .width = 4, .fill = '0' });
into[0] = '-';
buf = into[5..];
} else {
_ = std.fmt.formatIntBuf(into, @as(u16, @intCast(year)), 10, .lower, .{ .width = 4, .fill = '0' });
_ = std.fmt.printInt(into, @as(u16, @intCast(year)), 10, .lower, .{ .width = 4, .fill = '0' });
buf = into[4..];
}
@@ -541,12 +541,12 @@ fn writeTime(into: []u8, time: Time) u8 {
if (@rem(micros, 1000) == 0) {
into[8] = '.';
_ = std.fmt.formatIntBuf(into[9..12], micros / 1000, 10, .lower, .{ .width = 3, .fill = '0' });
_ = std.fmt.printInt(into[9..12], micros / 1000, 10, .lower, .{ .width = 3, .fill = '0' });
return 12;
}
into[8] = '.';
_ = std.fmt.formatIntBuf(into[9..15], micros, 10, .lower, .{ .width = 6, .fill = '0' });
_ = std.fmt.printInt(into[9..15], micros, 10, .lower, .{ .width = 6, .fill = '0' });
return 15;
}
@@ -730,7 +730,7 @@ test "Date: json" {
{
// date, positive year
const date = Date{ .year = 2023, .month = 9, .day = 22 };
const out = try std.json.stringifyAlloc(testing.allocator, date, .{});
const out = try std.json.Stringify.valueAlloc(testing.allocator, date, .{});
defer testing.allocator.free(out);
try testing.expectString("\"2023-09-22\"", out);
}
@@ -738,7 +738,7 @@ test "Date: json" {
{
// date, negative year
const date = Date{ .year = -4, .month = 12, .day = 3 };
const out = try std.json.stringifyAlloc(testing.allocator, date, .{});
const out = try std.json.Stringify.valueAlloc(testing.allocator, date, .{});
defer testing.allocator.free(out);
try testing.expectString("\"-0004-12-03\"", out);
}
@@ -754,13 +754,13 @@ test "Date: json" {
test "Date: format" {
{
var buf: [20]u8 = undefined;
const out = try std.fmt.bufPrint(&buf, "{s}", .{Date{ .year = 2023, .month = 5, .day = 22 }});
const out = try std.fmt.bufPrint(&buf, "{f}", .{Date{ .year = 2023, .month = 5, .day = 22 }});
try testing.expectString("2023-05-22", out);
}
{
var buf: [20]u8 = undefined;
const out = try std.fmt.bufPrint(&buf, "{s}", .{Date{ .year = -102, .month = 12, .day = 9 }});
const out = try std.fmt.bufPrint(&buf, "{f}", .{Date{ .year = -102, .month = 12, .day = 9 }});
try testing.expectString("-0102-12-09", out);
}
}
@@ -913,7 +913,7 @@ test "Time: json" {
{
// time no fraction
const time = Time{ .hour = 23, .min = 59, .sec = 2, .micros = 0 };
const out = try std.json.stringifyAlloc(testing.allocator, time, .{});
const out = try std.json.Stringify.valueAlloc(testing.allocator, time, .{});
defer testing.allocator.free(out);
try testing.expectString("\"23:59:02\"", out);
}
@@ -921,7 +921,7 @@ test "Time: json" {
{
// time, milliseconds only
const time = Time{ .hour = 7, .min = 9, .sec = 32, .micros = 202000 };
const out = try std.json.stringifyAlloc(testing.allocator, time, .{});
const out = try std.json.Stringify.valueAlloc(testing.allocator, time, .{});
defer testing.allocator.free(out);
try testing.expectString("\"07:09:32.202\"", out);
}
@@ -929,7 +929,7 @@ test "Time: json" {
{
// time, micros
const time = Time{ .hour = 1, .min = 2, .sec = 3, .micros = 123456 };
const out = try std.json.stringifyAlloc(testing.allocator, time, .{});
const out = try std.json.Stringify.valueAlloc(testing.allocator, time, .{});
defer testing.allocator.free(out);
try testing.expectString("\"01:02:03.123456\"", out);
}
@@ -945,37 +945,37 @@ test "Time: json" {
test "Time: format" {
{
var buf: [20]u8 = undefined;
const out = try std.fmt.bufPrint(&buf, "{s}", .{Time{ .hour = 23, .min = 59, .sec = 59, .micros = 0 }});
const out = try std.fmt.bufPrint(&buf, "{f}", .{Time{ .hour = 23, .min = 59, .sec = 59, .micros = 0 }});
try testing.expectString("23:59:59", out);
}
{
var buf: [20]u8 = undefined;
const out = try std.fmt.bufPrint(&buf, "{s}", .{Time{ .hour = 8, .min = 9, .sec = 10, .micros = 12 }});
const out = try std.fmt.bufPrint(&buf, "{f}", .{Time{ .hour = 8, .min = 9, .sec = 10, .micros = 12 }});
try testing.expectString("08:09:10.000012", out);
}
{
var buf: [20]u8 = undefined;
const out = try std.fmt.bufPrint(&buf, "{s}", .{Time{ .hour = 8, .min = 9, .sec = 10, .micros = 123 }});
const out = try std.fmt.bufPrint(&buf, "{f}", .{Time{ .hour = 8, .min = 9, .sec = 10, .micros = 123 }});
try testing.expectString("08:09:10.000123", out);
}
{
var buf: [20]u8 = undefined;
const out = try std.fmt.bufPrint(&buf, "{s}", .{Time{ .hour = 8, .min = 9, .sec = 10, .micros = 1234 }});
const out = try std.fmt.bufPrint(&buf, "{f}", .{Time{ .hour = 8, .min = 9, .sec = 10, .micros = 1234 }});
try testing.expectString("08:09:10.001234", out);
}
{
var buf: [20]u8 = undefined;
const out = try std.fmt.bufPrint(&buf, "{s}", .{Time{ .hour = 8, .min = 9, .sec = 10, .micros = 12345 }});
const out = try std.fmt.bufPrint(&buf, "{f}", .{Time{ .hour = 8, .min = 9, .sec = 10, .micros = 12345 }});
try testing.expectString("08:09:10.012345", out);
}
{
var buf: [20]u8 = undefined;
const out = try std.fmt.bufPrint(&buf, "{s}", .{Time{ .hour = 8, .min = 9, .sec = 10, .micros = 123456 }});
const out = try std.fmt.bufPrint(&buf, "{f}", .{Time{ .hour = 8, .min = 9, .sec = 10, .micros = 123456 }});
try testing.expectString("08:09:10.123456", out);
}
}
@@ -1625,7 +1625,7 @@ test "DateTime: json" {
{
// DateTime, time no fraction
const dt = try DateTime.parse("2023-09-22T23:59:02Z", .rfc3339);
const out = try std.json.stringifyAlloc(testing.allocator, dt, .{});
const out = try std.json.Stringify.valueAlloc(testing.allocator, dt, .{});
defer testing.allocator.free(out);
try testing.expectString("\"2023-09-22T23:59:02Z\"", out);
}
@@ -1633,7 +1633,7 @@ test "DateTime: json" {
{
// time, milliseconds only
const dt = try DateTime.parse("2023-09-22T07:09:32.202Z", .rfc3339);
const out = try std.json.stringifyAlloc(testing.allocator, dt, .{});
const out = try std.json.Stringify.valueAlloc(testing.allocator, dt, .{});
defer testing.allocator.free(out);
try testing.expectString("\"2023-09-22T07:09:32.202Z\"", out);
}
@@ -1641,7 +1641,7 @@ test "DateTime: json" {
{
// time, micros
const dt = try DateTime.parse("-0004-12-03T01:02:03.123456Z", .rfc3339);
const out = try std.json.stringifyAlloc(testing.allocator, dt, .{});
const out = try std.json.Stringify.valueAlloc(testing.allocator, dt, .{});
defer testing.allocator.free(out);
try testing.expectString("\"-0004-12-03T01:02:03.123456Z\"", out);
}
@@ -1657,37 +1657,37 @@ test "DateTime: json" {
test "DateTime: format" {
{
var buf: [30]u8 = undefined;
const out = try std.fmt.bufPrint(&buf, "{s}", .{try DateTime.initUTC(2023, 5, 22, 23, 59, 59, 0)});
const out = try std.fmt.bufPrint(&buf, "{f}", .{try DateTime.initUTC(2023, 5, 22, 23, 59, 59, 0)});
try testing.expectString("2023-05-22T23:59:59Z", out);
}
{
var buf: [30]u8 = undefined;
const out = try std.fmt.bufPrint(&buf, "{s}", .{try DateTime.initUTC(2023, 5, 22, 8, 9, 10, 12)});
const out = try std.fmt.bufPrint(&buf, "{f}", .{try DateTime.initUTC(2023, 5, 22, 8, 9, 10, 12)});
try testing.expectString("2023-05-22T08:09:10.000012Z", out);
}
{
var buf: [30]u8 = undefined;
const out = try std.fmt.bufPrint(&buf, "{s}", .{try DateTime.initUTC(2023, 5, 22, 8, 9, 10, 123)});
const out = try std.fmt.bufPrint(&buf, "{f}", .{try DateTime.initUTC(2023, 5, 22, 8, 9, 10, 123)});
try testing.expectString("2023-05-22T08:09:10.000123Z", out);
}
{
var buf: [30]u8 = undefined;
const out = try std.fmt.bufPrint(&buf, "{s}", .{try DateTime.initUTC(2023, 5, 22, 8, 9, 10, 1234)});
const out = try std.fmt.bufPrint(&buf, "{f}", .{try DateTime.initUTC(2023, 5, 22, 8, 9, 10, 1234)});
try testing.expectString("2023-05-22T08:09:10.001234Z", out);
}
{
var buf: [30]u8 = undefined;
const out = try std.fmt.bufPrint(&buf, "{s}", .{try DateTime.initUTC(-102, 12, 9, 8, 9, 10, 12345)});
const out = try std.fmt.bufPrint(&buf, "{f}", .{try DateTime.initUTC(-102, 12, 9, 8, 9, 10, 12345)});
try testing.expectString("-0102-12-09T08:09:10.012345Z", out);
}
{
var buf: [30]u8 = undefined;
const out = try std.fmt.bufPrint(&buf, "{s}", .{try DateTime.initUTC(-102, 12, 9, 8, 9, 10, 123456)});
const out = try std.fmt.bufPrint(&buf, "{f}", .{try DateTime.initUTC(-102, 12, 9, 8, 9, 10, 123456)});
try testing.expectString("-0102-12-09T08:09:10.123456Z", out);
}
}
@@ -2075,7 +2075,7 @@ test "DateTime: sub" {
fn expectDateTime(expected: []const u8, dt: DateTime) !void {
var buf: [30]u8 = undefined;
const actual = try std.fmt.bufPrint(&buf, "{s}", .{dt});
const actual = try std.fmt.bufPrint(&buf, "{f}", .{dt});
try testing.expectString(expected, actual);
}