authorgravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-07-20 00:14:55-07:00
committergravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-09-26 12:35:38-07:00
log6d21ffce6ee79bba8238db9f8012579f3cec7e57
tree13925c886d0f889de7ec1c3a4a06a8c248614fa2
parenta5bfa7aa453f2a061791501339044db452b93df5

Use clearer conventions for diagnostics


1 files changed, 517 insertions(+), 516 deletions(-)

lib/std/zon/parse.zig+517-516
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4//! * `fromZoir`/`fromZoirAlloc`4//! * `fromZoir`/`fromZoirAlloc`
5//!5//!
6//! To update an existing values, see the `updateFrom*` variants. To get human readable errors, use6//! To update an existing values, see the `updateFrom*` variants. To get human readable errors, use
7//! the `diag` option. For lower level control over parsing, see `std.zig.Zoir`. For importing ZON7//! the `errors` option. For lower level control over parsing, see `std.zig.Zoir`. For importing ZON
8//! at compile time, use `@import`.8//! at compile time, use `@import`.
99
10const std = @import("std");10const std = @import("std");
...@@ -23,6 +23,7 @@ const ArenaAllocator = std.heap.ArenaAllocator;...@@ -23,6 +23,7 @@ const ArenaAllocator = std.heap.ArenaAllocator;
23/// Rename when adding or removing support for a type.23/// Rename when adding or removing support for a type.
24const valid_types = {};24const valid_types = {};
2525
26/// An error encountered while parsing ZON.
26pub const Error = struct {27pub const Error = struct {
27 msg: []const u8,28 msg: []const u8,
28 loc: Ast.Location,29 loc: Ast.Location,
...@@ -90,20 +91,20 @@ pub const Error = struct {...@@ -90,20 +91,20 @@ pub const Error = struct {
90 };91 };
91};92};
9293
93/// Human readable information about the success or failure of a parse.94/// Errors encountered while parsing ZON.
94pub const Diagnostics = struct {95pub const Errors = struct {
95 arena: Allocator,96 arena: Allocator,
96 compile_errors: std.ArrayList(Error),97 list: std.ArrayList(Error),
9798
98 pub fn init(arena: Allocator) @This() {99 pub fn init(arena: Allocator) @This() {
99 return .{100 return .{
100 .arena = arena,101 .arena = arena,
101 .compile_errors = .empty,102 .list = .empty,
102 };103 };
103 }104 }
104105
105 pub fn format(self: *const @This(), w: *std.Io.Writer) std.Io.Writer.Error!void {106 pub fn format(self: *const @This(), w: *std.Io.Writer) std.Io.Writer.Error!void {
106 for (self.compile_errors.items) |e| {107 for (self.list.items) |e| {
107 try w.print("{d}:{d}: error: {s}\n", .{108 try w.print("{d}:{d}: error: {s}\n", .{
108 e.loc.line + 1,109 e.loc.line + 1,
109 e.loc.column + 1,110 e.loc.column + 1,
...@@ -121,17 +122,17 @@ pub const Diagnostics = struct {...@@ -121,17 +122,17 @@ pub const Diagnostics = struct {
121 }122 }
122123
123 pub fn clear(self: *@This()) void {124 pub fn clear(self: *@This()) void {
124 self.compile_errors.clearRetainingCapacity();125 self.errors.clearRetainingCapacity();
125 }126 }
126};127};
127128
128pub const FromSliceOptions = struct {129pub const FromSliceOptions = struct {
129 /// Used for scratch allocations.130 /// Used for scratch allocations.
130 gpa: Allocator,131 gpa: Allocator,
131 /// The ZON source.132 /// The ZON source to parse.
132 source: [:0]const u8,133 source: [:0]const u8,
133 /// Write human readable error messages here.134 /// If non-null, any errors encountered are appended here.
134 diag: ?*Diagnostics,135 errors: ?*Errors,
135 /// If true, unknown fields do not error.136 /// If true, unknown fields do not error.
136 ignore_unknown_fields: bool = false,137 ignore_unknown_fields: bool = false,
137};138};
...@@ -142,7 +143,7 @@ pub const FromSliceOptions = struct {...@@ -142,7 +143,7 @@ pub const FromSliceOptions = struct {
142/// invalid or can not be deserialized into type `T`.143/// invalid or can not be deserialized into type `T`.
143///144///
144/// When the parser returns `error.ParseZon`, it will also store a human readable explanation in145/// When the parser returns `error.ParseZon`, it will also store a human readable explanation in
145/// `diag` if non null.146/// `errors` if non null.
146///147///
147/// Asserts at compile time that the result type doesn't contain pointers. As such, the result148/// Asserts at compile time that the result type doesn't contain pointers. As such, the result
148/// doesn't need to be freed.149/// doesn't need to be freed.
...@@ -154,7 +155,7 @@ pub fn fromSlice(T: type, options: FromSliceOptions) error{ OutOfMemory, ParseZo...@@ -154,7 +155,7 @@ pub fn fromSlice(T: type, options: FromSliceOptions) error{ OutOfMemory, ParseZo
154 .gpa = options.gpa,155 .gpa = options.gpa,
155 .arena = .failing,156 .arena = .failing,
156 .source = options.source,157 .source = options.source,
157 .diag = options.diag,158 .errors = options.errors,
158 .ignore_unknown_fields = options.ignore_unknown_fields,159 .ignore_unknown_fields = options.ignore_unknown_fields,
159 });160 });
160}161}
...@@ -172,7 +173,7 @@ pub fn updateFromSlice(...@@ -172,7 +173,7 @@ pub fn updateFromSlice(
172 .gpa = options.gpa,173 .gpa = options.gpa,
173 .arena = .failing,174 .arena = .failing,
174 .source = options.source,175 .source = options.source,
175 .diag = options.diag,176 .errors = options.errors,
176 .ignore_unknown_fields = options.ignore_unknown_fields,177 .ignore_unknown_fields = options.ignore_unknown_fields,
177 });178 });
178}179}
...@@ -182,10 +183,10 @@ pub const FromSliceAllocOptions = struct {...@@ -182,10 +183,10 @@ pub const FromSliceAllocOptions = struct {
182 gpa: Allocator,183 gpa: Allocator,
183 /// Owns the result.184 /// Owns the result.
184 arena: Allocator,185 arena: Allocator,
185 /// The ZON source.186 /// The ZON source to parse.
186 source: [:0]const u8,187 source: [:0]const u8,
187 /// Write human readable error messages here.188 /// If non-null, any errors encountered are appended here.
188 diag: ?*Diagnostics,189 errors: ?*Errors,
189 /// If true, unknown fields do not error.190 /// If true, unknown fields do not error.
190 ignore_unknown_fields: bool = false,191 ignore_unknown_fields: bool = false,
191};192};
...@@ -198,7 +199,7 @@ pub fn fromSliceAlloc(T: type, options: FromSliceAllocOptions) error{ OutOfMemor...@@ -198,7 +199,7 @@ pub fn fromSliceAlloc(T: type, options: FromSliceAllocOptions) error{ OutOfMemor
198 .gpa = options.gpa,199 .gpa = options.gpa,
199 .arena = options.arena,200 .arena = options.arena,
200 .source = options.source,201 .source = options.source,
201 .diag = options.diag,202 .errors = options.errors,
202 .ignore_unknown_fields = options.ignore_unknown_fields,203 .ignore_unknown_fields = options.ignore_unknown_fields,
203 .initialized = false,204 .initialized = false,
204 });205 });
...@@ -215,7 +216,7 @@ pub fn updateFromSliceAlloc(...@@ -215,7 +216,7 @@ pub fn updateFromSliceAlloc(
215 .gpa = options.gpa,216 .gpa = options.gpa,
216 .arena = options.arena,217 .arena = options.arena,
217 .source = options.source,218 .source = options.source,
218 .diag = options.diag,219 .errors = options.errors,
219 .ignore_unknown_fields = options.ignore_unknown_fields,220 .ignore_unknown_fields = options.ignore_unknown_fields,
220 .initialized = true,221 .initialized = true,
221 });222 });
...@@ -225,7 +226,7 @@ const ParseSliceAllocOptions = struct {...@@ -225,7 +226,7 @@ const ParseSliceAllocOptions = struct {
225 gpa: Allocator,226 gpa: Allocator,
226 arena: Allocator,227 arena: Allocator,
227 source: [:0]const u8,228 source: [:0]const u8,
228 diag: ?*Diagnostics,229 errors: ?*Errors,
229 ignore_unknown_fields: bool,230 ignore_unknown_fields: bool,
230 initialized: bool,231 initialized: bool,
231};232};
...@@ -246,7 +247,7 @@ fn parseSliceAlloc(...@@ -246,7 +247,7 @@ fn parseSliceAlloc(
246 .ast = &ast,247 .ast = &ast,
247 .zoir = &zoir,248 .zoir = &zoir,
248 .node = .root,249 .node = .root,
249 .diag = options.diag,250 .errors = options.errors,
250 .ignore_unknown_fields = options.ignore_unknown_fields,251 .ignore_unknown_fields = options.ignore_unknown_fields,
251 .initialized = options.initialized,252 .initialized = options.initialized,
252 });253 });
...@@ -259,8 +260,8 @@ pub const FromZoirOptions = struct {...@@ -259,8 +260,8 @@ pub const FromZoirOptions = struct {
259 zoir: *const Zoir,260 zoir: *const Zoir,
260 /// The node to start parsing at.261 /// The node to start parsing at.
261 node: Zoir.Node.Index = .root,262 node: Zoir.Node.Index = .root,
262 /// Write human readable error messages here.263 /// If non-null, any errors encountered are appended here.
263 diag: ?*Diagnostics,264 errors: ?*Errors,
264 /// If true, unknown fields do not error.265 /// If true, unknown fields do not error.
265 ignore_unknown_fields: bool = false,266 ignore_unknown_fields: bool = false,
266};267};
...@@ -273,7 +274,7 @@ pub fn fromZoir(T: type, options: FromZoirOptions) error{ParseZon}!T {...@@ -273,7 +274,7 @@ pub fn fromZoir(T: type, options: FromZoirOptions) error{ParseZon}!T {
273 .ast = options.ast,274 .ast = options.ast,
274 .zoir = options.zoir,275 .zoir = options.zoir,
275 .node = options.node,276 .node = options.node,
276 .diag = options.diag,277 .errors = options.errors,
277 .ignore_unknown_fields = options.ignore_unknown_fields,278 .ignore_unknown_fields = options.ignore_unknown_fields,
278 }) catch |err| switch (err) {279 }) catch |err| switch (err) {
279 error.OutOfMemory => unreachable, // Checked by comptime assertion above280 error.OutOfMemory => unreachable, // Checked by comptime assertion above
...@@ -293,7 +294,7 @@ pub fn updateFromZoir(...@@ -293,7 +294,7 @@ pub fn updateFromZoir(
293 .ast = options.ast,294 .ast = options.ast,
294 .zoir = options.zoir,295 .zoir = options.zoir,
295 .node = options.node,296 .node = options.node,
296 .diag = options.diag,297 .errors = options.errors,
297 .ignore_unknown_fields = options.ignore_unknown_fields,298 .ignore_unknown_fields = options.ignore_unknown_fields,
298 }) catch |err| switch (err) {299 }) catch |err| switch (err) {
299 error.OutOfMemory => unreachable, // Checked by comptime assertion above300 error.OutOfMemory => unreachable, // Checked by comptime assertion above
...@@ -310,8 +311,8 @@ pub const FromZoirAllocOptions = struct {...@@ -310,8 +311,8 @@ pub const FromZoirAllocOptions = struct {
310 zoir: *const Zoir,311 zoir: *const Zoir,
311 /// The node to start parsing at.312 /// The node to start parsing at.
312 node: Zoir.Node.Index = .root,313 node: Zoir.Node.Index = .root,
313 /// Write human readable error messages here.314 /// If non-null, any errors encountered are appended here.
314 diag: ?*Diagnostics,315 errors: ?*Errors,
315 /// If true, unknown fields do not error.316 /// If true, unknown fields do not error.
316 ignore_unknown_fields: bool = false,317 ignore_unknown_fields: bool = false,
317};318};
...@@ -324,7 +325,7 @@ pub fn fromZoirAlloc(T: type, options: FromZoirAllocOptions) error{ OutOfMemory,...@@ -324,7 +325,7 @@ pub fn fromZoirAlloc(T: type, options: FromZoirAllocOptions) error{ OutOfMemory,
324 .ast = options.ast,325 .ast = options.ast,
325 .zoir = options.zoir,326 .zoir = options.zoir,
326 .node = options.node,327 .node = options.node,
327 .diag = options.diag,328 .errors = options.errors,
328 .ignore_unknown_fields = options.ignore_unknown_fields,329 .ignore_unknown_fields = options.ignore_unknown_fields,
329 .initialized = false,330 .initialized = false,
330 });331 });
...@@ -342,7 +343,7 @@ pub fn updateFromZoirAlloc(...@@ -342,7 +343,7 @@ pub fn updateFromZoirAlloc(
342 .ast = options.ast,343 .ast = options.ast,
343 .zoir = options.zoir,344 .zoir = options.zoir,
344 .node = options.node,345 .node = options.node,
345 .diag = options.diag,346 .errors = options.errors,
346 .ignore_unknown_fields = options.ignore_unknown_fields,347 .ignore_unknown_fields = options.ignore_unknown_fields,
347 .initialized = true,348 .initialized = true,
348 });349 });
...@@ -353,7 +354,7 @@ const ParseZoirAllocOptions = struct {...@@ -353,7 +354,7 @@ const ParseZoirAllocOptions = struct {
353 ast: *const Ast,354 ast: *const Ast,
354 zoir: *const Zoir,355 zoir: *const Zoir,
355 node: Zoir.Node.Index,356 node: Zoir.Node.Index,
356 diag: ?*Diagnostics,357 errors: ?*Errors,
357 ignore_unknown_fields: bool,358 ignore_unknown_fields: bool,
358 initialized: bool,359 initialized: bool,
359};360};
...@@ -366,21 +367,21 @@ fn parseZoirAlloc(...@@ -366,21 +367,21 @@ fn parseZoirAlloc(
366 comptime assert(canParseType(T));367 comptime assert(canParseType(T));
367368
368 if (options.zoir.hasCompileErrors()) {369 if (options.zoir.hasCompileErrors()) {
369 if (options.diag) |s| {370 if (options.errors) |errors| {
370 for (options.zoir.compile_errors) |e| {371 for (options.zoir.compile_errors) |e| {
371 var notes: std.ArrayList(Error.Note) = .empty;372 var notes: std.ArrayList(Error.Note) = .empty;
372 for (e.getNotes(options.zoir)) |note| {373 for (e.getNotes(options.zoir)) |note| {
373 try notes.append(s.arena, .init(options.ast, .{374 try notes.append(errors.arena, .init(options.ast, .{
374 .msg = try s.arena.dupe(u8, note.msg.get(options.zoir)),375 .msg = try errors.arena.dupe(u8, note.msg.get(options.zoir)),
375 .token = note.token,376 .token = note.token,
376 .node_or_offset = note.node_or_offset,377 .node_or_offset = note.node_or_offset,
377 }));378 }));
378 }379 }
379 try s.compile_errors.append(s.arena, .init(options.ast, .{380 try errors.list.append(errors.arena, .init(options.ast, .{
380 .msg = try s.arena.dupe(u8, e.msg.get(options.zoir)),381 .msg = try errors.arena.dupe(u8, e.msg.get(options.zoir)),
381 .token = e.token,382 .token = e.token,
382 .node_or_offset = e.node_or_offset,383 .node_or_offset = e.node_or_offset,
383 .notes = try notes.toOwnedSlice(s.arena),384 .notes = try notes.toOwnedSlice(errors.arena),
384 }));385 }));
385 }386 }
386 }387 }
...@@ -392,7 +393,7 @@ fn parseZoirAlloc(...@@ -392,7 +393,7 @@ fn parseZoirAlloc(
392 .ast = options.ast,393 .ast = options.ast,
393 .zoir = options.zoir,394 .zoir = options.zoir,
394 .ignore_unknown_fields = options.ignore_unknown_fields,395 .ignore_unknown_fields = options.ignore_unknown_fields,
395 .diag = options.diag,396 .errors = options.errors,
396 };397 };
397398
398 try parser.parseExprInto(options.node, value, options.initialized);399 try parser.parseExprInto(options.node, value, options.initialized);
...@@ -423,7 +424,7 @@ const Parser = struct {...@@ -423,7 +424,7 @@ const Parser = struct {
423 arena: Allocator,424 arena: Allocator,
424 ast: *const Ast,425 ast: *const Ast,
425 zoir: *const Zoir,426 zoir: *const Zoir,
426 diag: ?*Diagnostics,427 errors: ?*Errors,
427 ignore_unknown_fields: bool,428 ignore_unknown_fields: bool,
428429
429 const ParseExprError = error{ ParseZon, OutOfMemory };430 const ParseExprError = error{ ParseZon, OutOfMemory };
...@@ -997,10 +998,10 @@ const Parser = struct {...@@ -997,10 +998,10 @@ const Parser = struct {
997 ) error{ OutOfMemory, ParseZon } {998 ) error{ OutOfMemory, ParseZon } {
998 @branchHint(.cold);999 @branchHint(.cold);
999 comptime assert(args.len > 0);1000 comptime assert(args.len > 0);
1000 if (self.diag) |s| try s.compile_errors.append(s.arena, .init(self.ast, .{1001 if (self.errors) |errors| try errors.list.append(errors.arena, .init(self.ast, .{
1001 .token = .fromToken(token),1002 .token = .fromToken(token),
1002 .node_or_offset = offset,1003 .node_or_offset = offset,
1003 .msg = try std.fmt.allocPrint(s.arena, fmt, args),1004 .msg = try std.fmt.allocPrint(errors.arena, fmt, args),
1004 .notes = notes,1005 .notes = notes,
1005 }));1006 }));
1006 return error.ParseZon;1007 return error.ParseZon;
...@@ -1022,7 +1023,7 @@ const Parser = struct {...@@ -1022,7 +1023,7 @@ const Parser = struct {
1022 failure: Error,1023 failure: Error,
1023 ) error{ OutOfMemory, ParseZon } {1024 ) error{ OutOfMemory, ParseZon } {
1024 @branchHint(.cold);1025 @branchHint(.cold);
1025 if (self.diag) |s| try s.compile_errors.append(s.arena, failure);1026 if (self.errors) |errors| try errors.list.append(errors.arena, failure);
1026 return error.ParseZon;1027 return error.ParseZon;
1027 }1028 }
10281029
...@@ -1059,7 +1060,7 @@ const Parser = struct {...@@ -1059,7 +1060,7 @@ const Parser = struct {
1059 name: []const u8,1060 name: []const u8,
1060 ) error{ OutOfMemory, ParseZon } {1061 ) error{ OutOfMemory, ParseZon } {
1061 @branchHint(.cold);1062 @branchHint(.cold);
1062 const diag = self.diag orelse return error.ParseZon;1063 const errors = self.errors orelse return error.ParseZon;
1063 const token = if (field) |f| b: {1064 const token = if (field) |f| b: {
1064 var buf: [2]Ast.Node.Index = undefined;1065 var buf: [2]Ast.Node.Index = undefined;
1065 const struct_init = self.ast.fullStructInit(&buf, node.getAstNode(self.zoir)).?;1066 const struct_init = self.ast.fullStructInit(&buf, node.getAstNode(self.zoir)).?;
...@@ -1070,13 +1071,13 @@ const Parser = struct {...@@ -1070,13 +1071,13 @@ const Parser = struct {
1070 inline .@"struct", .@"union", .@"enum" => |info| {1071 inline .@"struct", .@"union", .@"enum" => |info| {
1071 var notes: std.ArrayList(Error.Note) = .empty;1072 var notes: std.ArrayList(Error.Note) = .empty;
1072 if (info.field_names.len == 0) {1073 if (info.field_names.len == 0) {
1073 try notes.append(diag.arena, .init(self.ast, .{1074 try notes.append(errors.arena, .init(self.ast, .{
1074 .token = .fromToken(token),1075 .token = .fromToken(token),
1075 .node_or_offset = 0,1076 .node_or_offset = 0,
1076 .msg = "none expected",1077 .msg = "none expected",
1077 }));1078 }));
1078 } else {1079 } else {
1079 var aw: std.Io.Writer.Allocating = .init(diag.arena);1080 var aw: std.Io.Writer.Allocating = .init(errors.arena);
1080 aw.writer.writeAll("supported: ") catch return error.OutOfMemory;1081 aw.writer.writeAll("supported: ") catch return error.OutOfMemory;
1081 inline for (info.field_names, 0..) |field_name, i| {1082 inline for (info.field_names, 0..) |field_name, i| {
1082 if (i != 0) aw.writer.writeAll(", ") catch return error.OutOfMemory;1083 if (i != 0) aw.writer.writeAll(", ") catch return error.OutOfMemory;
...@@ -1085,7 +1086,7 @@ const Parser = struct {...@@ -1085,7 +1086,7 @@ const Parser = struct {
1085 .allow_underscore = true,1086 .allow_underscore = true,
1086 })}) catch return error.OutOfMemory;1087 })}) catch return error.OutOfMemory;
1087 }1088 }
1088 try notes.append(diag.arena, .init(self.ast, .{1089 try notes.append(errors.arena, .init(self.ast, .{
1089 .token = .fromToken(token),1090 .token = .fromToken(token),
1090 .node_or_offset = 0,1091 .node_or_offset = 0,
1091 .msg = try aw.toOwnedSlice(),1092 .msg = try aw.toOwnedSlice(),
...@@ -1096,7 +1097,7 @@ const Parser = struct {...@@ -1096,7 +1097,7 @@ const Parser = struct {
1096 0,1097 0,
1097 "unexpected {s} '{s}'",1098 "unexpected {s} '{s}'",
1098 .{ item_kind, name },1099 .{ item_kind, name },
1099 try notes.toOwnedSlice(diag.arena),1100 try notes.toOwnedSlice(errors.arena),
1100 );1101 );
1101 },1102 },
1102 else => comptime unreachable,1103 else => comptime unreachable,
...@@ -1112,7 +1113,7 @@ const Parser = struct {...@@ -1112,7 +1113,7 @@ const Parser = struct {
1112 field: usize,1113 field: usize,
1113 ) error{ OutOfMemory, ParseZon } {1114 ) error{ OutOfMemory, ParseZon } {
1114 @branchHint(.cold);1115 @branchHint(.cold);
1115 if (self.diag == null) return error.ParseZon;1116 if (self.errors == null) return error.ParseZon;
1116 const ast_node = node.getAstNode(self.zoir);1117 const ast_node = node.getAstNode(self.zoir);
1117 var buf: [2]Ast.Node.Index = undefined;1118 var buf: [2]Ast.Node.Index = undefined;
1118 const token = if (self.ast.fullStructInit(&buf, ast_node)) |struct_init| b: {1119 const token = if (self.ast.fullStructInit(&buf, ast_node)) |struct_init| b: {
...@@ -1293,16 +1294,16 @@ test "std.zon ast errors" {...@@ -1293,16 +1294,16 @@ test "std.zon ast errors" {
1293 var arena_allocator: ArenaAllocator = .init(gpa);1294 var arena_allocator: ArenaAllocator = .init(gpa);
1294 defer arena_allocator.deinit();1295 defer arena_allocator.deinit();
1295 const arena = arena_allocator.allocator();1296 const arena = arena_allocator.allocator();
1296 var diag: Diagnostics = .init(arena);1297 var errors: Errors = .init(arena);
1297 try std.testing.expectError(1298 try std.testing.expectError(
1298 error.ParseZon,1299 error.ParseZon,
1299 fromSlice(struct {}, .{1300 fromSlice(struct {}, .{
1300 .gpa = gpa,1301 .gpa = gpa,
1301 .source = ".{.x = 1 .y = 2}",1302 .source = ".{.x = 1 .y = 2}",
1302 .diag = &diag,1303 .errors = &errors,
1303 }),1304 }),
1304 );1305 );
1305 try std.testing.expectFmt("1:13: error: expected ',' after initializer\n", "{f}", .{diag});1306 try std.testing.expectFmt("1:13: error: expected ',' after initializer\n", "{f}", .{errors});
1306}1307}
13071308
1308test "std.zon comments" {1309test "std.zon comments" {
...@@ -1318,11 +1319,11 @@ test "std.zon comments" {...@@ -1318,11 +1319,11 @@ test "std.zon comments" {
1318 \\10 // comment1319 \\10 // comment
1319 \\// comment1320 \\// comment
1320 ,1321 ,
1321 .diag = null,1322 .errors = null,
1322 }));1323 }));
13231324
1324 {1325 {
1325 var diag: Diagnostics = .init(arena);1326 var errors: Errors = .init(arena);
1326 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{1327 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
1327 .gpa = gpa,1328 .gpa = gpa,
1328 .source =1329 .source =
...@@ -1330,12 +1331,12 @@ test "std.zon comments" {...@@ -1330,12 +1331,12 @@ test "std.zon comments" {
1330 \\10 // comment1331 \\10 // comment
1331 \\// comment1332 \\// comment
1332 ,1333 ,
1333 .diag = &diag,1334 .errors = &errors,
1334 }));1335 }));
1335 try std.testing.expectFmt(1336 try std.testing.expectFmt(
1336 "1:1: error: expected expression, found 'a document comment'\n",1337 "1:1: error: expected expression, found 'a document comment'\n",
1337 "{f}",1338 "{f}",
1338 .{diag},1339 .{errors},
1339 );1340 );
1340 }1341 }
1341}1342}
...@@ -1345,14 +1346,14 @@ test "std.zon failure/oom formatting" {...@@ -1345,14 +1346,14 @@ test "std.zon failure/oom formatting" {
1345 var arena_allocator: ArenaAllocator = .init(gpa);1346 var arena_allocator: ArenaAllocator = .init(gpa);
1346 defer arena_allocator.deinit();1347 defer arena_allocator.deinit();
1347 const arena = arena_allocator.allocator();1348 const arena = arena_allocator.allocator();
1348 var diag: Diagnostics = .init(arena);1349 var errors: Errors = .init(arena);
1349 try std.testing.expectError(error.OutOfMemory, fromSliceAlloc([]const u8, .{1350 try std.testing.expectError(error.OutOfMemory, fromSliceAlloc([]const u8, .{
1350 .gpa = .failing,1351 .gpa = .failing,
1351 .arena = arena,1352 .arena = arena,
1352 .source = "\"foo\"",1353 .source = "\"foo\"",
1353 .diag = &diag,1354 .errors = &errors,
1354 }));1355 }));
1355 try std.testing.expectFmt("", "{f}", .{diag});1356 try std.testing.expectFmt("", "{f}", .{errors});
1356}1357}
13571358
1358test "std.zon fromSliceAlloc syntax error" {1359test "std.zon fromSliceAlloc syntax error" {
...@@ -1362,7 +1363,7 @@ test "std.zon fromSliceAlloc syntax error" {...@@ -1362,7 +1363,7 @@ test "std.zon fromSliceAlloc syntax error" {
1362 fromSlice(u8, .{1363 fromSlice(u8, .{
1363 .gpa = gpa,1364 .gpa = gpa,
1364 .source = ".{",1365 .source = ".{",
1365 .diag = null,1366 .errors = null,
1366 }),1367 }),
1367 );1368 );
1368}1369}
...@@ -1378,13 +1379,13 @@ test "std.zon optional" {...@@ -1378,13 +1379,13 @@ test "std.zon optional" {
1378 const none = try fromSlice(?u32, .{1379 const none = try fromSlice(?u32, .{
1379 .gpa = gpa,1380 .gpa = gpa,
1380 .source = "null",1381 .source = "null",
1381 .diag = null,1382 .errors = null,
1382 });1383 });
1383 try std.testing.expect(none == null);1384 try std.testing.expect(none == null);
1384 const some = try fromSlice(?u32, .{1385 const some = try fromSlice(?u32, .{
1385 .gpa = gpa,1386 .gpa = gpa,
1386 .source = "1",1387 .source = "1",
1387 .diag = null,1388 .errors = null,
1388 });1389 });
1389 try std.testing.expect(some.? == 1);1390 try std.testing.expect(some.? == 1);
1390 }1391 }
...@@ -1395,14 +1396,14 @@ test "std.zon optional" {...@@ -1395,14 +1396,14 @@ test "std.zon optional" {
1395 .gpa = gpa,1396 .gpa = gpa,
1396 .arena = arena,1397 .arena = arena,
1397 .source = "null",1398 .source = "null",
1398 .diag = null,1399 .errors = null,
1399 });1400 });
1400 try std.testing.expect(none == null);1401 try std.testing.expect(none == null);
1401 const some = try fromSliceAlloc(?[]const u8, .{1402 const some = try fromSliceAlloc(?[]const u8, .{
1402 .gpa = gpa,1403 .gpa = gpa,
1403 .arena = arena,1404 .arena = arena,
1404 .source = "\"foo\"",1405 .source = "\"foo\"",
1405 .diag = null,1406 .errors = null,
1406 });1407 });
1407 try std.testing.expectEqualStrings("foo", some.?);1408 try std.testing.expectEqualStrings("foo", some.?);
1408 }1409 }
...@@ -1422,38 +1423,38 @@ test "std.zon unions" {...@@ -1422,38 +1423,38 @@ test "std.zon unions" {
1422 const tagged_x = try fromSlice(Tagged, .{1423 const tagged_x = try fromSlice(Tagged, .{
1423 .gpa = gpa,1424 .gpa = gpa,
1424 .source = ".{.x = 1.5}",1425 .source = ".{.x = 1.5}",
1425 .diag = null,1426 .errors = null,
1426 });1427 });
1427 try std.testing.expectEqual(Tagged{ .x = 1.5 }, tagged_x);1428 try std.testing.expectEqual(Tagged{ .x = 1.5 }, tagged_x);
1428 const tagged_y = try fromSlice(Tagged, .{1429 const tagged_y = try fromSlice(Tagged, .{
1429 .gpa = gpa,1430 .gpa = gpa,
1430 .source = ".{.@\"y y\" = true}",1431 .source = ".{.@\"y y\" = true}",
1431 .diag = null,1432 .errors = null,
1432 });1433 });
1433 try std.testing.expectEqual(Tagged{ .@"y y" = true }, tagged_y);1434 try std.testing.expectEqual(Tagged{ .@"y y" = true }, tagged_y);
1434 const tagged_z_shorthand = try fromSlice(Tagged, .{1435 const tagged_z_shorthand = try fromSlice(Tagged, .{
1435 .gpa = gpa,1436 .gpa = gpa,
1436 .source = ".z",1437 .source = ".z",
1437 .diag = null,1438 .errors = null,
1438 });1439 });
1439 try std.testing.expectEqual(@as(Tagged, .z), tagged_z_shorthand);1440 try std.testing.expectEqual(@as(Tagged, .z), tagged_z_shorthand);
1440 const tagged_zz_shorthand = try fromSlice(Tagged, .{1441 const tagged_zz_shorthand = try fromSlice(Tagged, .{
1441 .gpa = gpa,1442 .gpa = gpa,
1442 .source = ".@\"z z\"",1443 .source = ".@\"z z\"",
1443 .diag = null,1444 .errors = null,
1444 });1445 });
1445 try std.testing.expectEqual(@as(Tagged, .@"z z"), tagged_zz_shorthand);1446 try std.testing.expectEqual(@as(Tagged, .@"z z"), tagged_zz_shorthand);
14461447
1447 const untagged_x = try fromSlice(Untagged, .{1448 const untagged_x = try fromSlice(Untagged, .{
1448 .gpa = gpa,1449 .gpa = gpa,
1449 .source = ".{.x = 1.5}",1450 .source = ".{.x = 1.5}",
1450 .diag = null,1451 .errors = null,
1451 });1452 });
1452 try std.testing.expect(untagged_x.x == 1.5);1453 try std.testing.expect(untagged_x.x == 1.5);
1453 const untagged_y = try fromSlice(Untagged, .{1454 const untagged_y = try fromSlice(Untagged, .{
1454 .gpa = gpa,1455 .gpa = gpa,
1455 .source = ".{.@\"y y\" = true}",1456 .source = ".{.@\"y y\" = true}",
1456 .diag = null,1457 .errors = null,
1457 });1458 });
1458 try std.testing.expect(untagged_y.@"y y");1459 try std.testing.expect(untagged_y.@"y y");
1459 }1460 }
...@@ -1466,7 +1467,7 @@ test "std.zon unions" {...@@ -1466,7 +1467,7 @@ test "std.zon unions" {
1466 .gpa = gpa,1467 .gpa = gpa,
1467 .arena = arena,1468 .arena = arena,
1468 .source = ".{.baz = false}",1469 .source = ".{.baz = false}",
1469 .diag = null,1470 .errors = null,
1470 });1471 });
1471 try std.testing.expectEqual(Union{ .baz = false }, noalloc);1472 try std.testing.expectEqual(Union{ .baz = false }, noalloc);
14721473
...@@ -1474,7 +1475,7 @@ test "std.zon unions" {...@@ -1474,7 +1475,7 @@ test "std.zon unions" {
1474 .gpa = gpa,1475 .gpa = gpa,
1475 .arena = arena,1476 .arena = arena,
1476 .source = ".{.bar = \"qux\"}",1477 .source = ".{.bar = \"qux\"}",
1477 .diag = null,1478 .errors = null,
1478 });1479 });
1479 try std.testing.expectEqualDeep(Union{ .bar = "qux" }, alloc);1480 try std.testing.expectEqualDeep(Union{ .bar = "qux" }, alloc);
1480 }1481 }
...@@ -1482,14 +1483,14 @@ test "std.zon unions" {...@@ -1482,14 +1483,14 @@ test "std.zon unions" {
1482 // Unknown field1483 // Unknown field
1483 {1484 {
1484 const Union = union { x: f32, y: f32 };1485 const Union = union { x: f32, y: f32 };
1485 var diag: Diagnostics = .init(arena);1486 var errors: Errors = .init(arena);
1486 try std.testing.expectError(1487 try std.testing.expectError(
1487 error.ParseZon,1488 error.ParseZon,
1488 fromSliceAlloc(Union, .{1489 fromSliceAlloc(Union, .{
1489 .gpa = gpa,1490 .gpa = gpa,
1490 .arena = arena,1491 .arena = arena,
1491 .source = ".{.z=2.5}",1492 .source = ".{.z=2.5}",
1492 .diag = &diag,1493 .errors = &errors,
1493 }),1494 }),
1494 );1495 );
1495 try std.testing.expectFmt(1496 try std.testing.expectFmt(
...@@ -1498,80 +1499,80 @@ test "std.zon unions" {...@@ -1498,80 +1499,80 @@ test "std.zon unions" {
1498 \\1499 \\
1499 ,1500 ,
1500 "{f}",1501 "{f}",
1501 .{diag},1502 .{errors},
1502 );1503 );
1503 }1504 }
15041505
1505 // Explicit void field1506 // Explicit void field
1506 {1507 {
1507 const Union = union(enum) { x: void };1508 const Union = union(enum) { x: void };
1508 var diag: Diagnostics = .init(arena);1509 var errors: Errors = .init(arena);
1509 try std.testing.expectError(1510 try std.testing.expectError(
1510 error.ParseZon,1511 error.ParseZon,
1511 fromSliceAlloc(Union, .{1512 fromSliceAlloc(Union, .{
1512 .gpa = gpa,1513 .gpa = gpa,
1513 .arena = arena,1514 .arena = arena,
1514 .source = ".{.x=1}",1515 .source = ".{.x=1}",
1515 .diag = &diag,1516 .errors = &errors,
1516 }),1517 }),
1517 );1518 );
1518 try std.testing.expectFmt("1:6: error: expected type 'void'\n", "{f}", .{diag});1519 try std.testing.expectFmt("1:6: error: expected type 'void'\n", "{f}", .{errors});
1519 }1520 }
15201521
1521 // Extra field1522 // Extra field
1522 {1523 {
1523 const Union = union { x: f32, y: bool };1524 const Union = union { x: f32, y: bool };
1524 var diag: Diagnostics = .init(arena);1525 var errors: Errors = .init(arena);
1525 try std.testing.expectError(1526 try std.testing.expectError(
1526 error.ParseZon,1527 error.ParseZon,
1527 fromSliceAlloc(Union, .{1528 fromSliceAlloc(Union, .{
1528 .gpa = gpa,1529 .gpa = gpa,
1529 .arena = arena,1530 .arena = arena,
1530 .source = ".{.x = 1.5, .y = true}",1531 .source = ".{.x = 1.5, .y = true}",
1531 .diag = &diag,1532 .errors = &errors,
1532 }),1533 }),
1533 );1534 );
1534 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{diag});1535 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{errors});
1535 }1536 }
15361537
1537 // No fields1538 // No fields
1538 {1539 {
1539 const Union = union { x: f32, y: bool };1540 const Union = union { x: f32, y: bool };
1540 var diag: Diagnostics = .init(arena);1541 var errors: Errors = .init(arena);
1541 try std.testing.expectError(1542 try std.testing.expectError(
1542 error.ParseZon,1543 error.ParseZon,
1543 fromSliceAlloc(Union, .{1544 fromSliceAlloc(Union, .{
1544 .gpa = gpa,1545 .gpa = gpa,
1545 .arena = arena,1546 .arena = arena,
1546 .source = ".{}",1547 .source = ".{}",
1547 .diag = &diag,1548 .errors = &errors,
1548 }),1549 }),
1549 );1550 );
1550 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{diag});1551 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{errors});
1551 }1552 }
15521553
1553 // Enum literals cannot coerce into untagged unions1554 // Enum literals cannot coerce into untagged unions
1554 {1555 {
1555 const Union = union { x: void };1556 const Union = union { x: void };
1556 var diag: Diagnostics = .init(arena);1557 var errors: Errors = .init(arena);
1557 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, .{1558 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, .{
1558 .gpa = gpa,1559 .gpa = gpa,
1559 .arena = arena,1560 .arena = arena,
1560 .source = ".x",1561 .source = ".x",
1561 .diag = &diag,1562 .errors = &errors,
1562 }));1563 }));
1563 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{diag});1564 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{errors});
1564 }1565 }
15651566
1566 // Unknown field for enum literal coercion1567 // Unknown field for enum literal coercion
1567 {1568 {
1568 const Union = union(enum) { x: void };1569 const Union = union(enum) { x: void };
1569 var diag: Diagnostics = .init(arena);1570 var errors: Errors = .init(arena);
1570 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, .{1571 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, .{
1571 .gpa = gpa,1572 .gpa = gpa,
1572 .arena = arena,1573 .arena = arena,
1573 .source = ".y",1574 .source = ".y",
1574 .diag = &diag,1575 .errors = &errors,
1575 }));1576 }));
1576 try std.testing.expectFmt(1577 try std.testing.expectFmt(
1577 \\1:2: error: unexpected field 'y'1578 \\1:2: error: unexpected field 'y'
...@@ -1579,21 +1580,21 @@ test "std.zon unions" {...@@ -1579,21 +1580,21 @@ test "std.zon unions" {
1579 \\1580 \\
1580 ,1581 ,
1581 "{f}",1582 "{f}",
1582 .{diag},1583 .{errors},
1583 );1584 );
1584 }1585 }
15851586
1586 // Non void field for enum literal coercion1587 // Non void field for enum literal coercion
1587 {1588 {
1588 const Union = union(enum) { x: f32 };1589 const Union = union(enum) { x: f32 };
1589 var diag: Diagnostics = .init(arena);1590 var errors: Errors = .init(arena);
1590 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, .{1591 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, .{
1591 .gpa = gpa,1592 .gpa = gpa,
1592 .arena = arena,1593 .arena = arena,
1593 .source = ".x",1594 .source = ".x",
1594 .diag = &diag,1595 .errors = &errors,
1595 }));1596 }));
1596 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{diag});1597 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{errors});
1597 }1598 }
1598}1599}
15991600
...@@ -1613,28 +1614,28 @@ test "std.zon structs" {...@@ -1613,28 +1614,28 @@ test "std.zon structs" {
1613 const zero = try fromSlice(Vec0, .{1614 const zero = try fromSlice(Vec0, .{
1614 .gpa = gpa,1615 .gpa = gpa,
1615 .source = ".{}",1616 .source = ".{}",
1616 .diag = null,1617 .errors = null,
1617 });1618 });
1618 try std.testing.expectEqual(Vec0{}, zero);1619 try std.testing.expectEqual(Vec0{}, zero);
16191620
1620 const one = try fromSlice(Vec1, .{1621 const one = try fromSlice(Vec1, .{
1621 .gpa = gpa,1622 .gpa = gpa,
1622 .source = ".{.x = 1.2}",1623 .source = ".{.x = 1.2}",
1623 .diag = null,1624 .errors = null,
1624 });1625 });
1625 try std.testing.expectEqual(Vec1{ .x = 1.2 }, one);1626 try std.testing.expectEqual(Vec1{ .x = 1.2 }, one);
16261627
1627 const two = try fromSlice(Vec2, .{1628 const two = try fromSlice(Vec2, .{
1628 .gpa = gpa,1629 .gpa = gpa,
1629 .source = ".{.x = 1.2, .y = 3.4}",1630 .source = ".{.x = 1.2, .y = 3.4}",
1630 .diag = null,1631 .errors = null,
1631 });1632 });
1632 try std.testing.expectEqual(Vec2{ .x = 1.2, .y = 3.4 }, two);1633 try std.testing.expectEqual(Vec2{ .x = 1.2, .y = 3.4 }, two);
16331634
1634 const three = try fromSlice(Vec3, .{1635 const three = try fromSlice(Vec3, .{
1635 .gpa = gpa,1636 .gpa = gpa,
1636 .source = ".{.x = 1.2, .y = 3.4, .z = 5.6}",1637 .source = ".{.x = 1.2, .y = 3.4, .z = 5.6}",
1637 .diag = null,1638 .errors = null,
1638 });1639 });
1639 try std.testing.expectEqual(Vec3{ .x = 1.2, .y = 3.4, .z = 5.6 }, three);1640 try std.testing.expectEqual(Vec3{ .x = 1.2, .y = 3.4, .z = 5.6 }, three);
1640 }1641 }
...@@ -1647,7 +1648,7 @@ test "std.zon structs" {...@@ -1647,7 +1648,7 @@ test "std.zon structs" {
1647 .gpa = gpa,1648 .gpa = gpa,
1648 .arena = arena,1649 .arena = arena,
1649 .source = ".{.bar = \"qux\", .baz = .{\"a\", \"b\"}}",1650 .source = ".{.bar = \"qux\", .baz = .{\"a\", \"b\"}}",
1650 .diag = null,1651 .errors = null,
1651 });1652 });
1652 try std.testing.expectEqualDeep(Foo{ .bar = "qux", .baz = &.{ "a", "b" } }, parsed);1653 try std.testing.expectEqualDeep(Foo{ .bar = "qux", .baz = &.{ "a", "b" } }, parsed);
1653 }1654 }
...@@ -1655,13 +1656,13 @@ test "std.zon structs" {...@@ -1655,13 +1656,13 @@ test "std.zon structs" {
1655 // Unknown field1656 // Unknown field
1656 {1657 {
1657 const Vec2 = struct { x: f32, y: f32 };1658 const Vec2 = struct { x: f32, y: f32 };
1658 var diag: Diagnostics = .init(arena);1659 var errors: Errors = .init(arena);
1659 try std.testing.expectError(1660 try std.testing.expectError(
1660 error.ParseZon,1661 error.ParseZon,
1661 fromSlice(Vec2, .{1662 fromSlice(Vec2, .{
1662 .gpa = gpa,1663 .gpa = gpa,
1663 .source = ".{.x=1.5, .z=2.5}",1664 .source = ".{.x=1.5, .z=2.5}",
1664 .diag = &diag,1665 .errors = &errors,
1665 }),1666 }),
1666 );1667 );
1667 try std.testing.expectFmt(1668 try std.testing.expectFmt(
...@@ -1670,27 +1671,27 @@ test "std.zon structs" {...@@ -1670,27 +1671,27 @@ test "std.zon structs" {
1670 \\1671 \\
1671 ,1672 ,
1672 "{f}",1673 "{f}",
1673 .{diag},1674 .{errors},
1674 );1675 );
1675 }1676 }
16761677
1677 // Duplicate field1678 // Duplicate field
1678 {1679 {
1679 const Vec2 = struct { x: f32, y: f32 };1680 const Vec2 = struct { x: f32, y: f32 };
1680 var diag: Diagnostics = .init(arena);1681 var errors: Errors = .init(arena);
1681 try std.testing.expectError(1682 try std.testing.expectError(
1682 error.ParseZon,1683 error.ParseZon,
1683 fromSlice(Vec2, .{1684 fromSlice(Vec2, .{
1684 .gpa = gpa,1685 .gpa = gpa,
1685 .source = ".{.x=1.5, .x=2.5, .x=3.5}",1686 .source = ".{.x=1.5, .x=2.5, .x=3.5}",
1686 .diag = &diag,1687 .errors = &errors,
1687 }),1688 }),
1688 );1689 );
1689 try std.testing.expectFmt(1690 try std.testing.expectFmt(
1690 \\1:4: error: duplicate struct field name1691 \\1:4: error: duplicate struct field name
1691 \\1:12: note: duplicate name here1692 \\1:12: note: duplicate name here
1692 \\1693 \\
1693 , "{f}", .{diag});1694 , "{f}", .{errors});
1694 }1695 }
16951696
1696 // Ignore unknown fields1697 // Ignore unknown fields
...@@ -1700,7 +1701,7 @@ test "std.zon structs" {...@@ -1700,7 +1701,7 @@ test "std.zon structs" {
1700 .gpa = gpa,1701 .gpa = gpa,
1701 .source = ".{ .x = 1.0, .z = 3.0 }",1702 .source = ".{ .x = 1.0, .z = 3.0 }",
1702 .ignore_unknown_fields = true,1703 .ignore_unknown_fields = true,
1703 .diag = null,1704 .errors = null,
1704 });1705 });
1705 try std.testing.expectEqual(Vec2{ .x = 1.0, .y = 2.0 }, parsed);1706 try std.testing.expectEqual(Vec2{ .x = 1.0, .y = 2.0 }, parsed);
1706 }1707 }
...@@ -1708,35 +1709,35 @@ test "std.zon structs" {...@@ -1708,35 +1709,35 @@ test "std.zon structs" {
1708 // Unknown field when struct has no fields (regression test)1709 // Unknown field when struct has no fields (regression test)
1709 {1710 {
1710 const Vec2 = struct {};1711 const Vec2 = struct {};
1711 var diag: Diagnostics = .init(arena);1712 var errors: Errors = .init(arena);
1712 try std.testing.expectError(1713 try std.testing.expectError(
1713 error.ParseZon,1714 error.ParseZon,
1714 fromSlice(Vec2, .{1715 fromSlice(Vec2, .{
1715 .gpa = gpa,1716 .gpa = gpa,
1716 .source = ".{.x=1.5, .z=2.5}",1717 .source = ".{.x=1.5, .z=2.5}",
1717 .diag = &diag,1718 .errors = &errors,
1718 }),1719 }),
1719 );1720 );
1720 try std.testing.expectFmt(1721 try std.testing.expectFmt(
1721 \\1:4: error: unexpected field 'x'1722 \\1:4: error: unexpected field 'x'
1722 \\1:4: note: none expected1723 \\1:4: note: none expected
1723 \\1724 \\
1724 , "{f}", .{diag});1725 , "{f}", .{errors});
1725 }1726 }
17261727
1727 // Missing field1728 // Missing field
1728 {1729 {
1729 const Vec2 = struct { x: f32, y: f32 };1730 const Vec2 = struct { x: f32, y: f32 };
1730 var diag: Diagnostics = .init(arena);1731 var errors: Errors = .init(arena);
1731 try std.testing.expectError(1732 try std.testing.expectError(
1732 error.ParseZon,1733 error.ParseZon,
1733 fromSlice(Vec2, .{1734 fromSlice(Vec2, .{
1734 .gpa = gpa,1735 .gpa = gpa,
1735 .source = ".{.x=1.5}",1736 .source = ".{.x=1.5}",
1736 .diag = &diag,1737 .errors = &errors,
1737 }),1738 }),
1738 );1739 );
1739 try std.testing.expectFmt("1:2: error: missing required field y\n", "{f}", .{diag});1740 try std.testing.expectFmt("1:2: error: missing required field y\n", "{f}", .{errors});
1740 }1741 }
17411742
1742 // Default field1743 // Default field
...@@ -1745,7 +1746,7 @@ test "std.zon structs" {...@@ -1745,7 +1746,7 @@ test "std.zon structs" {
1745 const parsed = try fromSlice(Vec2, .{1746 const parsed = try fromSlice(Vec2, .{
1746 .gpa = gpa,1747 .gpa = gpa,
1747 .source = ".{.x = 1.2}",1748 .source = ".{.x = 1.2}",
1748 .diag = null,1749 .errors = null,
1749 });1750 });
1750 try std.testing.expectEqual(Vec2{ .x = 1.2, .y = 1.5 }, parsed);1751 try std.testing.expectEqual(Vec2{ .x = 1.2, .y = 1.5 }, parsed);
1751 }1752 }
...@@ -1756,7 +1757,7 @@ test "std.zon structs" {...@@ -1756,7 +1757,7 @@ test "std.zon structs" {
1756 const parsed = try fromSlice(Vec2, .{1757 const parsed = try fromSlice(Vec2, .{
1757 .gpa = gpa,1758 .gpa = gpa,
1758 .source = ".{.x = 1.2}",1759 .source = ".{.x = 1.2}",
1759 .diag = null,1760 .errors = null,
1760 });1761 });
1761 try std.testing.expectEqual(Vec2{ .x = 1.2, .y = 1.5 }, parsed);1762 try std.testing.expectEqual(Vec2{ .x = 1.2, .y = 1.5 }, parsed);
1762 }1763 }
...@@ -1764,17 +1765,17 @@ test "std.zon structs" {...@@ -1764,17 +1765,17 @@ test "std.zon structs" {
1764 // Comptime field assignment1765 // Comptime field assignment
1765 {1766 {
1766 const Vec2 = struct { x: f32, comptime y: f32 = 1.5 };1767 const Vec2 = struct { x: f32, comptime y: f32 = 1.5 };
1767 var diag: Diagnostics = .init(arena);1768 var errors: Errors = .init(arena);
1768 const parsed = fromSlice(Vec2, .{1769 const parsed = fromSlice(Vec2, .{
1769 .gpa = gpa,1770 .gpa = gpa,
1770 .source = ".{.x = 1.2, .y = 1.5}",1771 .source = ".{.x = 1.2, .y = 1.5}",
1771 .diag = &diag,1772 .errors = &errors,
1772 });1773 });
1773 try std.testing.expectError(error.ParseZon, parsed);1774 try std.testing.expectError(error.ParseZon, parsed);
1774 try std.testing.expectFmt(1775 try std.testing.expectFmt(
1775 \\1:18: error: cannot initialize comptime field1776 \\1:18: error: cannot initialize comptime field
1776 \\1777 \\
1777 , "{f}", .{diag});1778 , "{f}", .{errors});
1778 }1779 }
17791780
1780 // Enum field (regression test, we were previously getting the field name in an1781 // Enum field (regression test, we were previously getting the field name in an
...@@ -1784,7 +1785,7 @@ test "std.zon structs" {...@@ -1784,7 +1785,7 @@ test "std.zon structs" {
1784 const parsed = try fromSlice(Vec0, .{1785 const parsed = try fromSlice(Vec0, .{
1785 .gpa = gpa,1786 .gpa = gpa,
1786 .source = ".{ .x = .x }",1787 .source = ".{ .x = .x }",
1787 .diag = null,1788 .errors = null,
1788 });1789 });
1789 try std.testing.expectEqual(Vec0{ .x = .x }, parsed);1790 try std.testing.expectEqual(Vec0{ .x = .x }, parsed);
1790 }1791 }
...@@ -1795,7 +1796,7 @@ test "std.zon structs" {...@@ -1795,7 +1796,7 @@ test "std.zon structs" {
1795 const parsed = try fromSlice(Vec0, .{1796 const parsed = try fromSlice(Vec0, .{
1796 .gpa = gpa,1797 .gpa = gpa,
1797 .source = ".{ .@\"x x\" = .@\"x x\" }",1798 .source = ".{ .@\"x x\" = .@\"x x\" }",
1798 .diag = null,1799 .errors = null,
1799 });1800 });
1800 try std.testing.expectEqual(Vec0{ .@"x x" = .@"x x" }, parsed);1801 try std.testing.expectEqual(Vec0{ .@"x x" = .@"x x" }, parsed);
1801 }1802 }
...@@ -1804,83 +1805,83 @@ test "std.zon structs" {...@@ -1804,83 +1805,83 @@ test "std.zon structs" {
1804 {1805 {
1805 // Structs1806 // Structs
1806 {1807 {
1807 var diag: Diagnostics = .init(arena);1808 var errors: Errors = .init(arena);
1808 const parsed = fromSlice(struct {}, .{1809 const parsed = fromSlice(struct {}, .{
1809 .gpa = gpa,1810 .gpa = gpa,
1810 .source = "Empty{}",1811 .source = "Empty{}",
1811 .diag = &diag,1812 .errors = &errors,
1812 });1813 });
1813 try std.testing.expectError(error.ParseZon, parsed);1814 try std.testing.expectError(error.ParseZon, parsed);
1814 try std.testing.expectFmt(1815 try std.testing.expectFmt(
1815 \\1:1: error: types are not available in ZON1816 \\1:1: error: types are not available in ZON
1816 \\1:1: note: replace the type with '.'1817 \\1:1: note: replace the type with '.'
1817 \\1818 \\
1818 , "{f}", .{diag});1819 , "{f}", .{errors});
1819 }1820 }
18201821
1821 // Arrays1822 // Arrays
1822 {1823 {
1823 var diag: Diagnostics = .init(arena);1824 var errors: Errors = .init(arena);
1824 const parsed = fromSlice([3]u8, .{1825 const parsed = fromSlice([3]u8, .{
1825 .gpa = gpa,1826 .gpa = gpa,
1826 .source = "[3]u8{1, 2, 3}",1827 .source = "[3]u8{1, 2, 3}",
1827 .diag = &diag,1828 .errors = &errors,
1828 });1829 });
1829 try std.testing.expectError(error.ParseZon, parsed);1830 try std.testing.expectError(error.ParseZon, parsed);
1830 try std.testing.expectFmt(1831 try std.testing.expectFmt(
1831 \\1:1: error: types are not available in ZON1832 \\1:1: error: types are not available in ZON
1832 \\1:1: note: replace the type with '.'1833 \\1:1: note: replace the type with '.'
1833 \\1834 \\
1834 , "{f}", .{diag});1835 , "{f}", .{errors});
1835 }1836 }
18361837
1837 // Slices1838 // Slices
1838 {1839 {
1839 var diag: Diagnostics = .init(arena);1840 var errors: Errors = .init(arena);
1840 const parsed = fromSliceAlloc([]u8, .{1841 const parsed = fromSliceAlloc([]u8, .{
1841 .gpa = gpa,1842 .gpa = gpa,
1842 .arena = arena,1843 .arena = arena,
1843 .source = "[]u8{1, 2, 3}",1844 .source = "[]u8{1, 2, 3}",
1844 .diag = &diag,1845 .errors = &errors,
1845 });1846 });
1846 try std.testing.expectError(error.ParseZon, parsed);1847 try std.testing.expectError(error.ParseZon, parsed);
1847 try std.testing.expectFmt(1848 try std.testing.expectFmt(
1848 \\1:1: error: types are not available in ZON1849 \\1:1: error: types are not available in ZON
1849 \\1:1: note: replace the type with '.'1850 \\1:1: note: replace the type with '.'
1850 \\1851 \\
1851 , "{f}", .{diag});1852 , "{f}", .{errors});
1852 }1853 }
18531854
1854 // Tuples1855 // Tuples
1855 {1856 {
1856 var diag: Diagnostics = .init(arena);1857 var errors: Errors = .init(arena);
1857 const parsed = fromSlice(struct { u8, u8, u8 }, .{1858 const parsed = fromSlice(struct { u8, u8, u8 }, .{
1858 .gpa = gpa,1859 .gpa = gpa,
1859 .source = "Tuple{1, 2, 3}",1860 .source = "Tuple{1, 2, 3}",
1860 .diag = &diag,1861 .errors = &errors,
1861 });1862 });
1862 try std.testing.expectError(error.ParseZon, parsed);1863 try std.testing.expectError(error.ParseZon, parsed);
1863 try std.testing.expectFmt(1864 try std.testing.expectFmt(
1864 \\1:1: error: types are not available in ZON1865 \\1:1: error: types are not available in ZON
1865 \\1:1: note: replace the type with '.'1866 \\1:1: note: replace the type with '.'
1866 \\1867 \\
1867 , "{f}", .{diag});1868 , "{f}", .{errors});
1868 }1869 }
18691870
1870 // Nested1871 // Nested
1871 {1872 {
1872 var diag: Diagnostics = .init(arena);1873 var errors: Errors = .init(arena);
1873 const parsed = fromSlice(struct {}, .{1874 const parsed = fromSlice(struct {}, .{
1874 .gpa = gpa,1875 .gpa = gpa,
1875 .source = ".{ .x = Tuple{1, 2, 3} }",1876 .source = ".{ .x = Tuple{1, 2, 3} }",
1876 .diag = &diag,1877 .errors = &errors,
1877 });1878 });
1878 try std.testing.expectError(error.ParseZon, parsed);1879 try std.testing.expectError(error.ParseZon, parsed);
1879 try std.testing.expectFmt(1880 try std.testing.expectFmt(
1880 \\1:9: error: types are not available in ZON1881 \\1:9: error: types are not available in ZON
1881 \\1:9: note: replace the type with '.'1882 \\1:9: note: replace the type with '.'
1882 \\1883 \\
1883 , "{f}", .{diag});1884 , "{f}", .{errors});
1884 }1885 }
1885 }1886 }
1886}1887}
...@@ -1901,28 +1902,28 @@ test "std.zon tuples" {...@@ -1901,28 +1902,28 @@ test "std.zon tuples" {
1901 const zero = try fromSlice(Tuple0, .{1902 const zero = try fromSlice(Tuple0, .{
1902 .gpa = gpa,1903 .gpa = gpa,
1903 .source = ".{}",1904 .source = ".{}",
1904 .diag = null,1905 .errors = null,
1905 });1906 });
1906 try std.testing.expectEqual(Tuple0{}, zero);1907 try std.testing.expectEqual(Tuple0{}, zero);
19071908
1908 const one = try fromSlice(Tuple1, .{1909 const one = try fromSlice(Tuple1, .{
1909 .gpa = gpa,1910 .gpa = gpa,
1910 .source = ".{1.2}",1911 .source = ".{1.2}",
1911 .diag = null,1912 .errors = null,
1912 });1913 });
1913 try std.testing.expectEqual(Tuple1{1.2}, one);1914 try std.testing.expectEqual(Tuple1{1.2}, one);
19141915
1915 const two = try fromSlice(Tuple2, .{1916 const two = try fromSlice(Tuple2, .{
1916 .gpa = gpa,1917 .gpa = gpa,
1917 .source = ".{1.2, true}",1918 .source = ".{1.2, true}",
1918 .diag = null,1919 .errors = null,
1919 });1920 });
1920 try std.testing.expectEqual(Tuple2{ 1.2, true }, two);1921 try std.testing.expectEqual(Tuple2{ 1.2, true }, two);
19211922
1922 const three = try fromSlice(Tuple3, .{1923 const three = try fromSlice(Tuple3, .{
1923 .gpa = gpa,1924 .gpa = gpa,
1924 .source = ".{1.2, false, 3}",1925 .source = ".{1.2, false, 3}",
1925 .diag = null,1926 .errors = null,
1926 });1927 });
1927 try std.testing.expectEqual(Tuple3{ 1.2, false, 3 }, three);1928 try std.testing.expectEqual(Tuple3{ 1.2, false, 3 }, three);
1928 }1929 }
...@@ -1934,7 +1935,7 @@ test "std.zon tuples" {...@@ -1934,7 +1935,7 @@ test "std.zon tuples" {
1934 .gpa = gpa,1935 .gpa = gpa,
1935 .arena = arena,1936 .arena = arena,
1936 .source = ".{\"hello\", \"world\"}",1937 .source = ".{\"hello\", \"world\"}",
1937 .diag = null,1938 .errors = null,
1938 });1939 });
1939 try std.testing.expectEqualDeep(Tuple{ "hello", "world" }, parsed);1940 try std.testing.expectEqualDeep(Tuple{ "hello", "world" }, parsed);
1940 }1941 }
...@@ -1942,65 +1943,65 @@ test "std.zon tuples" {...@@ -1942,65 +1943,65 @@ test "std.zon tuples" {
1942 // Extra field1943 // Extra field
1943 {1944 {
1944 const Tuple = struct { f32, bool };1945 const Tuple = struct { f32, bool };
1945 var diag: Diagnostics = .init(arena);1946 var errors: Errors = .init(arena);
1946 try std.testing.expectError(1947 try std.testing.expectError(
1947 error.ParseZon,1948 error.ParseZon,
1948 fromSlice(Tuple, .{1949 fromSlice(Tuple, .{
1949 .gpa = gpa,1950 .gpa = gpa,
1950 .source = ".{0.5, true, 123}",1951 .source = ".{0.5, true, 123}",
1951 .diag = &diag,1952 .errors = &errors,
1952 }),1953 }),
1953 );1954 );
1954 try std.testing.expectFmt("1:14: error: index 2 outside of tuple length 2\n", "{f}", .{diag});1955 try std.testing.expectFmt("1:14: error: index 2 outside of tuple length 2\n", "{f}", .{errors});
1955 }1956 }
19561957
1957 // Extra field1958 // Extra field
1958 {1959 {
1959 const Tuple = struct { f32, bool };1960 const Tuple = struct { f32, bool };
1960 var diag: Diagnostics = .init(arena);1961 var errors: Errors = .init(arena);
1961 try std.testing.expectError(1962 try std.testing.expectError(
1962 error.ParseZon,1963 error.ParseZon,
1963 fromSlice(Tuple, .{1964 fromSlice(Tuple, .{
1964 .gpa = gpa,1965 .gpa = gpa,
1965 .source = ".{0.5}",1966 .source = ".{0.5}",
1966 .diag = &diag,1967 .errors = &errors,
1967 }),1968 }),
1968 );1969 );
1969 try std.testing.expectFmt(1970 try std.testing.expectFmt(
1970 "1:2: error: missing tuple field with index 1\n",1971 "1:2: error: missing tuple field with index 1\n",
1971 "{f}",1972 "{f}",
1972 .{diag},1973 .{errors},
1973 );1974 );
1974 }1975 }
19751976
1976 // Tuple with unexpected field names1977 // Tuple with unexpected field names
1977 {1978 {
1978 const Tuple = struct { f32 };1979 const Tuple = struct { f32 };
1979 var diag: Diagnostics = .init(arena);1980 var errors: Errors = .init(arena);
1980 try std.testing.expectError(1981 try std.testing.expectError(
1981 error.ParseZon,1982 error.ParseZon,
1982 fromSlice(Tuple, .{1983 fromSlice(Tuple, .{
1983 .gpa = gpa,1984 .gpa = gpa,
1984 .source = ".{.foo = 10.0}",1985 .source = ".{.foo = 10.0}",
1985 .diag = &diag,1986 .errors = &errors,
1986 }),1987 }),
1987 );1988 );
1988 try std.testing.expectFmt("1:2: error: expected tuple\n", "{f}", .{diag});1989 try std.testing.expectFmt("1:2: error: expected tuple\n", "{f}", .{errors});
1989 }1990 }
19901991
1991 // Struct with missing field names1992 // Struct with missing field names
1992 {1993 {
1993 const Struct = struct { foo: f32 };1994 const Struct = struct { foo: f32 };
1994 var diag: Diagnostics = .init(arena);1995 var errors: Errors = .init(arena);
1995 try std.testing.expectError(1996 try std.testing.expectError(
1996 error.ParseZon,1997 error.ParseZon,
1997 fromSlice(Struct, .{1998 fromSlice(Struct, .{
1998 .gpa = gpa,1999 .gpa = gpa,
1999 .source = ".{10.0}",2000 .source = ".{10.0}",
2000 .diag = &diag,2001 .errors = &errors,
2001 }),2002 }),
2002 );2003 );
2003 try std.testing.expectFmt("1:2: error: expected struct\n", "{f}", .{diag});2004 try std.testing.expectFmt("1:2: error: expected struct\n", "{f}", .{errors});
2004 }2005 }
20052006
2006 // Comptime field2007 // Comptime field
...@@ -2009,7 +2010,7 @@ test "std.zon tuples" {...@@ -2009,7 +2010,7 @@ test "std.zon tuples" {
2009 const parsed = try fromSlice(Vec2, .{2010 const parsed = try fromSlice(Vec2, .{
2010 .gpa = gpa,2011 .gpa = gpa,
2011 .source = ".{ 1.2 }",2012 .source = ".{ 1.2 }",
2012 .diag = null,2013 .errors = null,
2013 });2014 });
2014 try std.testing.expectEqual(Vec2{ 1.2, 1.5 }, parsed);2015 try std.testing.expectEqual(Vec2{ 1.2, 1.5 }, parsed);
2015 }2016 }
...@@ -2017,17 +2018,17 @@ test "std.zon tuples" {...@@ -2017,17 +2018,17 @@ test "std.zon tuples" {
2017 // Comptime field assignment2018 // Comptime field assignment
2018 {2019 {
2019 const Vec2 = struct { f32, comptime f32 = 1.5 };2020 const Vec2 = struct { f32, comptime f32 = 1.5 };
2020 var diag: Diagnostics = .init(arena);2021 var errors: Errors = .init(arena);
2021 const parsed = fromSlice(Vec2, .{2022 const parsed = fromSlice(Vec2, .{
2022 .gpa = gpa,2023 .gpa = gpa,
2023 .source = ".{ 1.2, 1.5}",2024 .source = ".{ 1.2, 1.5}",
2024 .diag = &diag,2025 .errors = &errors,
2025 });2026 });
2026 try std.testing.expectError(error.ParseZon, parsed);2027 try std.testing.expectError(error.ParseZon, parsed);
2027 try std.testing.expectFmt(2028 try std.testing.expectFmt(
2028 \\1:9: error: cannot initialize comptime field2029 \\1:9: error: cannot initialize comptime field
2029 \\2030 \\
2030 , "{f}", .{diag});2031 , "{f}", .{errors});
2031 }2032 }
2032}2033}
20332034
...@@ -2045,42 +2046,42 @@ test "std.zon arrays and slices" {...@@ -2045,42 +2046,42 @@ test "std.zon arrays and slices" {
2045 const zero = try fromSlice([0]u8, .{2046 const zero = try fromSlice([0]u8, .{
2046 .gpa = gpa,2047 .gpa = gpa,
2047 .source = ".{}",2048 .source = ".{}",
2048 .diag = null,2049 .errors = null,
2049 });2050 });
2050 try std.testing.expectEqualSlices(u8, &@as([0]u8, .{}), &zero);2051 try std.testing.expectEqualSlices(u8, &@as([0]u8, .{}), &zero);
20512052
2052 const one = try fromSlice([1]u8, .{2053 const one = try fromSlice([1]u8, .{
2053 .gpa = gpa,2054 .gpa = gpa,
2054 .source = ".{'a'}",2055 .source = ".{'a'}",
2055 .diag = null,2056 .errors = null,
2056 });2057 });
2057 try std.testing.expectEqualSlices(u8, &@as([1]u8, .{'a'}), &one);2058 try std.testing.expectEqualSlices(u8, &@as([1]u8, .{'a'}), &one);
20582059
2059 const two = try fromSlice([2]u8, .{2060 const two = try fromSlice([2]u8, .{
2060 .gpa = gpa,2061 .gpa = gpa,
2061 .source = ".{'a', 'b'}",2062 .source = ".{'a', 'b'}",
2062 .diag = null,2063 .errors = null,
2063 });2064 });
2064 try std.testing.expectEqualSlices(u8, &@as([2]u8, .{ 'a', 'b' }), &two);2065 try std.testing.expectEqualSlices(u8, &@as([2]u8, .{ 'a', 'b' }), &two);
20652066
2066 const two_comma = try fromSlice([2]u8, .{2067 const two_comma = try fromSlice([2]u8, .{
2067 .gpa = gpa,2068 .gpa = gpa,
2068 .source = ".{'a', 'b',}",2069 .source = ".{'a', 'b',}",
2069 .diag = null,2070 .errors = null,
2070 });2071 });
2071 try std.testing.expectEqualSlices(u8, &@as([2]u8, .{ 'a', 'b' }), &two_comma);2072 try std.testing.expectEqualSlices(u8, &@as([2]u8, .{ 'a', 'b' }), &two_comma);
20722073
2073 const three = try fromSlice([3]u8, .{2074 const three = try fromSlice([3]u8, .{
2074 .gpa = gpa,2075 .gpa = gpa,
2075 .source = ".{'a', 'b', 'c'}",2076 .source = ".{'a', 'b', 'c'}",
2076 .diag = null,2077 .errors = null,
2077 });2078 });
2078 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b', 'c' }, &three);2079 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b', 'c' }, &three);
20792080
2080 const sentinel = try fromSlice([3:'z']u8, .{2081 const sentinel = try fromSlice([3:'z']u8, .{
2081 .gpa = gpa,2082 .gpa = gpa,
2082 .source = ".{'a', 'b', 'c'}",2083 .source = ".{'a', 'b', 'c'}",
2083 .diag = null,2084 .errors = null,
2084 });2085 });
2085 const expected_sentinel: [3:'z']u8 = .{ 'a', 'b', 'c' };2086 const expected_sentinel: [3:'z']u8 = .{ 'a', 'b', 'c' };
2086 try std.testing.expectEqualSlices(u8, &expected_sentinel, &sentinel);2087 try std.testing.expectEqualSlices(u8, &expected_sentinel, &sentinel);
...@@ -2092,7 +2093,7 @@ test "std.zon arrays and slices" {...@@ -2092,7 +2093,7 @@ test "std.zon arrays and slices" {
2092 .gpa = gpa,2093 .gpa = gpa,
2093 .arena = arena,2094 .arena = arena,
2094 .source = ".{}",2095 .source = ".{}",
2095 .diag = null,2096 .errors = null,
2096 });2097 });
2097 try std.testing.expectEqualSlices(u8, @as([]const u8, &.{}), zero);2098 try std.testing.expectEqualSlices(u8, @as([]const u8, &.{}), zero);
20982099
...@@ -2100,7 +2101,7 @@ test "std.zon arrays and slices" {...@@ -2100,7 +2101,7 @@ test "std.zon arrays and slices" {
2100 .gpa = gpa,2101 .gpa = gpa,
2101 .arena = arena,2102 .arena = arena,
2102 .source = ".{'a'}",2103 .source = ".{'a'}",
2103 .diag = null,2104 .errors = null,
2104 });2105 });
2105 try std.testing.expectEqualSlices(u8, &.{'a'}, one);2106 try std.testing.expectEqualSlices(u8, &.{'a'}, one);
21062107
...@@ -2108,7 +2109,7 @@ test "std.zon arrays and slices" {...@@ -2108,7 +2109,7 @@ test "std.zon arrays and slices" {
2108 .gpa = gpa,2109 .gpa = gpa,
2109 .arena = arena,2110 .arena = arena,
2110 .source = ".{'a', 'b'}",2111 .source = ".{'a', 'b'}",
2111 .diag = null,2112 .errors = null,
2112 });2113 });
2113 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b' }, two);2114 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b' }, two);
21142115
...@@ -2116,7 +2117,7 @@ test "std.zon arrays and slices" {...@@ -2116,7 +2117,7 @@ test "std.zon arrays and slices" {
2116 .gpa = gpa,2117 .gpa = gpa,
2117 .arena = arena,2118 .arena = arena,
2118 .source = ".{'a', 'b',}",2119 .source = ".{'a', 'b',}",
2119 .diag = null,2120 .errors = null,
2120 });2121 });
2121 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b' }, two_comma);2122 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b' }, two_comma);
21222123
...@@ -2124,7 +2125,7 @@ test "std.zon arrays and slices" {...@@ -2124,7 +2125,7 @@ test "std.zon arrays and slices" {
2124 .gpa = gpa,2125 .gpa = gpa,
2125 .arena = arena,2126 .arena = arena,
2126 .source = ".{'a', 'b', 'c'}",2127 .source = ".{'a', 'b', 'c'}",
2127 .diag = null,2128 .errors = null,
2128 });2129 });
2129 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b', 'c' }, three);2130 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b', 'c' }, three);
21302131
...@@ -2132,7 +2133,7 @@ test "std.zon arrays and slices" {...@@ -2132,7 +2133,7 @@ test "std.zon arrays and slices" {
2132 .gpa = gpa,2133 .gpa = gpa,
2133 .arena = arena,2134 .arena = arena,
2134 .source = ".{'a', 'b', 'c'}",2135 .source = ".{'a', 'b', 'c'}",
2135 .diag = null,2136 .errors = null,
2136 });2137 });
2137 const expected_sentinel: [:'z']const u8 = &.{ 'a', 'b', 'c' };2138 const expected_sentinel: [:'z']const u8 = &.{ 'a', 'b', 'c' };
2138 try std.testing.expectEqualSlices(u8, expected_sentinel, sentinel);2139 try std.testing.expectEqualSlices(u8, expected_sentinel, sentinel);
...@@ -2147,7 +2148,7 @@ test "std.zon arrays and slices" {...@@ -2147,7 +2148,7 @@ test "std.zon arrays and slices" {
2147 .gpa = gpa,2148 .gpa = gpa,
2148 .arena = arena,2149 .arena = arena,
2149 .source = ".{\"abc\"}",2150 .source = ".{\"abc\"}",
2150 .diag = null,2151 .errors = null,
2151 });2152 });
2152 const expected: [1][]const u8 = .{"abc"};2153 const expected: [1][]const u8 = .{"abc"};
2153 try std.testing.expectEqualDeep(expected, parsed);2154 try std.testing.expectEqualDeep(expected, parsed);
...@@ -2159,7 +2160,7 @@ test "std.zon arrays and slices" {...@@ -2159,7 +2160,7 @@ test "std.zon arrays and slices" {
2159 .gpa = gpa,2160 .gpa = gpa,
2160 .arena = arena,2161 .arena = arena,
2161 .source = ".{\"abc\"}",2162 .source = ".{\"abc\"}",
2162 .diag = null,2163 .errors = null,
2163 });2164 });
2164 const expected: []const []const u8 = &.{"abc"};2165 const expected: []const []const u8 = &.{"abc"};
2165 try std.testing.expectEqualDeep(expected, parsed);2166 try std.testing.expectEqualDeep(expected, parsed);
...@@ -2173,7 +2174,7 @@ test "std.zon arrays and slices" {...@@ -2173,7 +2174,7 @@ test "std.zon arrays and slices" {
2173 const sentinel = try fromSlice([1:2]u8, .{2174 const sentinel = try fromSlice([1:2]u8, .{
2174 .gpa = gpa,2175 .gpa = gpa,
2175 .source = ".{1}",2176 .source = ".{1}",
2176 .diag = null,2177 .errors = null,
2177 });2178 });
2178 try std.testing.expectEqual(@as(usize, 1), sentinel.len);2179 try std.testing.expectEqual(@as(usize, 1), sentinel.len);
2179 try std.testing.expectEqual(@as(u8, 1), sentinel[0]);2180 try std.testing.expectEqual(@as(u8, 1), sentinel[0]);
...@@ -2186,7 +2187,7 @@ test "std.zon arrays and slices" {...@@ -2186,7 +2187,7 @@ test "std.zon arrays and slices" {
2186 .gpa = gpa,2187 .gpa = gpa,
2187 .arena = arena,2188 .arena = arena,
2188 .source = ".{1}",2189 .source = ".{1}",
2189 .diag = null,2190 .errors = null,
2190 });2191 });
2191 try std.testing.expectEqual(@as(usize, 1), sentinel.len);2192 try std.testing.expectEqual(@as(usize, 1), sentinel.len);
2192 try std.testing.expectEqual(@as(u8, 1), sentinel[0]);2193 try std.testing.expectEqual(@as(u8, 1), sentinel[0]);
...@@ -2196,73 +2197,73 @@ test "std.zon arrays and slices" {...@@ -2196,73 +2197,73 @@ test "std.zon arrays and slices" {
21962197
2197 // Expect 0 find 32198 // Expect 0 find 3
2198 {2199 {
2199 var diag: Diagnostics = .init(arena);2200 var errors: Errors = .init(arena);
2200 try std.testing.expectError(2201 try std.testing.expectError(
2201 error.ParseZon,2202 error.ParseZon,
2202 fromSlice([0]u8, .{2203 fromSlice([0]u8, .{
2203 .gpa = gpa,2204 .gpa = gpa,
2204 .source = ".{'a', 'b', 'c'}",2205 .source = ".{'a', 'b', 'c'}",
2205 .diag = &diag,2206 .errors = &errors,
2206 }),2207 }),
2207 );2208 );
2208 try std.testing.expectFmt(2209 try std.testing.expectFmt(
2209 "1:3: error: index 0 outside of array of length 0\n",2210 "1:3: error: index 0 outside of array of length 0\n",
2210 "{f}",2211 "{f}",
2211 .{diag},2212 .{errors},
2212 );2213 );
2213 }2214 }
22142215
2215 // Expect 1 find 22216 // Expect 1 find 2
2216 {2217 {
2217 var diag: Diagnostics = .init(arena);2218 var errors: Errors = .init(arena);
2218 try std.testing.expectError(2219 try std.testing.expectError(
2219 error.ParseZon,2220 error.ParseZon,
2220 fromSlice([1]u8, .{2221 fromSlice([1]u8, .{
2221 .gpa = gpa,2222 .gpa = gpa,
2222 .source = ".{'a', 'b'}",2223 .source = ".{'a', 'b'}",
2223 .diag = &diag,2224 .errors = &errors,
2224 }),2225 }),
2225 );2226 );
2226 try std.testing.expectFmt(2227 try std.testing.expectFmt(
2227 "1:8: error: index 1 outside of array of length 1\n",2228 "1:8: error: index 1 outside of array of length 1\n",
2228 "{f}",2229 "{f}",
2229 .{diag},2230 .{errors},
2230 );2231 );
2231 }2232 }
22322233
2233 // Expect 2 find 12234 // Expect 2 find 1
2234 {2235 {
2235 var diag: Diagnostics = .init(arena);2236 var errors: Errors = .init(arena);
2236 try std.testing.expectError(2237 try std.testing.expectError(
2237 error.ParseZon,2238 error.ParseZon,
2238 fromSlice([2]u8, .{2239 fromSlice([2]u8, .{
2239 .gpa = gpa,2240 .gpa = gpa,
2240 .source = ".{'a'}",2241 .source = ".{'a'}",
2241 .diag = &diag,2242 .errors = &errors,
2242 }),2243 }),
2243 );2244 );
2244 try std.testing.expectFmt(2245 try std.testing.expectFmt(
2245 "1:2: error: expected 2 array elements; found 1\n",2246 "1:2: error: expected 2 array elements; found 1\n",
2246 "{f}",2247 "{f}",
2247 .{diag},2248 .{errors},
2248 );2249 );
2249 }2250 }
22502251
2251 // Expect 3 find 02252 // Expect 3 find 0
2252 {2253 {
2253 var diag: Diagnostics = .init(arena);2254 var errors: Errors = .init(arena);
2254 try std.testing.expectError(2255 try std.testing.expectError(
2255 error.ParseZon,2256 error.ParseZon,
2256 fromSlice([3]u8, .{2257 fromSlice([3]u8, .{
2257 .gpa = gpa,2258 .gpa = gpa,
2258 .source = ".{}",2259 .source = ".{}",
2259 .diag = &diag,2260 .errors = &errors,
2260 }),2261 }),
2261 );2262 );
2262 try std.testing.expectFmt(2263 try std.testing.expectFmt(
2263 "1:2: error: expected 3 array elements; found 0\n",2264 "1:2: error: expected 3 array elements; found 0\n",
2264 "{f}",2265 "{f}",
2265 .{diag},2266 .{errors},
2266 );2267 );
2267 }2268 }
22682269
...@@ -2270,31 +2271,31 @@ test "std.zon arrays and slices" {...@@ -2270,31 +2271,31 @@ test "std.zon arrays and slices" {
2270 {2271 {
2271 // Array2272 // Array
2272 {2273 {
2273 var diag: Diagnostics = .init(arena);2274 var errors: Errors = .init(arena);
2274 try std.testing.expectError(2275 try std.testing.expectError(
2275 error.ParseZon,2276 error.ParseZon,
2276 fromSlice([3]bool, .{2277 fromSlice([3]bool, .{
2277 .gpa = gpa,2278 .gpa = gpa,
2278 .source = ".{'a', 'b', 'c'}",2279 .source = ".{'a', 'b', 'c'}",
2279 .diag = &diag,2280 .errors = &errors,
2280 }),2281 }),
2281 );2282 );
2282 try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{f}", .{diag});2283 try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{f}", .{errors});
2283 }2284 }
22842285
2285 // Slice2286 // Slice
2286 {2287 {
2287 var diag: Diagnostics = .init(arena);2288 var errors: Errors = .init(arena);
2288 try std.testing.expectError(2289 try std.testing.expectError(
2289 error.ParseZon,2290 error.ParseZon,
2290 fromSliceAlloc([]bool, .{2291 fromSliceAlloc([]bool, .{
2291 .gpa = gpa,2292 .gpa = gpa,
2292 .arena = arena,2293 .arena = arena,
2293 .source = ".{'a', 'b', 'c'}",2294 .source = ".{'a', 'b', 'c'}",
2294 .diag = &diag,2295 .errors = &errors,
2295 }),2296 }),
2296 );2297 );
2297 try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{f}", .{diag});2298 try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{f}", .{errors});
2298 }2299 }
2299 }2300 }
23002301
...@@ -2302,40 +2303,40 @@ test "std.zon arrays and slices" {...@@ -2302,40 +2303,40 @@ test "std.zon arrays and slices" {
2302 {2303 {
2303 // Array2304 // Array
2304 {2305 {
2305 var diag: Diagnostics = .init(arena);2306 var errors: Errors = .init(arena);
2306 try std.testing.expectError(2307 try std.testing.expectError(
2307 error.ParseZon,2308 error.ParseZon,
2308 fromSlice([3]u8, .{2309 fromSlice([3]u8, .{
2309 .gpa = gpa,2310 .gpa = gpa,
2310 .source = "'a'",2311 .source = "'a'",
2311 .diag = &diag,2312 .errors = &errors,
2312 }),2313 }),
2313 );2314 );
2314 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});2315 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
2315 }2316 }
23162317
2317 // Slice2318 // Slice
2318 {2319 {
2319 var diag: Diagnostics = .init(arena);2320 var errors: Errors = .init(arena);
2320 try std.testing.expectError(2321 try std.testing.expectError(
2321 error.ParseZon,2322 error.ParseZon,
2322 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = "'a'", .diag = &diag }),2323 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = "'a'", .errors = &errors }),
2323 );2324 );
2324 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});2325 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
2325 }2326 }
2326 }2327 }
23272328
2328 // Address of is not allowed (indirection for slices in ZON is implicit)2329 // Address of is not allowed (indirection for slices in ZON is implicit)
2329 {2330 {
2330 var diag: Diagnostics = .init(arena);2331 var errors: Errors = .init(arena);
2331 try std.testing.expectError(2332 try std.testing.expectError(
2332 error.ParseZon,2333 error.ParseZon,
2333 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = " &.{'a', 'b', 'c'}", .diag = &diag }),2334 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = " &.{'a', 'b', 'c'}", .errors = &errors }),
2334 );2335 );
2335 try std.testing.expectFmt(2336 try std.testing.expectFmt(
2336 "1:3: error: pointers are not available in ZON\n",2337 "1:3: error: pointers are not available in ZON\n",
2337 "{f}",2338 "{f}",
2338 .{diag},2339 .{errors},
2339 );2340 );
2340 }2341 }
2341}2342}
...@@ -2352,7 +2353,7 @@ test "std.zon string literal" {...@@ -2352,7 +2353,7 @@ test "std.zon string literal" {
2352 .gpa = gpa,2353 .gpa = gpa,
2353 .arena = arena,2354 .arena = arena,
2354 .source = "\"abc\"",2355 .source = "\"abc\"",
2355 .diag = null,2356 .errors = null,
2356 });2357 });
2357 try std.testing.expectEqualStrings(@as([]const u8, "abc"), parsed);2358 try std.testing.expectEqualStrings(@as([]const u8, "abc"), parsed);
2358 }2359 }
...@@ -2363,7 +2364,7 @@ test "std.zon string literal" {...@@ -2363,7 +2364,7 @@ test "std.zon string literal" {
2363 .gpa = gpa,2364 .gpa = gpa,
2364 .arena = arena,2365 .arena = arena,
2365 .source = "\"ab\\nc\"",2366 .source = "\"ab\\nc\"",
2366 .diag = null,2367 .errors = null,
2367 });2368 });
2368 try std.testing.expectEqualStrings(@as([]const u8, "ab\nc"), parsed);2369 try std.testing.expectEqualStrings(@as([]const u8, "ab\nc"), parsed);
2369 }2370 }
...@@ -2374,7 +2375,7 @@ test "std.zon string literal" {...@@ -2374,7 +2375,7 @@ test "std.zon string literal" {
2374 .gpa = gpa,2375 .gpa = gpa,
2375 .arena = arena,2376 .arena = arena,
2376 .source = "\"ab\\x00c\"",2377 .source = "\"ab\\x00c\"",
2377 .diag = null,2378 .errors = null,
2378 });2379 });
2379 try std.testing.expectEqualStrings(@as([]const u8, "ab\x00c"), parsed);2380 try std.testing.expectEqualStrings(@as([]const u8, "ab\x00c"), parsed);
2380 }2381 }
...@@ -2382,21 +2383,21 @@ test "std.zon string literal" {...@@ -2382,21 +2383,21 @@ test "std.zon string literal" {
2382 // Passing string literal to a mutable slice2383 // Passing string literal to a mutable slice
2383 {2384 {
2384 {2385 {
2385 var diag: Diagnostics = .init(arena);2386 var errors: Errors = .init(arena);
2386 try std.testing.expectError(2387 try std.testing.expectError(
2387 error.ParseZon,2388 error.ParseZon,
2388 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = "\"abcd\"", .diag = &diag }),2389 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = "\"abcd\"", .errors = &errors }),
2389 );2390 );
2390 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});2391 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
2391 }2392 }
23922393
2393 {2394 {
2394 var diag: Diagnostics = .init(arena);2395 var errors: Errors = .init(arena);
2395 try std.testing.expectError(2396 try std.testing.expectError(
2396 error.ParseZon,2397 error.ParseZon,
2397 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\abcd", .diag = &diag }),2398 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\abcd", .errors = &errors }),
2398 );2399 );
2399 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});2400 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
2400 }2401 }
2401 }2402 }
24022403
...@@ -2407,29 +2408,29 @@ test "std.zon string literal" {...@@ -2407,29 +2408,29 @@ test "std.zon string literal" {
2407 defer ast.deinit(gpa);2408 defer ast.deinit(gpa);
2408 var zoir = try ZonGen.generate(gpa, ast, .{ .parse_str_lits = false });2409 var zoir = try ZonGen.generate(gpa, ast, .{ .parse_str_lits = false });
2409 defer zoir.deinit(gpa);2410 defer zoir.deinit(gpa);
2410 var diag: Diagnostics = .init(arena);2411 var errors: Errors = .init(arena);
2411 try std.testing.expectError(2412 try std.testing.expectError(
2412 error.ParseZon,2413 error.ParseZon,
2413 fromSlice([4:0]u8, .{2414 fromSlice([4:0]u8, .{
2414 .gpa = gpa,2415 .gpa = gpa,
2415 .source = "\"abcd\"",2416 .source = "\"abcd\"",
2416 .diag = &diag,2417 .errors = &errors,
2417 }),2418 }),
2418 );2419 );
2419 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});2420 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
2420 }2421 }
24212422
2422 {2423 {
2423 var diag: Diagnostics = .init(arena);2424 var errors: Errors = .init(arena);
2424 try std.testing.expectError(2425 try std.testing.expectError(
2425 error.ParseZon,2426 error.ParseZon,
2426 fromSlice([4:0]u8, .{2427 fromSlice([4:0]u8, .{
2427 .gpa = gpa,2428 .gpa = gpa,
2428 .source = "\\\\abcd",2429 .source = "\\\\abcd",
2429 .diag = &diag,2430 .errors = &errors,
2430 }),2431 }),
2431 );2432 );
2432 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});2433 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
2433 }2434 }
2434 }2435 }
24352436
...@@ -2440,7 +2441,7 @@ test "std.zon string literal" {...@@ -2440,7 +2441,7 @@ test "std.zon string literal" {
2440 .gpa = gpa,2441 .gpa = gpa,
2441 .arena = arena,2442 .arena = arena,
2442 .source = "\"abc\"",2443 .source = "\"abc\"",
2443 .diag = null,2444 .errors = null,
2444 });2445 });
2445 try std.testing.expectEqualStrings("abc", parsed);2446 try std.testing.expectEqualStrings("abc", parsed);
2446 try std.testing.expectEqual(@as(u8, 0), parsed[3]);2447 try std.testing.expectEqual(@as(u8, 0), parsed[3]);
...@@ -2451,7 +2452,7 @@ test "std.zon string literal" {...@@ -2451,7 +2452,7 @@ test "std.zon string literal" {
2451 .gpa = gpa,2452 .gpa = gpa,
2452 .arena = arena,2453 .arena = arena,
2453 .source = "\\\\abc",2454 .source = "\\\\abc",
2454 .diag = null,2455 .errors = null,
2455 });2456 });
2456 try std.testing.expectEqualStrings("abc", parsed);2457 try std.testing.expectEqualStrings("abc", parsed);
2457 try std.testing.expectEqual(@as(u8, 0), parsed[3]);2458 try std.testing.expectEqual(@as(u8, 0), parsed[3]);
...@@ -2461,103 +2462,103 @@ test "std.zon string literal" {...@@ -2461,103 +2462,103 @@ test "std.zon string literal" {
2461 // Other value terminated slices2462 // Other value terminated slices
2462 {2463 {
2463 {2464 {
2464 var diag: Diagnostics = .init(arena);2465 var errors: Errors = .init(arena);
2465 try std.testing.expectError(2466 try std.testing.expectError(
2466 error.ParseZon,2467 error.ParseZon,
2467 fromSliceAlloc([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\"foo\"", .diag = &diag }),2468 fromSliceAlloc([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\"foo\"", .errors = &errors }),
2468 );2469 );
2469 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});2470 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
2470 }2471 }
24712472
2472 {2473 {
2473 var diag: Diagnostics = .init(arena);2474 var errors: Errors = .init(arena);
2474 try std.testing.expectError(2475 try std.testing.expectError(
2475 error.ParseZon,2476 error.ParseZon,
2476 fromSliceAlloc([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\foo", .diag = &diag }),2477 fromSliceAlloc([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\foo", .errors = &errors }),
2477 );2478 );
2478 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});2479 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
2479 }2480 }
2480 }2481 }
24812482
2482 // Expecting string literal, getting something else2483 // Expecting string literal, getting something else
2483 {2484 {
2484 var diag: Diagnostics = .init(arena);2485 var errors: Errors = .init(arena);
2485 try std.testing.expectError(2486 try std.testing.expectError(
2486 error.ParseZon,2487 error.ParseZon,
2487 fromSliceAlloc([]const u8, .{ .gpa = gpa, .arena = arena, .source = "true", .diag = &diag }),2488 fromSliceAlloc([]const u8, .{ .gpa = gpa, .arena = arena, .source = "true", .errors = &errors }),
2488 );2489 );
2489 try std.testing.expectFmt("1:1: error: expected string\n", "{f}", .{diag});2490 try std.testing.expectFmt("1:1: error: expected string\n", "{f}", .{errors});
2490 }2491 }
24912492
2492 // Expecting string literal, getting an incompatible tuple2493 // Expecting string literal, getting an incompatible tuple
2493 {2494 {
2494 var diag: Diagnostics = .init(arena);2495 var errors: Errors = .init(arena);
2495 try std.testing.expectError(2496 try std.testing.expectError(
2496 error.ParseZon,2497 error.ParseZon,
2497 fromSliceAlloc([]const u8, .{ .gpa = gpa, .arena = arena, .source = ".{false}", .diag = &diag }),2498 fromSliceAlloc([]const u8, .{ .gpa = gpa, .arena = arena, .source = ".{false}", .errors = &errors }),
2498 );2499 );
2499 try std.testing.expectFmt("1:3: error: expected type 'u8'\n", "{f}", .{diag});2500 try std.testing.expectFmt("1:3: error: expected type 'u8'\n", "{f}", .{errors});
2500 }2501 }
25012502
2502 // Invalid string literal2503 // Invalid string literal
2503 {2504 {
2504 var diag: Diagnostics = .init(arena);2505 var errors: Errors = .init(arena);
2505 try std.testing.expectError(2506 try std.testing.expectError(
2506 error.ParseZon,2507 error.ParseZon,
2507 fromSliceAlloc([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"\\a\"", .diag = &diag }),2508 fromSliceAlloc([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"\\a\"", .errors = &errors }),
2508 );2509 );
2509 try std.testing.expectFmt("1:3: error: invalid escape character: 'a'\n", "{f}", .{diag});2510 try std.testing.expectFmt("1:3: error: invalid escape character: 'a'\n", "{f}", .{errors});
2510 }2511 }
25112512
2512 // Slice wrong child type2513 // Slice wrong child type
2513 {2514 {
2514 {2515 {
2515 var diag: Diagnostics = .init(arena);2516 var errors: Errors = .init(arena);
2516 try std.testing.expectError(2517 try std.testing.expectError(
2517 error.ParseZon,2518 error.ParseZon,
2518 fromSliceAlloc([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"a\"", .diag = &diag }),2519 fromSliceAlloc([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"a\"", .errors = &errors }),
2519 );2520 );
2520 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});2521 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
2521 }2522 }
25222523
2523 {2524 {
2524 var diag: Diagnostics = .init(arena);2525 var errors: Errors = .init(arena);
2525 try std.testing.expectError(2526 try std.testing.expectError(
2526 error.ParseZon,2527 error.ParseZon,
2527 fromSliceAlloc([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\\\\a", .diag = &diag }),2528 fromSliceAlloc([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\\\\a", .errors = &errors }),
2528 );2529 );
2529 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});2530 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
2530 }2531 }
2531 }2532 }
25322533
2533 // Bad alignment2534 // Bad alignment
2534 {2535 {
2535 {2536 {
2536 var diag: Diagnostics = .init(arena);2537 var errors: Errors = .init(arena);
2537 try std.testing.expectError(2538 try std.testing.expectError(
2538 error.ParseZon,2539 error.ParseZon,
2539 fromSliceAlloc([]align(2) const u8, .{2540 fromSliceAlloc([]align(2) const u8, .{
2540 .gpa = gpa,2541 .gpa = gpa,
2541 .arena = arena,2542 .arena = arena,
2542 .source = "\"abc\"",2543 .source = "\"abc\"",
2543 .diag = &diag,2544 .errors = &errors,
2544 }),2545 }),
2545 );2546 );
2546 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});2547 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
2547 }2548 }
25482549
2549 {2550 {
2550 var diag: Diagnostics = .init(arena);2551 var errors: Errors = .init(arena);
2551 try std.testing.expectError(2552 try std.testing.expectError(
2552 error.ParseZon,2553 error.ParseZon,
2553 fromSliceAlloc([]align(2) const u8, .{2554 fromSliceAlloc([]align(2) const u8, .{
2554 .gpa = gpa,2555 .gpa = gpa,
2555 .arena = arena,2556 .arena = arena,
2556 .source = "\\\\abc",2557 .source = "\\\\abc",
2557 .diag = &diag,2558 .errors = &errors,
2558 }),2559 }),
2559 );2560 );
2560 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});2561 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
2561 }2562 }
2562 }2563 }
25632564
...@@ -2591,7 +2592,7 @@ test "std.zon string literal" {...@@ -2591,7 +2592,7 @@ test "std.zon string literal" {
2591 \\ \\and this.2592 \\ \\and this.
2592 \\}2593 \\}
2593 ,2594 ,
2594 .diag = null,2595 .errors = null,
2595 });2596 });
2596 try std.testing.expectEqualStrings(2597 try std.testing.expectEqualStrings(
2597 "hello, world!\nthis is a multiline string!\n\n...",2598 "hello, world!\nthis is a multiline string!\n\n...",
...@@ -2620,36 +2621,36 @@ test "std.zon enum literals" {...@@ -2620,36 +2621,36 @@ test "std.zon enum literals" {
2620 try std.testing.expectEqual(Enum.foo, try fromSlice(Enum, .{2621 try std.testing.expectEqual(Enum.foo, try fromSlice(Enum, .{
2621 .gpa = gpa,2622 .gpa = gpa,
2622 .source = ".foo",2623 .source = ".foo",
2623 .diag = null,2624 .errors = null,
2624 }));2625 }));
2625 try std.testing.expectEqual(Enum.bar, try fromSlice(Enum, .{2626 try std.testing.expectEqual(Enum.bar, try fromSlice(Enum, .{
2626 .gpa = gpa,2627 .gpa = gpa,
2627 .source = ".bar",2628 .source = ".bar",
2628 .diag = null,2629 .errors = null,
2629 }));2630 }));
2630 try std.testing.expectEqual(Enum.baz, try fromSlice(Enum, .{2631 try std.testing.expectEqual(Enum.baz, try fromSlice(Enum, .{
2631 .gpa = gpa,2632 .gpa = gpa,
2632 .source = ".baz",2633 .source = ".baz",
2633 .diag = null,2634 .errors = null,
2634 }));2635 }));
2635 try std.testing.expectEqual(2636 try std.testing.expectEqual(
2636 Enum.@"ab\nc",2637 Enum.@"ab\nc",
2637 try fromSlice(Enum, .{2638 try fromSlice(Enum, .{
2638 .gpa = gpa,2639 .gpa = gpa,
2639 .source = ".@\"ab\\nc\"",2640 .source = ".@\"ab\\nc\"",
2640 .diag = null,2641 .errors = null,
2641 }),2642 }),
2642 );2643 );
26432644
2644 // Bad tag2645 // Bad tag
2645 {2646 {
2646 var diag: Diagnostics = .init(arena);2647 var errors: Errors = .init(arena);
2647 try std.testing.expectError(2648 try std.testing.expectError(
2648 error.ParseZon,2649 error.ParseZon,
2649 fromSlice(Enum, .{2650 fromSlice(Enum, .{
2650 .gpa = gpa,2651 .gpa = gpa,
2651 .source = ".qux",2652 .source = ".qux",
2652 .diag = &diag,2653 .errors = &errors,
2653 }),2654 }),
2654 );2655 );
2655 try std.testing.expectFmt(2656 try std.testing.expectFmt(
...@@ -2658,19 +2659,19 @@ test "std.zon enum literals" {...@@ -2658,19 +2659,19 @@ test "std.zon enum literals" {
2658 \\2659 \\
2659 ,2660 ,
2660 "{f}",2661 "{f}",
2661 .{diag},2662 .{errors},
2662 );2663 );
2663 }2664 }
26642665
2665 // Bad tag that's too long for parser2666 // Bad tag that's too long for parser
2666 {2667 {
2667 var diag: Diagnostics = .init(arena);2668 var errors: Errors = .init(arena);
2668 try std.testing.expectError(2669 try std.testing.expectError(
2669 error.ParseZon,2670 error.ParseZon,
2670 fromSlice(Enum, .{2671 fromSlice(Enum, .{
2671 .gpa = gpa,2672 .gpa = gpa,
2672 .source = ".@\"foobarbaz\"",2673 .source = ".@\"foobarbaz\"",
2673 .diag = &diag,2674 .errors = &errors,
2674 }),2675 }),
2675 );2676 );
2676 try std.testing.expectFmt(2677 try std.testing.expectFmt(
...@@ -2679,39 +2680,39 @@ test "std.zon enum literals" {...@@ -2679,39 +2680,39 @@ test "std.zon enum literals" {
2679 \\2680 \\
2680 ,2681 ,
2681 "{f}",2682 "{f}",
2682 .{diag},2683 .{errors},
2683 );2684 );
2684 }2685 }
26852686
2686 // Bad type2687 // Bad type
2687 {2688 {
2688 var diag: Diagnostics = .init(arena);2689 var errors: Errors = .init(arena);
2689 try std.testing.expectError(2690 try std.testing.expectError(
2690 error.ParseZon,2691 error.ParseZon,
2691 fromSlice(Enum, .{2692 fromSlice(Enum, .{
2692 .gpa = gpa,2693 .gpa = gpa,
2693 .source = "true",2694 .source = "true",
2694 .diag = &diag,2695 .errors = &errors,
2695 }),2696 }),
2696 );2697 );
2697 try std.testing.expectFmt("1:1: error: expected enum literal\n", "{f}", .{diag});2698 try std.testing.expectFmt("1:1: error: expected enum literal\n", "{f}", .{errors});
2698 }2699 }
26992700
2700 // Test embedded nulls in an identifier2701 // Test embedded nulls in an identifier
2701 {2702 {
2702 var diag: Diagnostics = .init(arena);2703 var errors: Errors = .init(arena);
2703 try std.testing.expectError(2704 try std.testing.expectError(
2704 error.ParseZon,2705 error.ParseZon,
2705 fromSlice(Enum, .{2706 fromSlice(Enum, .{
2706 .gpa = gpa,2707 .gpa = gpa,
2707 .source = ".@\"\\x00\"",2708 .source = ".@\"\\x00\"",
2708 .diag = &diag,2709 .errors = &errors,
2709 }),2710 }),
2710 );2711 );
2711 try std.testing.expectFmt(2712 try std.testing.expectFmt(
2712 "1:2: error: identifier cannot contain null bytes\n",2713 "1:2: error: identifier cannot contain null bytes\n",
2713 "{f}",2714 "{f}",
2714 .{diag},2715 .{errors},
2715 );2716 );
2716 }2717 }
2717}2718}
...@@ -2726,23 +2727,23 @@ test "std.zon parse bool" {...@@ -2726,23 +2727,23 @@ test "std.zon parse bool" {
2726 try std.testing.expectEqual(true, try fromSlice(bool, .{2727 try std.testing.expectEqual(true, try fromSlice(bool, .{
2727 .gpa = gpa,2728 .gpa = gpa,
2728 .source = "true",2729 .source = "true",
2729 .diag = null,2730 .errors = null,
2730 }));2731 }));
2731 try std.testing.expectEqual(false, try fromSlice(bool, .{2732 try std.testing.expectEqual(false, try fromSlice(bool, .{
2732 .gpa = gpa,2733 .gpa = gpa,
2733 .source = "false",2734 .source = "false",
2734 .diag = null,2735 .errors = null,
2735 }));2736 }));
27362737
2737 // Errors2738 // Errors
2738 {2739 {
2739 var diag: Diagnostics = .init(arena);2740 var errors: Errors = .init(arena);
2740 try std.testing.expectError(2741 try std.testing.expectError(
2741 error.ParseZon,2742 error.ParseZon,
2742 fromSlice(bool, .{2743 fromSlice(bool, .{
2743 .gpa = gpa,2744 .gpa = gpa,
2744 .source = " foo",2745 .source = " foo",
2745 .diag = &diag,2746 .errors = &errors,
2746 }),2747 }),
2747 );2748 );
2748 try std.testing.expectFmt(2749 try std.testing.expectFmt(
...@@ -2750,16 +2751,16 @@ test "std.zon parse bool" {...@@ -2750,16 +2751,16 @@ test "std.zon parse bool" {
2750 \\1:2: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan'2751 \\1:2: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan'
2751 \\1:2: note: precede identifier with '.' for an enum literal2752 \\1:2: note: precede identifier with '.' for an enum literal
2752 \\2753 \\
2753 , "{f}", .{diag});2754 , "{f}", .{errors});
2754 }2755 }
2755 {2756 {
2756 var diag: Diagnostics = .init(arena);2757 var errors: Errors = .init(arena);
2757 try std.testing.expectError(error.ParseZon, fromSlice(bool, .{2758 try std.testing.expectError(error.ParseZon, fromSlice(bool, .{
2758 .gpa = gpa,2759 .gpa = gpa,
2759 .source = "123",2760 .source = "123",
2760 .diag = &diag,2761 .errors = &errors,
2761 }));2762 }));
2762 try std.testing.expectFmt("1:1: error: expected type 'bool'\n", "{f}", .{diag});2763 try std.testing.expectFmt("1:1: error: expected type 'bool'\n", "{f}", .{errors});
2763 }2764 }
2764}2765}
27652766
...@@ -2795,46 +2796,46 @@ test "std.zon parse int" {...@@ -2795,46 +2796,46 @@ test "std.zon parse int" {
2795 try std.testing.expectEqual(@as(u8, 10), try fromSlice(u8, .{2796 try std.testing.expectEqual(@as(u8, 10), try fromSlice(u8, .{
2796 .gpa = gpa,2797 .gpa = gpa,
2797 .source = "10",2798 .source = "10",
2798 .diag = null,2799 .errors = null,
2799 }));2800 }));
2800 try std.testing.expectEqual(@as(i16, 24), try fromSlice(i16, .{2801 try std.testing.expectEqual(@as(i16, 24), try fromSlice(i16, .{
2801 .gpa = gpa,2802 .gpa = gpa,
2802 .source = "24",2803 .source = "24",
2803 .diag = null,2804 .errors = null,
2804 }));2805 }));
2805 try std.testing.expectEqual(@as(i14, -4), try fromSlice(i14, .{2806 try std.testing.expectEqual(@as(i14, -4), try fromSlice(i14, .{
2806 .gpa = gpa,2807 .gpa = gpa,
2807 .source = "-4",2808 .source = "-4",
2808 .diag = null,2809 .errors = null,
2809 }));2810 }));
2810 try std.testing.expectEqual(@as(i32, -123), try fromSlice(i32, .{2811 try std.testing.expectEqual(@as(i32, -123), try fromSlice(i32, .{
2811 .gpa = gpa,2812 .gpa = gpa,
2812 .source = "-123",2813 .source = "-123",
2813 .diag = null,2814 .errors = null,
2814 }));2815 }));
28152816
2816 // Test limits2817 // Test limits
2817 try std.testing.expectEqual(@as(i8, 127), try fromSlice(i8, .{2818 try std.testing.expectEqual(@as(i8, 127), try fromSlice(i8, .{
2818 .gpa = gpa,2819 .gpa = gpa,
2819 .source = "127",2820 .source = "127",
2820 .diag = null,2821 .errors = null,
2821 }));2822 }));
2822 try std.testing.expectEqual(@as(i8, -128), try fromSlice(i8, .{2823 try std.testing.expectEqual(@as(i8, -128), try fromSlice(i8, .{
2823 .gpa = gpa,2824 .gpa = gpa,
2824 .source = "-128",2825 .source = "-128",
2825 .diag = null,2826 .errors = null,
2826 }));2827 }));
28272828
2828 // Test characters2829 // Test characters
2829 try std.testing.expectEqual(@as(u8, 'a'), try fromSlice(u8, .{2830 try std.testing.expectEqual(@as(u8, 'a'), try fromSlice(u8, .{
2830 .gpa = gpa,2831 .gpa = gpa,
2831 .source = "'a'",2832 .source = "'a'",
2832 .diag = null,2833 .errors = null,
2833 }));2834 }));
2834 try std.testing.expectEqual(@as(u8, 'z'), try fromSlice(u8, .{2835 try std.testing.expectEqual(@as(u8, 'z'), try fromSlice(u8, .{
2835 .gpa = gpa,2836 .gpa = gpa,
2836 .source = "'z'",2837 .source = "'z'",
2837 .diag = null,2838 .errors = null,
2838 }));2839 }));
28392840
2840 // Test big integers2841 // Test big integers
...@@ -2843,7 +2844,7 @@ test "std.zon parse int" {...@@ -2843,7 +2844,7 @@ test "std.zon parse int" {
2843 try fromSlice(u65, .{2844 try fromSlice(u65, .{
2844 .gpa = gpa,2845 .gpa = gpa,
2845 .source = "36893488147419103231",2846 .source = "36893488147419103231",
2846 .diag = null,2847 .errors = null,
2847 }),2848 }),
2848 );2849 );
2849 try std.testing.expectEqual(2850 try std.testing.expectEqual(
...@@ -2851,7 +2852,7 @@ test "std.zon parse int" {...@@ -2851,7 +2852,7 @@ test "std.zon parse int" {
2851 try fromSlice(u65, .{2852 try fromSlice(u65, .{
2852 .gpa = gpa,2853 .gpa = gpa,
2853 .source = "368934_881_474191032_31",2854 .source = "368934_881_474191032_31",
2854 .diag = null,2855 .errors = null,
2855 }),2856 }),
2856 );2857 );
2857 try std.testing.expectEqual(2858 try std.testing.expectEqual(
...@@ -2859,7 +2860,7 @@ test "std.zon parse int" {...@@ -2859,7 +2860,7 @@ test "std.zon parse int" {
2859 try fromSlice(u128, .{2860 try fromSlice(u128, .{
2860 .gpa = gpa,2861 .gpa = gpa,
2861 .source = "340282366920938463463374607431768211455",2862 .source = "340282366920938463463374607431768211455",
2862 .diag = null,2863 .errors = null,
2863 }),2864 }),
2864 );2865 );
28652866
...@@ -2869,7 +2870,7 @@ test "std.zon parse int" {...@@ -2869,7 +2870,7 @@ test "std.zon parse int" {
2869 try fromSlice(i66, .{2870 try fromSlice(i66, .{
2870 .gpa = gpa,2871 .gpa = gpa,
2871 .source = "36893488147419103231",2872 .source = "36893488147419103231",
2872 .diag = null,2873 .errors = null,
2873 }),2874 }),
2874 );2875 );
2875 try std.testing.expectEqual(2876 try std.testing.expectEqual(
...@@ -2877,33 +2878,33 @@ test "std.zon parse int" {...@@ -2877,33 +2878,33 @@ test "std.zon parse int" {
2877 try fromSlice(i66, .{2878 try fromSlice(i66, .{
2878 .gpa = gpa,2879 .gpa = gpa,
2879 .source = "-36893488147419103232",2880 .source = "-36893488147419103232",
2880 .diag = null,2881 .errors = null,
2881 }),2882 }),
2882 );2883 );
2883 {2884 {
2884 var diag: Diagnostics = .init(arena);2885 var errors: Errors = .init(arena);
2885 try std.testing.expectError(error.ParseZon, fromSlice(i66, .{2886 try std.testing.expectError(error.ParseZon, fromSlice(i66, .{
2886 .gpa = gpa,2887 .gpa = gpa,
2887 .source = "36893488147419103232",2888 .source = "36893488147419103232",
2888 .diag = &diag,2889 .errors = &errors,
2889 }));2890 }));
2890 try std.testing.expectFmt(2891 try std.testing.expectFmt(
2891 "1:1: error: type 'i66' cannot represent value\n",2892 "1:1: error: type 'i66' cannot represent value\n",
2892 "{f}",2893 "{f}",
2893 .{diag},2894 .{errors},
2894 );2895 );
2895 }2896 }
2896 {2897 {
2897 var diag: Diagnostics = .init(arena);2898 var errors: Errors = .init(arena);
2898 try std.testing.expectError(error.ParseZon, fromSlice(i66, .{2899 try std.testing.expectError(error.ParseZon, fromSlice(i66, .{
2899 .gpa = gpa,2900 .gpa = gpa,
2900 .source = "-36893488147419103233",2901 .source = "-36893488147419103233",
2901 .diag = &diag,2902 .errors = &errors,
2902 }));2903 }));
2903 try std.testing.expectFmt(2904 try std.testing.expectFmt(
2904 "1:1: error: type 'i66' cannot represent value\n",2905 "1:1: error: type 'i66' cannot represent value\n",
2905 "{f}",2906 "{f}",
2906 .{diag},2907 .{errors},
2907 );2908 );
2908 }2909 }
29092910
...@@ -2911,224 +2912,224 @@ test "std.zon parse int" {...@@ -2911,224 +2912,224 @@ test "std.zon parse int" {
2911 try std.testing.expectEqual(@as(i8, -1), try fromSlice(i8, .{2912 try std.testing.expectEqual(@as(i8, -1), try fromSlice(i8, .{
2912 .gpa = gpa,2913 .gpa = gpa,
2913 .source = "-1.0",2914 .source = "-1.0",
2914 .diag = null,2915 .errors = null,
2915 }));2916 }));
2916 try std.testing.expectEqual(@as(i8, 123), try fromSlice(i8, .{2917 try std.testing.expectEqual(@as(i8, 123), try fromSlice(i8, .{
2917 .gpa = gpa,2918 .gpa = gpa,
2918 .source = "123.0",2919 .source = "123.0",
2919 .diag = null,2920 .errors = null,
2920 }));2921 }));
29212922
2922 // Test non-decimal integers2923 // Test non-decimal integers
2923 try std.testing.expectEqual(@as(i16, 0xff), try fromSlice(i16, .{2924 try std.testing.expectEqual(@as(i16, 0xff), try fromSlice(i16, .{
2924 .gpa = gpa,2925 .gpa = gpa,
2925 .source = "0xff",2926 .source = "0xff",
2926 .diag = null,2927 .errors = null,
2927 }));2928 }));
2928 try std.testing.expectEqual(@as(i16, -0xff), try fromSlice(i16, .{2929 try std.testing.expectEqual(@as(i16, -0xff), try fromSlice(i16, .{
2929 .gpa = gpa,2930 .gpa = gpa,
2930 .source = "-0xff",2931 .source = "-0xff",
2931 .diag = null,2932 .errors = null,
2932 }));2933 }));
2933 try std.testing.expectEqual(@as(i16, 0o77), try fromSlice(i16, .{2934 try std.testing.expectEqual(@as(i16, 0o77), try fromSlice(i16, .{
2934 .gpa = gpa,2935 .gpa = gpa,
2935 .source = "0o77",2936 .source = "0o77",
2936 .diag = null,2937 .errors = null,
2937 }));2938 }));
2938 try std.testing.expectEqual(@as(i16, -0o77), try fromSlice(i16, .{2939 try std.testing.expectEqual(@as(i16, -0o77), try fromSlice(i16, .{
2939 .gpa = gpa,2940 .gpa = gpa,
2940 .source = "-0o77",2941 .source = "-0o77",
2941 .diag = null,2942 .errors = null,
2942 }));2943 }));
2943 try std.testing.expectEqual(@as(i16, 0b11), try fromSlice(i16, .{2944 try std.testing.expectEqual(@as(i16, 0b11), try fromSlice(i16, .{
2944 .gpa = gpa,2945 .gpa = gpa,
2945 .source = "0b11",2946 .source = "0b11",
2946 .diag = null,2947 .errors = null,
2947 }));2948 }));
2948 try std.testing.expectEqual(@as(i16, -0b11), try fromSlice(i16, .{2949 try std.testing.expectEqual(@as(i16, -0b11), try fromSlice(i16, .{
2949 .gpa = gpa,2950 .gpa = gpa,
2950 .source = "-0b11",2951 .source = "-0b11",
2951 .diag = null,2952 .errors = null,
2952 }));2953 }));
29532954
2954 // Test non-decimal big integers2955 // Test non-decimal big integers
2955 try std.testing.expectEqual(@as(u65, 0x1ffffffffffffffff), try fromSlice(u65, .{2956 try std.testing.expectEqual(@as(u65, 0x1ffffffffffffffff), try fromSlice(u65, .{
2956 .gpa = gpa,2957 .gpa = gpa,
2957 .source = "0x1ffffffffffffffff",2958 .source = "0x1ffffffffffffffff",
2958 .diag = null,2959 .errors = null,
2959 }));2960 }));
2960 try std.testing.expectEqual(@as(i66, 0x1ffffffffffffffff), try fromSlice(i66, .{2961 try std.testing.expectEqual(@as(i66, 0x1ffffffffffffffff), try fromSlice(i66, .{
2961 .gpa = gpa,2962 .gpa = gpa,
2962 .source = "0x1ffffffffffffffff",2963 .source = "0x1ffffffffffffffff",
2963 .diag = null,2964 .errors = null,
2964 }));2965 }));
2965 try std.testing.expectEqual(@as(i66, -0x1ffffffffffffffff), try fromSlice(i66, .{2966 try std.testing.expectEqual(@as(i66, -0x1ffffffffffffffff), try fromSlice(i66, .{
2966 .gpa = gpa,2967 .gpa = gpa,
2967 .source = "-0x1ffffffffffffffff",2968 .source = "-0x1ffffffffffffffff",
2968 .diag = null,2969 .errors = null,
2969 }));2970 }));
2970 try std.testing.expectEqual(@as(u65, 0x1ffffffffffffffff), try fromSlice(u65, .{2971 try std.testing.expectEqual(@as(u65, 0x1ffffffffffffffff), try fromSlice(u65, .{
2971 .gpa = gpa,2972 .gpa = gpa,
2972 .source = "0o3777777777777777777777",2973 .source = "0o3777777777777777777777",
2973 .diag = null,2974 .errors = null,
2974 }));2975 }));
2975 try std.testing.expectEqual(@as(i66, 0x1ffffffffffffffff), try fromSlice(i66, .{2976 try std.testing.expectEqual(@as(i66, 0x1ffffffffffffffff), try fromSlice(i66, .{
2976 .gpa = gpa,2977 .gpa = gpa,
2977 .source = "0o3777777777777777777777",2978 .source = "0o3777777777777777777777",
2978 .diag = null,2979 .errors = null,
2979 }));2980 }));
2980 try std.testing.expectEqual(@as(i66, -0x1ffffffffffffffff), try fromSlice(i66, .{2981 try std.testing.expectEqual(@as(i66, -0x1ffffffffffffffff), try fromSlice(i66, .{
2981 .gpa = gpa,2982 .gpa = gpa,
2982 .source = "-0o3777777777777777777777",2983 .source = "-0o3777777777777777777777",
2983 .diag = null,2984 .errors = null,
2984 }));2985 }));
2985 try std.testing.expectEqual(@as(u65, 0x1ffffffffffffffff), try fromSlice(u65, .{2986 try std.testing.expectEqual(@as(u65, 0x1ffffffffffffffff), try fromSlice(u65, .{
2986 .gpa = gpa,2987 .gpa = gpa,
2987 .source = "0b11111111111111111111111111111111111111111111111111111111111111111",2988 .source = "0b11111111111111111111111111111111111111111111111111111111111111111",
2988 .diag = null,2989 .errors = null,
2989 }));2990 }));
2990 try std.testing.expectEqual(@as(i66, 0x1ffffffffffffffff), try fromSlice(i66, .{2991 try std.testing.expectEqual(@as(i66, 0x1ffffffffffffffff), try fromSlice(i66, .{
2991 .gpa = gpa,2992 .gpa = gpa,
2992 .source = "0b11111111111111111111111111111111111111111111111111111111111111111",2993 .source = "0b11111111111111111111111111111111111111111111111111111111111111111",
2993 .diag = null,2994 .errors = null,
2994 }));2995 }));
2995 try std.testing.expectEqual(@as(i66, -0x1ffffffffffffffff), try fromSlice(i66, .{2996 try std.testing.expectEqual(@as(i66, -0x1ffffffffffffffff), try fromSlice(i66, .{
2996 .gpa = gpa,2997 .gpa = gpa,
2997 .source = "-0b11111111111111111111111111111111111111111111111111111111111111111",2998 .source = "-0b11111111111111111111111111111111111111111111111111111111111111111",
2998 .diag = null,2999 .errors = null,
2999 }));3000 }));
30003001
3001 // Number with invalid character in the middle3002 // Number with invalid character in the middle
3002 {3003 {
3003 var diag: Diagnostics = .init(arena);3004 var errors: Errors = .init(arena);
3004 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{3005 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
3005 .gpa = gpa,3006 .gpa = gpa,
3006 .source = "32a32",3007 .source = "32a32",
3007 .diag = &diag,3008 .errors = &errors,
3008 }));3009 }));
3009 try std.testing.expectFmt(3010 try std.testing.expectFmt(
3010 "1:3: error: invalid digit 'a' for decimal base\n",3011 "1:3: error: invalid digit 'a' for decimal base\n",
3011 "{f}",3012 "{f}",
3012 .{diag},3013 .{errors},
3013 );3014 );
3014 }3015 }
30153016
3016 // Failing to parse as int3017 // Failing to parse as int
3017 {3018 {
3018 var diag: Diagnostics = .init(arena);3019 var errors: Errors = .init(arena);
3019 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{3020 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
3020 .gpa = gpa,3021 .gpa = gpa,
3021 .source = "true",3022 .source = "true",
3022 .diag = &diag,3023 .errors = &errors,
3023 }));3024 }));
3024 try std.testing.expectFmt("1:1: error: expected type 'u8'\n", "{f}", .{diag});3025 try std.testing.expectFmt("1:1: error: expected type 'u8'\n", "{f}", .{errors});
3025 }3026 }
30263027
3027 // Failing because an int is out of range3028 // Failing because an int is out of range
3028 {3029 {
3029 var diag: Diagnostics = .init(arena);3030 var errors: Errors = .init(arena);
3030 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{3031 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
3031 .gpa = gpa,3032 .gpa = gpa,
3032 .source = "256",3033 .source = "256",
3033 .diag = &diag,3034 .errors = &errors,
3034 }));3035 }));
3035 try std.testing.expectFmt(3036 try std.testing.expectFmt(
3036 "1:1: error: type 'u8' cannot represent value\n",3037 "1:1: error: type 'u8' cannot represent value\n",
3037 "{f}",3038 "{f}",
3038 .{diag},3039 .{errors},
3039 );3040 );
3040 }3041 }
30413042
3042 // Failing because a negative int is out of range3043 // Failing because a negative int is out of range
3043 {3044 {
3044 var diag: Diagnostics = .init(arena);3045 var errors: Errors = .init(arena);
3045 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{3046 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{
3046 .gpa = gpa,3047 .gpa = gpa,
3047 .source = "-129",3048 .source = "-129",
3048 .diag = &diag,3049 .errors = &errors,
3049 }));3050 }));
3050 try std.testing.expectFmt(3051 try std.testing.expectFmt(
3051 "1:1: error: type 'i8' cannot represent value\n",3052 "1:1: error: type 'i8' cannot represent value\n",
3052 "{f}",3053 "{f}",
3053 .{diag},3054 .{errors},
3054 );3055 );
3055 }3056 }
30563057
3057 // Failing because an unsigned int is negative3058 // Failing because an unsigned int is negative
3058 {3059 {
3059 var diag: Diagnostics = .init(arena);3060 var errors: Errors = .init(arena);
3060 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{3061 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
3061 .gpa = gpa,3062 .gpa = gpa,
3062 .source = "-1",3063 .source = "-1",
3063 .diag = &diag,3064 .errors = &errors,
3064 }));3065 }));
3065 try std.testing.expectFmt(3066 try std.testing.expectFmt(
3066 "1:1: error: type 'u8' cannot represent value\n",3067 "1:1: error: type 'u8' cannot represent value\n",
3067 "{f}",3068 "{f}",
3068 .{diag},3069 .{errors},
3069 );3070 );
3070 }3071 }
30713072
3072 // Failing because a float is non-whole3073 // Failing because a float is non-whole
3073 {3074 {
3074 var diag: Diagnostics = .init(arena);3075 var errors: Errors = .init(arena);
3075 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{3076 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
3076 .gpa = gpa,3077 .gpa = gpa,
3077 .source = "1.5",3078 .source = "1.5",
3078 .diag = &diag,3079 .errors = &errors,
3079 }));3080 }));
3080 try std.testing.expectFmt(3081 try std.testing.expectFmt(
3081 "1:1: error: type 'u8' cannot represent value\n",3082 "1:1: error: type 'u8' cannot represent value\n",
3082 "{f}",3083 "{f}",
3083 .{diag},3084 .{errors},
3084 );3085 );
3085 }3086 }
30863087
3087 // Failing because a float is negative3088 // Failing because a float is negative
3088 {3089 {
3089 var diag: Diagnostics = .init(arena);3090 var errors: Errors = .init(arena);
3090 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{3091 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
3091 .gpa = gpa,3092 .gpa = gpa,
3092 .source = "-1.0",3093 .source = "-1.0",
3093 .diag = &diag,3094 .errors = &errors,
3094 }));3095 }));
3095 try std.testing.expectFmt(3096 try std.testing.expectFmt(
3096 "1:1: error: type 'u8' cannot represent value\n",3097 "1:1: error: type 'u8' cannot represent value\n",
3097 "{f}",3098 "{f}",
3098 .{diag},3099 .{errors},
3099 );3100 );
3100 }3101 }
31013102
3102 // Negative integer zero3103 // Negative integer zero
3103 {3104 {
3104 var diag: Diagnostics = .init(arena);3105 var errors: Errors = .init(arena);
3105 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{3106 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{
3106 .gpa = gpa,3107 .gpa = gpa,
3107 .source = "-0",3108 .source = "-0",
3108 .diag = &diag,3109 .errors = &errors,
3109 }));3110 }));
3110 try std.testing.expectFmt(3111 try std.testing.expectFmt(
3111 \\1:2: error: integer literal '-0' is ambiguous3112 \\1:2: error: integer literal '-0' is ambiguous
3112 \\1:2: note: use '0' for an integer zero3113 \\1:2: note: use '0' for an integer zero
3113 \\1:2: note: use '-0.0' for a floating-point signed zero3114 \\1:2: note: use '-0.0' for a floating-point signed zero
3114 \\3115 \\
3115 , "{f}", .{diag});3116 , "{f}", .{errors});
3116 }3117 }
31173118
3118 // Negative integer zero casted to float3119 // Negative integer zero casted to float
3119 {3120 {
3120 var diag: Diagnostics = .init(arena);3121 var errors: Errors = .init(arena);
3121 try std.testing.expectError(error.ParseZon, fromSlice(f32, .{3122 try std.testing.expectError(error.ParseZon, fromSlice(f32, .{
3122 .gpa = gpa,3123 .gpa = gpa,
3123 .source = "-0",3124 .source = "-0",
3124 .diag = &diag,3125 .errors = &errors,
3125 }));3126 }));
3126 try std.testing.expectFmt(3127 try std.testing.expectFmt(
3127 \\1:2: error: integer literal '-0' is ambiguous3128 \\1:2: error: integer literal '-0' is ambiguous
3128 \\1:2: note: use '0' for an integer zero3129 \\1:2: note: use '0' for an integer zero
3129 \\1:2: note: use '-0.0' for a floating-point signed zero3130 \\1:2: note: use '-0.0' for a floating-point signed zero
3130 \\3131 \\
3131 , "{f}", .{diag});3132 , "{f}", .{errors});
3132 }3133 }
31333134
3134 // Negative float 0 is allowed3135 // Negative float 0 is allowed
...@@ -3136,71 +3137,71 @@ test "std.zon parse int" {...@@ -3136,71 +3137,71 @@ test "std.zon parse int" {
3136 std.math.isNegativeZero(try fromSlice(f32, .{3137 std.math.isNegativeZero(try fromSlice(f32, .{
3137 .gpa = gpa,3138 .gpa = gpa,
3138 .source = "-0.0",3139 .source = "-0.0",
3139 .diag = null,3140 .errors = null,
3140 })),3141 })),
3141 );3142 );
3142 try std.testing.expect(std.math.isPositiveZero(try fromSlice(f32, .{3143 try std.testing.expect(std.math.isPositiveZero(try fromSlice(f32, .{
3143 .gpa = gpa,3144 .gpa = gpa,
3144 .source = "0.0",3145 .source = "0.0",
3145 .diag = null,3146 .errors = null,
3146 })));3147 })));
31473148
3148 // Double negation is not allowed3149 // Double negation is not allowed
3149 {3150 {
3150 var diag: Diagnostics = .init(arena);3151 var errors: Errors = .init(arena);
3151 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{3152 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{
3152 .gpa = gpa,3153 .gpa = gpa,
3153 .source = "--2",3154 .source = "--2",
3154 .diag = &diag,3155 .errors = &errors,
3155 }));3156 }));
3156 try std.testing.expectFmt(3157 try std.testing.expectFmt(
3157 "1:1: error: expected number or 'inf' after '-'\n",3158 "1:1: error: expected number or 'inf' after '-'\n",
3158 "{f}",3159 "{f}",
3159 .{diag},3160 .{errors},
3160 );3161 );
3161 }3162 }
31623163
3163 {3164 {
3164 var diag: Diagnostics = .init(arena);3165 var errors: Errors = .init(arena);
3165 try std.testing.expectError(3166 try std.testing.expectError(
3166 error.ParseZon,3167 error.ParseZon,
3167 fromSlice(f32, .{3168 fromSlice(f32, .{
3168 .gpa = gpa,3169 .gpa = gpa,
3169 .source = "--2.0",3170 .source = "--2.0",
3170 .diag = &diag,3171 .errors = &errors,
3171 }),3172 }),
3172 );3173 );
3173 try std.testing.expectFmt(3174 try std.testing.expectFmt(
3174 "1:1: error: expected number or 'inf' after '-'\n",3175 "1:1: error: expected number or 'inf' after '-'\n",
3175 "{f}",3176 "{f}",
3176 .{diag},3177 .{errors},
3177 );3178 );
3178 }3179 }
31793180
3180 // Invalid int literal3181 // Invalid int literal
3181 {3182 {
3182 var diag: Diagnostics = .init(arena);3183 var errors: Errors = .init(arena);
3183 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{3184 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
3184 .gpa = gpa,3185 .gpa = gpa,
3185 .source = "0xg",3186 .source = "0xg",
3186 .diag = &diag,3187 .errors = &errors,
3187 }));3188 }));
3188 try std.testing.expectFmt("1:3: error: invalid digit 'g' for hex base\n", "{f}", .{diag});3189 try std.testing.expectFmt("1:3: error: invalid digit 'g' for hex base\n", "{f}", .{errors});
3189 }3190 }
31903191
3191 // Notes on invalid int literal3192 // Notes on invalid int literal
3192 {3193 {
3193 var diag: Diagnostics = .init(arena);3194 var errors: Errors = .init(arena);
3194 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{3195 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
3195 .gpa = gpa,3196 .gpa = gpa,
3196 .source = "0123",3197 .source = "0123",
3197 .diag = &diag,3198 .errors = &errors,
3198 }));3199 }));
3199 try std.testing.expectFmt(3200 try std.testing.expectFmt(
3200 \\1:1: error: number '0123' has leading zero3201 \\1:1: error: number '0123' has leading zero
3201 \\1:1: note: use '0o' prefix for octal literals3202 \\1:1: note: use '0o' prefix for octal literals
3202 \\3203 \\
3203 , "{f}", .{diag});3204 , "{f}", .{errors});
3204 }3205 }
3205}3206}
32063207
...@@ -3211,29 +3212,29 @@ test "std.zon negative char" {...@@ -3211,29 +3212,29 @@ test "std.zon negative char" {
3211 const arena = arena_allocator.allocator();3212 const arena = arena_allocator.allocator();
32123213
3213 {3214 {
3214 var diag: Diagnostics = .init(arena);3215 var errors: Errors = .init(arena);
3215 try std.testing.expectError(error.ParseZon, fromSlice(f32, .{3216 try std.testing.expectError(error.ParseZon, fromSlice(f32, .{
3216 .gpa = gpa,3217 .gpa = gpa,
3217 .source = "-'a'",3218 .source = "-'a'",
3218 .diag = &diag,3219 .errors = &errors,
3219 }));3220 }));
3220 try std.testing.expectFmt(3221 try std.testing.expectFmt(
3221 "1:1: error: expected number or 'inf' after '-'\n",3222 "1:1: error: expected number or 'inf' after '-'\n",
3222 "{f}",3223 "{f}",
3223 .{diag},3224 .{errors},
3224 );3225 );
3225 }3226 }
3226 {3227 {
3227 var diag: Diagnostics = .init(arena);3228 var errors: Errors = .init(arena);
3228 try std.testing.expectError(error.ParseZon, fromSlice(i16, .{3229 try std.testing.expectError(error.ParseZon, fromSlice(i16, .{
3229 .gpa = gpa,3230 .gpa = gpa,
3230 .source = "-'a'",3231 .source = "-'a'",
3231 .diag = &diag,3232 .errors = &errors,
3232 }));3233 }));
3233 try std.testing.expectFmt(3234 try std.testing.expectFmt(
3234 "1:1: error: expected number or 'inf' after '-'\n",3235 "1:1: error: expected number or 'inf' after '-'\n",
3235 "{f}",3236 "{f}",
3236 .{diag},3237 .{errors},
3237 );3238 );
3238 }3239 }
3239}3240}
...@@ -3248,14 +3249,14 @@ test "std.zon parse float" {...@@ -3248,14 +3249,14 @@ test "std.zon parse float" {
3248 try std.testing.expectEqual(@as(f16, 0.5), try fromSlice(f16, .{3249 try std.testing.expectEqual(@as(f16, 0.5), try fromSlice(f16, .{
3249 .gpa = gpa,3250 .gpa = gpa,
3250 .source = "0.5",3251 .source = "0.5",
3251 .diag = null,3252 .errors = null,
3252 }));3253 }));
3253 try std.testing.expectEqual(3254 try std.testing.expectEqual(
3254 @as(f32, 123.456),3255 @as(f32, 123.456),
3255 try fromSlice(f32, .{3256 try fromSlice(f32, .{
3256 .gpa = gpa,3257 .gpa = gpa,
3257 .source = "123.456",3258 .source = "123.456",
3258 .diag = null,3259 .errors = null,
3259 }),3260 }),
3260 );3261 );
3261 try std.testing.expectEqual(3262 try std.testing.expectEqual(
...@@ -3263,47 +3264,47 @@ test "std.zon parse float" {...@@ -3263,47 +3264,47 @@ test "std.zon parse float" {
3263 try fromSlice(f64, .{3264 try fromSlice(f64, .{
3264 .gpa = gpa,3265 .gpa = gpa,
3265 .source = "-123.456",3266 .source = "-123.456",
3266 .diag = null,3267 .errors = null,
3267 }),3268 }),
3268 );3269 );
3269 try std.testing.expectEqual(@as(f128, 42.5), try fromSlice(f128, .{3270 try std.testing.expectEqual(@as(f128, 42.5), try fromSlice(f128, .{
3270 .gpa = gpa,3271 .gpa = gpa,
3271 .source = "42.5",3272 .source = "42.5",
3272 .diag = null,3273 .errors = null,
3273 }));3274 }));
32743275
3275 // Test whole numbers with and without decimals3276 // Test whole numbers with and without decimals
3276 try std.testing.expectEqual(@as(f16, 5.0), try fromSlice(f16, .{3277 try std.testing.expectEqual(@as(f16, 5.0), try fromSlice(f16, .{
3277 .gpa = gpa,3278 .gpa = gpa,
3278 .source = "5.0",3279 .source = "5.0",
3279 .diag = null,3280 .errors = null,
3280 }));3281 }));
3281 try std.testing.expectEqual(@as(f16, 5.0), try fromSlice(f16, .{3282 try std.testing.expectEqual(@as(f16, 5.0), try fromSlice(f16, .{
3282 .gpa = gpa,3283 .gpa = gpa,
3283 .source = "5",3284 .source = "5",
3284 .diag = null,3285 .errors = null,
3285 }));3286 }));
3286 try std.testing.expectEqual(@as(f32, -102), try fromSlice(f32, .{3287 try std.testing.expectEqual(@as(f32, -102), try fromSlice(f32, .{
3287 .gpa = gpa,3288 .gpa = gpa,
3288 .source = "-102.0",3289 .source = "-102.0",
3289 .diag = null,3290 .errors = null,
3290 }));3291 }));
3291 try std.testing.expectEqual(@as(f32, -102), try fromSlice(f32, .{3292 try std.testing.expectEqual(@as(f32, -102), try fromSlice(f32, .{
3292 .gpa = gpa,3293 .gpa = gpa,
3293 .source = "-102",3294 .source = "-102",
3294 .diag = null,3295 .errors = null,
3295 }));3296 }));
32963297
3297 // Test characters and negated characters3298 // Test characters and negated characters
3298 try std.testing.expectEqual(@as(f32, 'a'), try fromSlice(f32, .{3299 try std.testing.expectEqual(@as(f32, 'a'), try fromSlice(f32, .{
3299 .gpa = gpa,3300 .gpa = gpa,
3300 .source = "'a'",3301 .source = "'a'",
3301 .diag = null,3302 .errors = null,
3302 }));3303 }));
3303 try std.testing.expectEqual(@as(f32, 'z'), try fromSlice(f32, .{3304 try std.testing.expectEqual(@as(f32, 'z'), try fromSlice(f32, .{
3304 .gpa = gpa,3305 .gpa = gpa,
3305 .source = "'z'",3306 .source = "'z'",
3306 .diag = null,3307 .errors = null,
3307 }));3308 }));
33083309
3309 // Test big integers3310 // Test big integers
...@@ -3312,7 +3313,7 @@ test "std.zon parse float" {...@@ -3312,7 +3313,7 @@ test "std.zon parse float" {
3312 try fromSlice(f32, .{3313 try fromSlice(f32, .{
3313 .gpa = gpa,3314 .gpa = gpa,
3314 .source = "36893488147419103231",3315 .source = "36893488147419103231",
3315 .diag = null,3316 .errors = null,
3316 }),3317 }),
3317 );3318 );
3318 try std.testing.expectEqual(3319 try std.testing.expectEqual(
...@@ -3320,18 +3321,18 @@ test "std.zon parse float" {...@@ -3320,18 +3321,18 @@ test "std.zon parse float" {
3320 try fromSlice(f32, .{3321 try fromSlice(f32, .{
3321 .gpa = gpa,3322 .gpa = gpa,
3322 .source = "-36893488147419103231",3323 .source = "-36893488147419103231",
3323 .diag = null,3324 .errors = null,
3324 }),3325 }),
3325 );3326 );
3326 try std.testing.expectEqual(@as(f128, 0x1ffffffffffffffff), try fromSlice(f128, .{3327 try std.testing.expectEqual(@as(f128, 0x1ffffffffffffffff), try fromSlice(f128, .{
3327 .gpa = gpa,3328 .gpa = gpa,
3328 .source = "0x1ffffffffffffffff",3329 .source = "0x1ffffffffffffffff",
3329 .diag = null,3330 .errors = null,
3330 }));3331 }));
3331 try std.testing.expectEqual(@as(f32, @floatFromInt(0x1ffffffffffffffff)), try fromSlice(f32, .{3332 try std.testing.expectEqual(@as(f32, @floatFromInt(0x1ffffffffffffffff)), try fromSlice(f32, .{
3332 .gpa = gpa,3333 .gpa = gpa,
3333 .source = "0x1ffffffffffffffff",3334 .source = "0x1ffffffffffffffff",
3334 .diag = null,3335 .errors = null,
3335 }));3336 }));
33363337
3337 // Exponents, underscores3338 // Exponents, underscores
...@@ -3340,7 +3341,7 @@ test "std.zon parse float" {...@@ -3340,7 +3341,7 @@ test "std.zon parse float" {
3340 try fromSlice(f32, .{3341 try fromSlice(f32, .{
3341 .gpa = gpa,3342 .gpa = gpa,
3342 .source = "12_3.0E+77",3343 .source = "12_3.0E+77",
3343 .diag = null,3344 .errors = null,
3344 }),3345 }),
3345 );3346 );
33463347
...@@ -3350,7 +3351,7 @@ test "std.zon parse float" {...@@ -3350,7 +3351,7 @@ test "std.zon parse float" {
3350 try fromSlice(f32, .{3351 try fromSlice(f32, .{
3351 .gpa = gpa,3352 .gpa = gpa,
3352 .source = "0x103.70p-5",3353 .source = "0x103.70p-5",
3353 .diag = null,3354 .errors = null,
3354 }),3355 }),
3355 );3356 );
3356 try std.testing.expectEqual(3357 try std.testing.expectEqual(
...@@ -3358,7 +3359,7 @@ test "std.zon parse float" {...@@ -3358,7 +3359,7 @@ test "std.zon parse float" {
3358 try fromSlice(f32, .{3359 try fromSlice(f32, .{
3359 .gpa = gpa,3360 .gpa = gpa,
3360 .source = "-0x103.70",3361 .source = "-0x103.70",
3361 .diag = null,3362 .errors = null,
3362 }),3363 }),
3363 );3364 );
3364 try std.testing.expectEqual(3365 try std.testing.expectEqual(
...@@ -3366,7 +3367,7 @@ test "std.zon parse float" {...@@ -3366,7 +3367,7 @@ test "std.zon parse float" {
3366 try fromSlice(f32, .{3367 try fromSlice(f32, .{
3367 .gpa = gpa,3368 .gpa = gpa,
3368 .source = "0x1234_5678.9ABC_CDEFp-10",3369 .source = "0x1234_5678.9ABC_CDEFp-10",
3369 .diag = null,3370 .errors = null,
3370 }),3371 }),
3371 );3372 );
33723373
...@@ -3374,120 +3375,120 @@ test "std.zon parse float" {...@@ -3374,120 +3375,120 @@ test "std.zon parse float" {
3374 try std.testing.expect(std.math.isPositiveInf(try fromSlice(f32, .{3375 try std.testing.expect(std.math.isPositiveInf(try fromSlice(f32, .{
3375 .gpa = gpa,3376 .gpa = gpa,
3376 .source = "inf",3377 .source = "inf",
3377 .diag = null,3378 .errors = null,
3378 })));3379 })));
3379 try std.testing.expect(std.math.isNegativeInf(try fromSlice(f32, .{3380 try std.testing.expect(std.math.isNegativeInf(try fromSlice(f32, .{
3380 .gpa = gpa,3381 .gpa = gpa,
3381 .source = "-inf",3382 .source = "-inf",
3382 .diag = null,3383 .errors = null,
3383 })));3384 })));
3384 try std.testing.expect(std.math.isNan(try fromSlice(f32, .{3385 try std.testing.expect(std.math.isNan(try fromSlice(f32, .{
3385 .gpa = gpa,3386 .gpa = gpa,
3386 .source = "nan",3387 .source = "nan",
3387 .diag = null,3388 .errors = null,
3388 })));3389 })));
33893390
3390 // Negative nan not allowed3391 // Negative nan not allowed
3391 {3392 {
3392 var diag: Diagnostics = .init(arena);3393 var errors: Errors = .init(arena);
3393 try std.testing.expectError(error.ParseZon, fromSlice(f32, .{3394 try std.testing.expectError(error.ParseZon, fromSlice(f32, .{
3394 .gpa = gpa,3395 .gpa = gpa,
3395 .source = "-nan",3396 .source = "-nan",
3396 .diag = &diag,3397 .errors = &errors,
3397 }));3398 }));
3398 try std.testing.expectFmt(3399 try std.testing.expectFmt(
3399 "1:1: error: expected number or 'inf' after '-'\n",3400 "1:1: error: expected number or 'inf' after '-'\n",
3400 "{f}",3401 "{f}",
3401 .{diag},3402 .{errors},
3402 );3403 );
3403 }3404 }
34043405
3405 // nan as int not allowed3406 // nan as int not allowed
3406 {3407 {
3407 var diag: Diagnostics = .init(arena);3408 var errors: Errors = .init(arena);
3408 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{3409 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{
3409 .gpa = gpa,3410 .gpa = gpa,
3410 .source = "nan",3411 .source = "nan",
3411 .diag = &diag,3412 .errors = &errors,
3412 }));3413 }));
3413 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{diag});3414 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{errors});
3414 }3415 }
34153416
3416 // nan as int not allowed3417 // nan as int not allowed
3417 {3418 {
3418 var diag: Diagnostics = .init(arena);3419 var errors: Errors = .init(arena);
3419 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{3420 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{
3420 .gpa = gpa,3421 .gpa = gpa,
3421 .source = "nan",3422 .source = "nan",
3422 .diag = &diag,3423 .errors = &errors,
3423 }));3424 }));
3424 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{diag});3425 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{errors});
3425 }3426 }
34263427
3427 // inf as int not allowed3428 // inf as int not allowed
3428 {3429 {
3429 var diag: Diagnostics = .init(arena);3430 var errors: Errors = .init(arena);
3430 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{3431 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{
3431 .gpa = gpa,3432 .gpa = gpa,
3432 .source = "inf",3433 .source = "inf",
3433 .diag = &diag,3434 .errors = &errors,
3434 }));3435 }));
3435 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{diag});3436 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{errors});
3436 }3437 }
34373438
3438 // -inf as int not allowed3439 // -inf as int not allowed
3439 {3440 {
3440 var diag: Diagnostics = .init(arena);3441 var errors: Errors = .init(arena);
3441 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{3442 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{
3442 .gpa = gpa,3443 .gpa = gpa,
3443 .source = "-inf",3444 .source = "-inf",
3444 .diag = &diag,3445 .errors = &errors,
3445 }));3446 }));
3446 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{diag});3447 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{errors});
3447 }3448 }
34483449
3449 // Bad identifier as float3450 // Bad identifier as float
3450 {3451 {
3451 var diag: Diagnostics = .init(arena);3452 var errors: Errors = .init(arena);
3452 try std.testing.expectError(error.ParseZon, fromSlice(f32, .{3453 try std.testing.expectError(error.ParseZon, fromSlice(f32, .{
3453 .gpa = gpa,3454 .gpa = gpa,
3454 .source = "foo",3455 .source = "foo",
3455 .diag = &diag,3456 .errors = &errors,
3456 }));3457 }));
3457 try std.testing.expectFmt(3458 try std.testing.expectFmt(
3458 \\1:1: error: invalid expression3459 \\1:1: error: invalid expression
3459 \\1:1: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan'3460 \\1:1: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan'
3460 \\1:1: note: precede identifier with '.' for an enum literal3461 \\1:1: note: precede identifier with '.' for an enum literal
3461 \\3462 \\
3462 , "{f}", .{diag});3463 , "{f}", .{errors});
3463 }3464 }
34643465
3465 {3466 {
3466 var diag: Diagnostics = .init(arena);3467 var errors: Errors = .init(arena);
3467 try std.testing.expectError(error.ParseZon, fromSlice(f32, .{3468 try std.testing.expectError(error.ParseZon, fromSlice(f32, .{
3468 .gpa = gpa,3469 .gpa = gpa,
3469 .source = "-foo",3470 .source = "-foo",
3470 .diag = &diag,3471 .errors = &errors,
3471 }));3472 }));
3472 try std.testing.expectFmt(3473 try std.testing.expectFmt(
3473 "1:1: error: expected number or 'inf' after '-'\n",3474 "1:1: error: expected number or 'inf' after '-'\n",
3474 "{f}",3475 "{f}",
3475 .{diag},3476 .{errors},
3476 );3477 );
3477 }3478 }
34783479
3479 // Non float as float3480 // Non float as float
3480 {3481 {
3481 var diag: Diagnostics = .init(arena);3482 var errors: Errors = .init(arena);
3482 try std.testing.expectError(3483 try std.testing.expectError(
3483 error.ParseZon,3484 error.ParseZon,
3484 fromSlice(f32, .{3485 fromSlice(f32, .{
3485 .gpa = gpa,3486 .gpa = gpa,
3486 .source = "\"foo\"",3487 .source = "\"foo\"",
3487 .diag = &diag,3488 .errors = &errors,
3488 }),3489 }),
3489 );3490 );
3490 try std.testing.expectFmt("1:1: error: expected type 'f32'\n", "{f}", .{diag});3491 try std.testing.expectFmt("1:1: error: expected type 'f32'\n", "{f}", .{errors});
3491 }3492 }
3492}3493}
34933494
...@@ -3514,7 +3515,7 @@ test "std.zon free on error" {...@@ -3514,7 +3515,7 @@ test "std.zon free on error" {
3514 \\ .z = "fail",3515 \\ .z = "fail",
3515 \\}3516 \\}
3516 ,3517 ,
3517 .diag = null,3518 .errors = null,
3518 }));3519 }));
3519 }3520 }
35203521
...@@ -3535,7 +3536,7 @@ test "std.zon free on error" {...@@ -3535,7 +3536,7 @@ test "std.zon free on error" {
3535 \\ "fail",3536 \\ "fail",
3536 \\}3537 \\}
3537 ,3538 ,
3538 .diag = null,3539 .errors = null,
3539 }));3540 }));
3540 }3541 }
35413542
...@@ -3552,7 +3553,7 @@ test "std.zon free on error" {...@@ -3552,7 +3553,7 @@ test "std.zon free on error" {
3552 \\ .x = "hello",3553 \\ .x = "hello",
3553 \\}3554 \\}
3554 ,3555 ,
3555 .diag = null,3556 .errors = null,
3556 }));3557 }));
35573558
3558 // Test freeing partially allocated arrays3559 // Test freeing partially allocated arrays
...@@ -3566,7 +3567,7 @@ test "std.zon free on error" {...@@ -3566,7 +3567,7 @@ test "std.zon free on error" {
3566 \\ false,3567 \\ false,
3567 \\}3568 \\}
3568 ,3569 ,
3569 .diag = null,3570 .errors = null,
3570 }));3571 }));
35713572
3572 // Test freeing partially allocated slices3573 // Test freeing partially allocated slices
...@@ -3580,7 +3581,7 @@ test "std.zon free on error" {...@@ -3580,7 +3581,7 @@ test "std.zon free on error" {
3580 \\ false,3581 \\ false,
3581 \\}3582 \\}
3582 ,3583 ,
3583 .diag = null,3584 .errors = null,
3584 }));3585 }));
35853586
3586 // We can parse types that can't be freed, as long as they contain no allocations, e.g. untagged3587 // We can parse types that can't be freed, as long as they contain no allocations, e.g. untagged
...@@ -3590,7 +3591,7 @@ test "std.zon free on error" {...@@ -3590,7 +3591,7 @@ test "std.zon free on error" {
3590 (try fromSlice(union { x: f32 }, .{3591 (try fromSlice(union { x: f32 }, .{
3591 .gpa = gpa,3592 .gpa = gpa,
3592 .source = ".{ .x = 1.5 }",3593 .source = ".{ .x = 1.5 }",
3593 .diag = null,3594 .errors = null,
3594 })).x,3595 })).x,
3595 );3596 );
35963597
...@@ -3601,7 +3602,7 @@ test "std.zon free on error" {...@@ -3601,7 +3602,7 @@ test "std.zon free on error" {
3601 .gpa = gpa,3602 .gpa = gpa,
3602 .arena = arena,3603 .arena = arena,
3603 .source = ".{ .x = \"foo\" }",3604 .source = ".{ .x = \"foo\" }",
3604 .diag = null,3605 .errors = null,
3605 });3606 });
3606 try std.testing.expectEqualStrings("foo", result.x);3607 try std.testing.expectEqualStrings("foo", result.x);
3607 }3608 }
...@@ -3622,7 +3623,7 @@ test "std.zon vector" {...@@ -3622,7 +3623,7 @@ test "std.zon vector" {
3622 try fromSlice(@Vector(0, bool), .{3623 try fromSlice(@Vector(0, bool), .{
3623 .gpa = gpa,3624 .gpa = gpa,
3624 .source = ".{}",3625 .source = ".{}",
3625 .diag = null,3626 .errors = null,
3626 }),3627 }),
3627 );3628 );
3628 try std.testing.expectEqual(3629 try std.testing.expectEqual(
...@@ -3630,7 +3631,7 @@ test "std.zon vector" {...@@ -3630,7 +3631,7 @@ test "std.zon vector" {
3630 try fromSlice(@Vector(3, bool), .{3631 try fromSlice(@Vector(3, bool), .{
3631 .gpa = gpa,3632 .gpa = gpa,
3632 .source = ".{true, false, true}",3633 .source = ".{true, false, true}",
3633 .diag = null,3634 .errors = null,
3634 }),3635 }),
3635 );3636 );
36363637
...@@ -3639,7 +3640,7 @@ test "std.zon vector" {...@@ -3639,7 +3640,7 @@ test "std.zon vector" {
3639 try fromSlice(@Vector(0, f32), .{3640 try fromSlice(@Vector(0, f32), .{
3640 .gpa = gpa,3641 .gpa = gpa,
3641 .source = ".{}",3642 .source = ".{}",
3642 .diag = null,3643 .errors = null,
3643 }),3644 }),
3644 );3645 );
3645 try std.testing.expectEqual(3646 try std.testing.expectEqual(
...@@ -3647,7 +3648,7 @@ test "std.zon vector" {...@@ -3647,7 +3648,7 @@ test "std.zon vector" {
3647 try fromSlice(@Vector(3, f32), .{3648 try fromSlice(@Vector(3, f32), .{
3648 .gpa = gpa,3649 .gpa = gpa,
3649 .source = ".{1.5, 2.5, 3.5}",3650 .source = ".{1.5, 2.5, 3.5}",
3650 .diag = null,3651 .errors = null,
3651 }),3652 }),
3652 );3653 );
36533654
...@@ -3656,7 +3657,7 @@ test "std.zon vector" {...@@ -3656,7 +3657,7 @@ test "std.zon vector" {
3656 try fromSlice(@Vector(0, u8), .{3657 try fromSlice(@Vector(0, u8), .{
3657 .gpa = gpa,3658 .gpa = gpa,
3658 .source = ".{}",3659 .source = ".{}",
3659 .diag = null,3660 .errors = null,
3660 }),3661 }),
3661 );3662 );
3662 try std.testing.expectEqual(3663 try std.testing.expectEqual(
...@@ -3664,7 +3665,7 @@ test "std.zon vector" {...@@ -3664,7 +3665,7 @@ test "std.zon vector" {
3664 try fromSlice(@Vector(3, u8), .{3665 try fromSlice(@Vector(3, u8), .{
3665 .gpa = gpa,3666 .gpa = gpa,
3666 .source = ".{2, 4, 6}",3667 .source = ".{2, 4, 6}",
3667 .diag = null,3668 .errors = null,
3668 }),3669 }),
3669 );3670 );
36703671
...@@ -3675,14 +3676,14 @@ test "std.zon vector" {...@@ -3675,14 +3676,14 @@ test "std.zon vector" {
3675 .gpa = gpa,3676 .gpa = gpa,
3676 .arena = arena,3677 .arena = arena,
3677 .source = ".{}",3678 .source = ".{}",
3678 .diag = null,3679 .errors = null,
3679 }),3680 }),
3680 );3681 );
3681 const pointers = try fromSliceAlloc(@Vector(3, *const u8), .{3682 const pointers = try fromSliceAlloc(@Vector(3, *const u8), .{
3682 .gpa = gpa,3683 .gpa = gpa,
3683 .arena = arena,3684 .arena = arena,
3684 .source = ".{2, 4, 6}",3685 .source = ".{2, 4, 6}",
3685 .diag = null,3686 .errors = null,
3686 });3687 });
3687 try std.testing.expectEqualDeep(@Vector(3, *const u8){ &2, &4, &6 }, pointers);3688 try std.testing.expectEqualDeep(@Vector(3, *const u8){ &2, &4, &6 }, pointers);
3688 }3689 }
...@@ -3694,99 +3695,99 @@ test "std.zon vector" {...@@ -3694,99 +3695,99 @@ test "std.zon vector" {
3694 .gpa = gpa,3695 .gpa = gpa,
3695 .arena = arena,3696 .arena = arena,
3696 .source = ".{}",3697 .source = ".{}",
3697 .diag = null,3698 .errors = null,
3698 }),3699 }),
3699 );3700 );
3700 const pointers = try fromSliceAlloc(@Vector(3, ?*const u8), .{3701 const pointers = try fromSliceAlloc(@Vector(3, ?*const u8), .{
3701 .gpa = gpa,3702 .gpa = gpa,
3702 .arena = arena,3703 .arena = arena,
3703 .source = ".{2, null, 6}",3704 .source = ".{2, null, 6}",
3704 .diag = null,3705 .errors = null,
3705 });3706 });
3706 try std.testing.expectEqualDeep(@Vector(3, ?*const u8){ &2, null, &6 }, pointers);3707 try std.testing.expectEqualDeep(@Vector(3, ?*const u8){ &2, null, &6 }, pointers);
3707 }3708 }
37083709
3709 // Too few fields3710 // Too few fields
3710 {3711 {
3711 var diag: Diagnostics = .init(arena);3712 var errors: Errors = .init(arena);
3712 try std.testing.expectError(3713 try std.testing.expectError(
3713 error.ParseZon,3714 error.ParseZon,
3714 fromSlice(@Vector(2, f32), .{3715 fromSlice(@Vector(2, f32), .{
3715 .gpa = gpa,3716 .gpa = gpa,
3716 .source = ".{0.5}",3717 .source = ".{0.5}",
3717 .diag = &diag,3718 .errors = &errors,
3718 }),3719 }),
3719 );3720 );
3720 try std.testing.expectFmt(3721 try std.testing.expectFmt(
3721 "1:2: error: expected 2 array elements; found 1\n",3722 "1:2: error: expected 2 array elements; found 1\n",
3722 "{f}",3723 "{f}",
3723 .{diag},3724 .{errors},
3724 );3725 );
3725 }3726 }
37263727
3727 // Too many fields3728 // Too many fields
3728 {3729 {
3729 var diag: Diagnostics = .init(arena);3730 var errors: Errors = .init(arena);
3730 try std.testing.expectError(3731 try std.testing.expectError(
3731 error.ParseZon,3732 error.ParseZon,
3732 fromSlice(@Vector(2, f32), .{3733 fromSlice(@Vector(2, f32), .{
3733 .gpa = gpa,3734 .gpa = gpa,
3734 .source = ".{0.5, 1.5, 2.5}",3735 .source = ".{0.5, 1.5, 2.5}",
3735 .diag = &diag,3736 .errors = &errors,
3736 }),3737 }),
3737 );3738 );
3738 try std.testing.expectFmt(3739 try std.testing.expectFmt(
3739 "1:13: error: index 2 outside of array of length 2\n",3740 "1:13: error: index 2 outside of array of length 2\n",
3740 "{f}",3741 "{f}",
3741 .{diag},3742 .{errors},
3742 );3743 );
3743 }3744 }
37443745
3745 // Wrong type fields3746 // Wrong type fields
3746 {3747 {
3747 var diag: Diagnostics = .init(arena);3748 var errors: Errors = .init(arena);
3748 try std.testing.expectError(3749 try std.testing.expectError(
3749 error.ParseZon,3750 error.ParseZon,
3750 fromSlice(@Vector(3, f32), .{3751 fromSlice(@Vector(3, f32), .{
3751 .gpa = gpa,3752 .gpa = gpa,
3752 .source = ".{0.5, true, 2.5}",3753 .source = ".{0.5, true, 2.5}",
3753 .diag = &diag,3754 .errors = &errors,
3754 }),3755 }),
3755 );3756 );
3756 try std.testing.expectFmt(3757 try std.testing.expectFmt(
3757 "1:8: error: expected type 'f32'\n",3758 "1:8: error: expected type 'f32'\n",
3758 "{f}",3759 "{f}",
3759 .{diag},3760 .{errors},
3760 );3761 );
3761 }3762 }
37623763
3763 // Wrong type3764 // Wrong type
3764 {3765 {
3765 var diag: Diagnostics = .init(arena);3766 var errors: Errors = .init(arena);
3766 try std.testing.expectError(3767 try std.testing.expectError(
3767 error.ParseZon,3768 error.ParseZon,
3768 fromSlice(@Vector(3, u8), .{3769 fromSlice(@Vector(3, u8), .{
3769 .gpa = gpa,3770 .gpa = gpa,
3770 .source = "true",3771 .source = "true",
3771 .diag = &diag,3772 .errors = &errors,
3772 }),3773 }),
3773 );3774 );
3774 try std.testing.expectFmt("1:1: error: expected type '@Vector(3, u8)'\n", "{f}", .{diag});3775 try std.testing.expectFmt("1:1: error: expected type '@Vector(3, u8)'\n", "{f}", .{errors});
3775 }3776 }
37763777
3777 // Elements should get freed on error3778 // Elements should get freed on error
3778 {3779 {
3779 var diag: Diagnostics = .init(arena);3780 var errors: Errors = .init(arena);
3780 try std.testing.expectError(3781 try std.testing.expectError(
3781 error.ParseZon,3782 error.ParseZon,
3782 fromSliceAlloc(@Vector(3, *u8), .{3783 fromSliceAlloc(@Vector(3, *u8), .{
3783 .gpa = gpa,3784 .gpa = gpa,
3784 .arena = arena,3785 .arena = arena,
3785 .source = ".{1, true, 3}",3786 .source = ".{1, true, 3}",
3786 .diag = &diag,3787 .errors = &errors,
3787 }),3788 }),
3788 );3789 );
3789 try std.testing.expectFmt("1:6: error: expected type 'u8'\n", "{f}", .{diag});3790 try std.testing.expectFmt("1:6: error: expected type 'u8'\n", "{f}", .{errors});
3790 }3791 }
3791}3792}
37923793
...@@ -3802,7 +3803,7 @@ test "std.zon add pointers" {...@@ -3802,7 +3803,7 @@ test "std.zon add pointers" {
3802 .gpa = gpa,3803 .gpa = gpa,
3803 .arena = arena,3804 .arena = arena,
3804 .source = "10",3805 .source = "10",
3805 .diag = null,3806 .errors = null,
3806 });3807 });
3807 try std.testing.expectEqual(@as(u32, 10), result.*);3808 try std.testing.expectEqual(@as(u32, 10), result.*);
3808 }3809 }
...@@ -3812,7 +3813,7 @@ test "std.zon add pointers" {...@@ -3812,7 +3813,7 @@ test "std.zon add pointers" {
3812 .gpa = gpa,3813 .gpa = gpa,
3813 .arena = arena,3814 .arena = arena,
3814 .source = "10",3815 .source = "10",
3815 .diag = null,3816 .errors = null,
3816 });3817 });
3817 try std.testing.expectEqual(@as(u32, 10), result.*.*);3818 try std.testing.expectEqual(@as(u32, 10), result.*.*);
3818 }3819 }
...@@ -3822,7 +3823,7 @@ test "std.zon add pointers" {...@@ -3822,7 +3823,7 @@ test "std.zon add pointers" {
3822 .gpa = gpa,3823 .gpa = gpa,
3823 .arena = arena,3824 .arena = arena,
3824 .source = "10",3825 .source = "10",
3825 .diag = null,3826 .errors = null,
3826 });3827 });
3827 try std.testing.expectEqual(@as(u32, 10), result.*.*.*);3828 try std.testing.expectEqual(@as(u32, 10), result.*.*.*);
3828 }3829 }
...@@ -3833,7 +3834,7 @@ test "std.zon add pointers" {...@@ -3833,7 +3834,7 @@ test "std.zon add pointers" {
3833 .gpa = gpa,3834 .gpa = gpa,
3834 .arena = arena,3835 .arena = arena,
3835 .source = "10",3836 .source = "10",
3836 .diag = null,3837 .errors = null,
3837 });3838 });
3838 try std.testing.expectEqual(@as(u32, 10), some.?.*);3839 try std.testing.expectEqual(@as(u32, 10), some.?.*);
38393840
...@@ -3841,7 +3842,7 @@ test "std.zon add pointers" {...@@ -3841,7 +3842,7 @@ test "std.zon add pointers" {
3841 .gpa = gpa,3842 .gpa = gpa,
3842 .arena = arena,3843 .arena = arena,
3843 .source = "null",3844 .source = "null",
3844 .diag = null,3845 .errors = null,
3845 });3846 });
3846 try std.testing.expectEqual(null, none);3847 try std.testing.expectEqual(null, none);
3847 }3848 }
...@@ -3851,7 +3852,7 @@ test "std.zon add pointers" {...@@ -3851,7 +3852,7 @@ test "std.zon add pointers" {
3851 .gpa = gpa,3852 .gpa = gpa,
3852 .arena = arena,3853 .arena = arena,
3853 .source = "10",3854 .source = "10",
3854 .diag = null,3855 .errors = null,
3855 });3856 });
3856 try std.testing.expectEqual(@as(u32, 10), some.*.?);3857 try std.testing.expectEqual(@as(u32, 10), some.*.?);
38573858
...@@ -3859,7 +3860,7 @@ test "std.zon add pointers" {...@@ -3859,7 +3860,7 @@ test "std.zon add pointers" {
3859 .gpa = gpa,3860 .gpa = gpa,
3860 .arena = arena,3861 .arena = arena,
3861 .source = "null",3862 .source = "null",
3862 .diag = null,3863 .errors = null,
3863 });3864 });
3864 try std.testing.expectEqual(null, none.*);3865 try std.testing.expectEqual(null, none.*);
3865 }3866 }
...@@ -3869,7 +3870,7 @@ test "std.zon add pointers" {...@@ -3869,7 +3870,7 @@ test "std.zon add pointers" {
3869 .gpa = gpa,3870 .gpa = gpa,
3870 .arena = arena,3871 .arena = arena,
3871 .source = "10",3872 .source = "10",
3872 .diag = null,3873 .errors = null,
3873 });3874 });
3874 try std.testing.expectEqual(@as(u32, 10), some.?.*.*);3875 try std.testing.expectEqual(@as(u32, 10), some.?.*.*);
38753876
...@@ -3877,7 +3878,7 @@ test "std.zon add pointers" {...@@ -3877,7 +3878,7 @@ test "std.zon add pointers" {
3877 .gpa = gpa,3878 .gpa = gpa,
3878 .arena = arena,3879 .arena = arena,
3879 .source = "null",3880 .source = "null",
3880 .diag = null,3881 .errors = null,
3881 });3882 });
3882 try std.testing.expectEqual(null, none);3883 try std.testing.expectEqual(null, none);
3883 }3884 }
...@@ -3887,7 +3888,7 @@ test "std.zon add pointers" {...@@ -3887,7 +3888,7 @@ test "std.zon add pointers" {
3887 .gpa = gpa,3888 .gpa = gpa,
3888 .arena = arena,3889 .arena = arena,
3889 .source = "10",3890 .source = "10",
3890 .diag = null,3891 .errors = null,
3891 });3892 });
3892 try std.testing.expectEqual(@as(u32, 10), some.*.?.*);3893 try std.testing.expectEqual(@as(u32, 10), some.*.?.*);
38933894
...@@ -3895,7 +3896,7 @@ test "std.zon add pointers" {...@@ -3895,7 +3896,7 @@ test "std.zon add pointers" {
3895 .gpa = gpa,3896 .gpa = gpa,
3896 .arena = arena,3897 .arena = arena,
3897 .source = "null",3898 .source = "null",
3898 .diag = null,3899 .errors = null,
3899 });3900 });
3900 try std.testing.expectEqual(null, none.*);3901 try std.testing.expectEqual(null, none.*);
3901 }3902 }
...@@ -3905,7 +3906,7 @@ test "std.zon add pointers" {...@@ -3905,7 +3906,7 @@ test "std.zon add pointers" {
3905 .gpa = gpa,3906 .gpa = gpa,
3906 .arena = arena,3907 .arena = arena,
3907 .source = "10",3908 .source = "10",
3908 .diag = null,3909 .errors = null,
3909 });3910 });
3910 try std.testing.expectEqual(@as(u32, 10), some.*.*.?);3911 try std.testing.expectEqual(@as(u32, 10), some.*.*.?);
39113912
...@@ -3913,7 +3914,7 @@ test "std.zon add pointers" {...@@ -3913,7 +3914,7 @@ test "std.zon add pointers" {
3913 .gpa = gpa,3914 .gpa = gpa,
3914 .arena = arena,3915 .arena = arena,
3915 .source = "null",3916 .source = "null",
3916 .diag = null,3917 .errors = null,
3917 });3918 });
3918 try std.testing.expectEqual(null, none.*.*);3919 try std.testing.expectEqual(null, none.*.*);
3919 }3920 }
...@@ -3924,7 +3925,7 @@ test "std.zon add pointers" {...@@ -3924,7 +3925,7 @@ test "std.zon add pointers" {
3924 .gpa = gpa,3925 .gpa = gpa,
3925 .arena = arena,3926 .arena = arena,
3926 .source = ".{ 1, 2, 3 }",3927 .source = ".{ 1, 2, 3 }",
3927 .diag = null,3928 .errors = null,
3928 });3929 });
3929 try std.testing.expectEqual([3]u8{ 1, 2, 3 }, result.*);3930 try std.testing.expectEqual([3]u8{ 1, 2, 3 }, result.*);
3930 }3931 }
...@@ -3959,7 +3960,7 @@ test "std.zon add pointers" {...@@ -3959,7 +3960,7 @@ test "std.zon add pointers" {
3959 \\ .f2 = null,3960 \\ .f2 = null,
3960 \\}3961 \\}
3961 ,3962 ,
3962 .diag = null,3963 .errors = null,
3963 });3964 });
39643965
3965 try std.testing.expectEqualDeep(expected, found.?.*);3966 try std.testing.expectEqualDeep(expected, found.?.*);
...@@ -3967,185 +3968,185 @@ test "std.zon add pointers" {...@@ -3967,185 +3968,185 @@ test "std.zon add pointers" {
39673968
3968 // Test that optional types are flattened correctly in errors3969 // Test that optional types are flattened correctly in errors
3969 {3970 {
3970 var diag: Diagnostics = .init(arena);3971 var errors: Errors = .init(arena);
3971 try std.testing.expectError(3972 try std.testing.expectError(
3972 error.ParseZon,3973 error.ParseZon,
3973 fromSliceAlloc(*const ?*const u8, .{3974 fromSliceAlloc(*const ?*const u8, .{
3974 .gpa = gpa,3975 .gpa = gpa,
3975 .arena = arena,3976 .arena = arena,
3976 .source = "true",3977 .source = "true",
3977 .diag = &diag,3978 .errors = &errors,
3978 }),3979 }),
3979 );3980 );
3980 try std.testing.expectFmt("1:1: error: expected type '?u8'\n", "{f}", .{diag});3981 try std.testing.expectFmt("1:1: error: expected type '?u8'\n", "{f}", .{errors});
3981 }3982 }
39823983
3983 {3984 {
3984 var diag: Diagnostics = .init(arena);3985 var errors: Errors = .init(arena);
3985 try std.testing.expectError(3986 try std.testing.expectError(
3986 error.ParseZon,3987 error.ParseZon,
3987 fromSliceAlloc(*const ?*const f32, .{3988 fromSliceAlloc(*const ?*const f32, .{
3988 .gpa = gpa,3989 .gpa = gpa,
3989 .arena = arena,3990 .arena = arena,
3990 .source = "true",3991 .source = "true",
3991 .diag = &diag,3992 .errors = &errors,
3992 }),3993 }),
3993 );3994 );
3994 try std.testing.expectFmt("1:1: error: expected type '?f32'\n", "{f}", .{diag});3995 try std.testing.expectFmt("1:1: error: expected type '?f32'\n", "{f}", .{errors});
3995 }3996 }
39963997
3997 {3998 {
3998 var diag: Diagnostics = .init(arena);3999 var errors: Errors = .init(arena);
3999 try std.testing.expectError(4000 try std.testing.expectError(
4000 error.ParseZon,4001 error.ParseZon,
4001 fromSliceAlloc(*const ?*const @Vector(3, u8), .{4002 fromSliceAlloc(*const ?*const @Vector(3, u8), .{
4002 .gpa = gpa,4003 .gpa = gpa,
4003 .arena = arena,4004 .arena = arena,
4004 .source = "true",4005 .source = "true",
4005 .diag = &diag,4006 .errors = &errors,
4006 }),4007 }),
4007 );4008 );
4008 try std.testing.expectFmt("1:1: error: expected type '?@Vector(3, u8)'\n", "{f}", .{diag});4009 try std.testing.expectFmt("1:1: error: expected type '?@Vector(3, u8)'\n", "{f}", .{errors});
4009 }4010 }
40104011
4011 {4012 {
4012 var diag: Diagnostics = .init(arena);4013 var errors: Errors = .init(arena);
4013 try std.testing.expectError(4014 try std.testing.expectError(
4014 error.ParseZon,4015 error.ParseZon,
4015 fromSliceAlloc(*const ?*const bool, .{4016 fromSliceAlloc(*const ?*const bool, .{
4016 .gpa = gpa,4017 .gpa = gpa,
4017 .arena = arena,4018 .arena = arena,
4018 .source = "10",4019 .source = "10",
4019 .diag = &diag,4020 .errors = &errors,
4020 }),4021 }),
4021 );4022 );
4022 try std.testing.expectFmt("1:1: error: expected type '?bool'\n", "{f}", .{diag});4023 try std.testing.expectFmt("1:1: error: expected type '?bool'\n", "{f}", .{errors});
4023 }4024 }
40244025
4025 {4026 {
4026 var diag: Diagnostics = .init(arena);4027 var errors: Errors = .init(arena);
4027 try std.testing.expectError(4028 try std.testing.expectError(
4028 error.ParseZon,4029 error.ParseZon,
4029 fromSliceAlloc(*const ?*const struct { a: i32 }, .{4030 fromSliceAlloc(*const ?*const struct { a: i32 }, .{
4030 .gpa = gpa,4031 .gpa = gpa,
4031 .arena = arena,4032 .arena = arena,
4032 .source = "true",4033 .source = "true",
4033 .diag = &diag,4034 .errors = &errors,
4034 }),4035 }),
4035 );4036 );
4036 try std.testing.expectFmt("1:1: error: expected optional struct\n", "{f}", .{diag});4037 try std.testing.expectFmt("1:1: error: expected optional struct\n", "{f}", .{errors});
4037 }4038 }
40384039
4039 {4040 {
4040 var diag: Diagnostics = .init(arena);4041 var errors: Errors = .init(arena);
4041 try std.testing.expectError(4042 try std.testing.expectError(
4042 error.ParseZon,4043 error.ParseZon,
4043 fromSliceAlloc(*const ?*const struct { i32 }, .{4044 fromSliceAlloc(*const ?*const struct { i32 }, .{
4044 .gpa = gpa,4045 .gpa = gpa,
4045 .arena = arena,4046 .arena = arena,
4046 .source = "true",4047 .source = "true",
4047 .diag = &diag,4048 .errors = &errors,
4048 }),4049 }),
4049 );4050 );
4050 try std.testing.expectFmt("1:1: error: expected optional tuple\n", "{f}", .{diag});4051 try std.testing.expectFmt("1:1: error: expected optional tuple\n", "{f}", .{errors});
4051 }4052 }
40524053
4053 {4054 {
4054 var diag: Diagnostics = .init(arena);4055 var errors: Errors = .init(arena);
4055 try std.testing.expectError(4056 try std.testing.expectError(
4056 error.ParseZon,4057 error.ParseZon,
4057 fromSliceAlloc(*const ?*const union { x: void }, .{4058 fromSliceAlloc(*const ?*const union { x: void }, .{
4058 .gpa = gpa,4059 .gpa = gpa,
4059 .arena = arena,4060 .arena = arena,
4060 .source = "true",4061 .source = "true",
4061 .diag = &diag,4062 .errors = &errors,
4062 }),4063 }),
4063 );4064 );
4064 try std.testing.expectFmt("1:1: error: expected optional union\n", "{f}", .{diag});4065 try std.testing.expectFmt("1:1: error: expected optional union\n", "{f}", .{errors});
4065 }4066 }
40664067
4067 {4068 {
4068 var diag: Diagnostics = .init(arena);4069 var errors: Errors = .init(arena);
4069 try std.testing.expectError(4070 try std.testing.expectError(
4070 error.ParseZon,4071 error.ParseZon,
4071 fromSliceAlloc(*const ?*const [3]u8, .{4072 fromSliceAlloc(*const ?*const [3]u8, .{
4072 .gpa = gpa,4073 .gpa = gpa,
4073 .arena = arena,4074 .arena = arena,
4074 .source = "true",4075 .source = "true",
4075 .diag = &diag,4076 .errors = &errors,
4076 }),4077 }),
4077 );4078 );
4078 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{diag});4079 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{errors});
4079 }4080 }
40804081
4081 {4082 {
4082 var diag: Diagnostics = .init(arena);4083 var errors: Errors = .init(arena);
4083 try std.testing.expectError(4084 try std.testing.expectError(
4084 error.ParseZon,4085 error.ParseZon,
4085 fromSliceAlloc(?[3]u8, .{4086 fromSliceAlloc(?[3]u8, .{
4086 .gpa = gpa,4087 .gpa = gpa,
4087 .arena = arena,4088 .arena = arena,
4088 .source = "true",4089 .source = "true",
4089 .diag = &diag,4090 .errors = &errors,
4090 }),4091 }),
4091 );4092 );
4092 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{diag});4093 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{errors});
4093 }4094 }
40944095
4095 {4096 {
4096 var diag: Diagnostics = .init(arena);4097 var errors: Errors = .init(arena);
4097 try std.testing.expectError(4098 try std.testing.expectError(
4098 error.ParseZon,4099 error.ParseZon,
4099 fromSliceAlloc(*const ?*const []u8, .{4100 fromSliceAlloc(*const ?*const []u8, .{
4100 .gpa = gpa,4101 .gpa = gpa,
4101 .arena = arena,4102 .arena = arena,
4102 .source = "true",4103 .source = "true",
4103 .diag = &diag,4104 .errors = &errors,
4104 }),4105 }),
4105 );4106 );
4106 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{diag});4107 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{errors});
4107 }4108 }
41084109
4109 {4110 {
4110 var diag: Diagnostics = .init(arena);4111 var errors: Errors = .init(arena);
4111 try std.testing.expectError(4112 try std.testing.expectError(
4112 error.ParseZon,4113 error.ParseZon,
4113 fromSliceAlloc(?[]u8, .{4114 fromSliceAlloc(?[]u8, .{
4114 .gpa = gpa,4115 .gpa = gpa,
4115 .arena = arena,4116 .arena = arena,
4116 .source = "true",4117 .source = "true",
4117 .diag = &diag,4118 .errors = &errors,
4118 }),4119 }),
4119 );4120 );
4120 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{diag});4121 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{errors});
4121 }4122 }
41224123
4123 {4124 {
4124 var diag: Diagnostics = .init(arena);4125 var errors: Errors = .init(arena);
4125 try std.testing.expectError(4126 try std.testing.expectError(
4126 error.ParseZon,4127 error.ParseZon,
4127 fromSliceAlloc(*const ?*const []const u8, .{4128 fromSliceAlloc(*const ?*const []const u8, .{
4128 .gpa = gpa,4129 .gpa = gpa,
4129 .arena = arena,4130 .arena = arena,
4130 .source = "true",4131 .source = "true",
4131 .diag = &diag,4132 .errors = &errors,
4132 }),4133 }),
4133 );4134 );
4134 try std.testing.expectFmt("1:1: error: expected optional string\n", "{f}", .{diag});4135 try std.testing.expectFmt("1:1: error: expected optional string\n", "{f}", .{errors});
4135 }4136 }
41364137
4137 {4138 {
4138 var diag: Diagnostics = .init(arena);4139 var errors: Errors = .init(arena);
4139 try std.testing.expectError(4140 try std.testing.expectError(
4140 error.ParseZon,4141 error.ParseZon,
4141 fromSliceAlloc(*const ?*const enum { foo }, .{4142 fromSliceAlloc(*const ?*const enum { foo }, .{
4142 .gpa = gpa,4143 .gpa = gpa,
4143 .arena = arena,4144 .arena = arena,
4144 .source = "true",4145 .source = "true",
4145 .diag = &diag,4146 .errors = &errors,
4146 }),4147 }),
4147 );4148 );
4148 try std.testing.expectFmt("1:1: error: expected optional enum literal\n", "{f}", .{diag});4149 try std.testing.expectFmt("1:1: error: expected optional enum literal\n", "{f}", .{errors});
4149 }4150 }
4150}4151}
41514152
...@@ -4167,7 +4168,7 @@ test "std.zon stop on node" {...@@ -4167,7 +4168,7 @@ test "std.zon stop on node" {
4167 const result = try fromZoir(Vec2, .{4168 const result = try fromZoir(Vec2, .{
4168 .ast = &ast,4169 .ast = &ast,
4169 .zoir = &zoir,4170 .zoir = &zoir,
4170 .diag = null,4171 .errors = null,
4171 });4172 });
41724173
4173 try std.testing.expectEqual(result.y, 2.5);4174 try std.testing.expectEqual(result.y, 2.5);
...@@ -4184,7 +4185,7 @@ test "std.zon stop on node" {...@@ -4184,7 +4185,7 @@ test "std.zon stop on node" {
4184 const result = try fromZoir(Zoir.Node.Index, .{4185 const result = try fromZoir(Zoir.Node.Index, .{
4185 .ast = &ast,4186 .ast = &ast,
4186 .zoir = &zoir,4187 .zoir = &zoir,
4187 .diag = null,4188 .errors = null,
4188 });4189 });
4189 try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.23 }, result.get(&zoir));4190 try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.23 }, result.get(&zoir));
4190 }4191 }
...@@ -4198,7 +4199,7 @@ test "std.zon no alloc" {...@@ -4198,7 +4199,7 @@ test "std.zon no alloc" {
4198 try fromSlice([3]u8, .{4199 try fromSlice([3]u8, .{
4199 .gpa = gpa,4200 .gpa = gpa,
4200 .source = ".{ 1, 2, 3 }",4201 .source = ".{ 1, 2, 3 }",
4201 .diag = null,4202 .errors = null,
4202 }),4203 }),
4203 );4204 );
42044205
...@@ -4215,12 +4216,12 @@ test "std.zon no alloc" {...@@ -4215,12 +4216,12 @@ test "std.zon no alloc" {
4215 try fromZoir(Nested, .{4216 try fromZoir(Nested, .{
4216 .ast = &ast,4217 .ast = &ast,
4217 .zoir = &zoir,4218 .zoir = &zoir,
4218 .diag = null,4219 .errors = null,
4219 }),4220 }),
4220 );4221 );
4221}4222}
42224223
4223test "std.zon errors without diagnostics" {4224test "std.zon errors without errorsnostics" {
4224 const gpa = std.testing.allocator;4225 const gpa = std.testing.allocator;
4225 var arena_allocator: ArenaAllocator = .init(gpa);4226 var arena_allocator: ArenaAllocator = .init(gpa);
4226 defer arena_allocator.deinit();4227 defer arena_allocator.deinit();
...@@ -4235,7 +4236,7 @@ test "std.zon errors without diagnostics" {...@@ -4235,7 +4236,7 @@ test "std.zon errors without diagnostics" {
4235 .gpa = gpa,4236 .gpa = gpa,
4236 .arena = arena,4237 .arena = arena,
4237 .source = ".nothing",4238 .source = ".nothing",
4238 .diag = null,4239 .errors = null,
4239 }));4240 }));
42404241
4241 const Struct = struct {4242 const Struct = struct {
...@@ -4245,7 +4246,7 @@ test "std.zon errors without diagnostics" {...@@ -4245,7 +4246,7 @@ test "std.zon errors without diagnostics" {
4245 .gpa = gpa,4246 .gpa = gpa,
4246 .arena = arena,4247 .arena = arena,
4247 .source = ".{ .name = \"Alice\", .age = 25 }",4248 .source = ".{ .name = \"Alice\", .age = 25 }",
4248 .diag = null,4249 .errors = null,
4249 }));4250 }));
42504251
4251 const Union = union(enum) {4252 const Union = union(enum) {
...@@ -4256,13 +4257,13 @@ test "std.zon errors without diagnostics" {...@@ -4256,13 +4257,13 @@ test "std.zon errors without diagnostics" {
4256 .gpa = gpa,4257 .gpa = gpa,
4257 .arena = arena,4258 .arena = arena,
4258 .source = ".a",4259 .source = ".a",
4259 .diag = null,4260 .errors = null,
4260 }));4261 }));
4261 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, .{4262 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, .{
4262 .gpa = gpa,4263 .gpa = gpa,
4263 .arena = arena,4264 .arena = arena,
4264 .source = ".{ .b = 8 }",4265 .source = ".{ .b = 8 }",
4265 .diag = null,4266 .errors = null,
4266 }));4267 }));
4267}4268}
42684269
...@@ -4284,7 +4285,7 @@ test "std.zon aligned pointers" {...@@ -4284,7 +4285,7 @@ test "std.zon aligned pointers" {
4284 .gpa = gpa,4285 .gpa = gpa,
4285 .arena = arena,4286 .arena = arena,
4286 .source = ".{ .inner = 10 }",4287 .source = ".{ .inner = 10 }",
4287 .diag = null,4288 .errors = null,
4288 });4289 });
4289 try std.testing.expectEqualDeep(expected.inner, found.inner);4290 try std.testing.expectEqualDeep(expected.inner, found.inner);
4290}4291}
...@@ -4329,7 +4330,7 @@ test "std.zon update basic" {...@@ -4329,7 +4330,7 @@ test "std.zon update basic" {
4329 .gpa = gpa,4330 .gpa = gpa,
4330 .arena = arena,4331 .arena = arena,
4331 .source = ".{}",4332 .source = ".{}",
4332 .diag = null,4333 .errors = null,
4333 });4334 });
4334 try std.testing.expectEqualDeep(expected, found);4335 try std.testing.expectEqualDeep(expected, found);
43354336
...@@ -4337,7 +4338,7 @@ test "std.zon update basic" {...@@ -4337,7 +4338,7 @@ test "std.zon update basic" {
4337 .gpa = gpa,4338 .gpa = gpa,
4338 .arena = arena,4339 .arena = arena,
4339 .source = ".{ .bar = false }",4340 .source = ".{ .bar = false }",
4340 .diag = null,4341 .errors = null,
4341 });4342 });
4342 expected.bar = false;4343 expected.bar = false;
4343 try std.testing.expectEqualDeep(expected, found);4344 try std.testing.expectEqualDeep(expected, found);
...@@ -4346,7 +4347,7 @@ test "std.zon update basic" {...@@ -4346,7 +4347,7 @@ test "std.zon update basic" {
4346 .gpa = gpa,4347 .gpa = gpa,
4347 .arena = arena,4348 .arena = arena,
4348 .source = ".{ .baz = .{ .a = .{ 2, 4 } } }",4349 .source = ".{ .baz = .{ .a = .{ 2, 4 } } }",
4349 .diag = null,4350 .errors = null,
4350 });4351 });
4351 expected.baz.a[0] = 2;4352 expected.baz.a[0] = 2;
4352 expected.baz.a[1] = 4;4353 expected.baz.a[1] = 4;
...@@ -4356,7 +4357,7 @@ test "std.zon update basic" {...@@ -4356,7 +4357,7 @@ test "std.zon update basic" {
4356 .gpa = gpa,4357 .gpa = gpa,
4357 .arena = arena,4358 .arena = arena,
4358 .source = ".{ .foo = 11, .baz = .{ .b = .d } }",4359 .source = ".{ .foo = 11, .baz = .{ .b = .d } }",
4359 .diag = null,4360 .errors = null,
4360 });4361 });
4361 expected.foo = 11;4362 expected.foo = 11;
4362 expected.baz.b = .d;4363 expected.baz.b = .d;
...@@ -4366,7 +4367,7 @@ test "std.zon update basic" {...@@ -4366,7 +4367,7 @@ test "std.zon update basic" {
4366 .gpa = gpa,4367 .gpa = gpa,
4367 .arena = arena,4368 .arena = arena,
4368 .source = ".{ .optional = 10 }",4369 .source = ".{ .optional = 10 }",
4369 .diag = null,4370 .errors = null,
4370 });4371 });
4371 expected.optional = 10;4372 expected.optional = 10;
4372 try std.testing.expectEqualDeep(expected, found);4373 try std.testing.expectEqualDeep(expected, found);
...@@ -4375,7 +4376,7 @@ test "std.zon update basic" {...@@ -4375,7 +4376,7 @@ test "std.zon update basic" {
4375 .gpa = gpa,4376 .gpa = gpa,
4376 .arena = arena,4377 .arena = arena,
4377 .source = ".{ .optional = null }",4378 .source = ".{ .optional = null }",
4378 .diag = null,4379 .errors = null,
4379 });4380 });
4380 expected.optional = null;4381 expected.optional = null;
4381 try std.testing.expectEqualDeep(expected, found);4382 try std.testing.expectEqualDeep(expected, found);
...@@ -4384,7 +4385,7 @@ test "std.zon update basic" {...@@ -4384,7 +4385,7 @@ test "std.zon update basic" {
4384 .gpa = gpa,4385 .gpa = gpa,
4385 .arena = arena,4386 .arena = arena,
4386 .source = ".{ .ptr = .{ .x = 10, .y = 20, .z = 30 } }",4387 .source = ".{ .ptr = .{ .x = 10, .y = 20, .z = 30 } }",
4387 .diag = null,4388 .errors = null,
4388 });4389 });
4389 expected.ptr.x = 10;4390 expected.ptr.x = 10;
4390 expected.ptr.y = 20;4391 expected.ptr.y = 20;
...@@ -4395,7 +4396,7 @@ test "std.zon update basic" {...@@ -4395,7 +4396,7 @@ test "std.zon update basic" {
4395 .gpa = gpa,4396 .gpa = gpa,
4396 .arena = arena,4397 .arena = arena,
4397 .source = ".{ .str = \"foo\" }",4398 .source = ".{ .str = \"foo\" }",
4398 .diag = null,4399 .errors = null,
4399 });4400 });
4400 expected.str = "foo";4401 expected.str = "foo";
4401 try std.testing.expectEqualDeep(expected, found);4402 try std.testing.expectEqualDeep(expected, found);
...@@ -4418,7 +4419,7 @@ test "std.zon update optionals" {...@@ -4418,7 +4419,7 @@ test "std.zon update optionals" {
4418 try updateFromSlice(MyStruct, &found, .{4419 try updateFromSlice(MyStruct, &found, .{
4419 .gpa = gpa,4420 .gpa = gpa,
4420 .source = ".{ .foo = .{ .qux = 3 } }",4421 .source = ".{ .foo = .{ .qux = 3 } }",
4421 .diag = null,4422 .errors = null,
4422 });4423 });
4423 expected.foo = .{ .qux = 3 };4424 expected.foo = .{ .qux = 3 };
4424 try std.testing.expectEqual(expected, found);4425 try std.testing.expectEqual(expected, found);
...@@ -4427,13 +4428,13 @@ test "std.zon update optionals" {...@@ -4427,13 +4428,13 @@ test "std.zon update optionals" {
4427 // Updating an optional that starts out null should error if we leave off required fields.4428 // Updating an optional that starts out null should error if we leave off required fields.
4428 {4429 {
4429 var found: MyStruct = .{ .foo = null };4430 var found: MyStruct = .{ .foo = null };
4430 var diag: Diagnostics = .init(arena);4431 var errors: Errors = .init(arena);
4431 try std.testing.expectError(error.ParseZon, updateFromSlice(MyStruct, &found, .{4432 try std.testing.expectError(error.ParseZon, updateFromSlice(MyStruct, &found, .{
4432 .gpa = gpa,4433 .gpa = gpa,
4433 .source = ".{ .foo = .{} }",4434 .source = ".{ .foo = .{} }",
4434 .diag = &diag,4435 .errors = &errors,
4435 }));4436 }));
4436 try std.testing.expectFmt("1:12: error: missing required field qux\n", "{f}", .{diag});4437 try std.testing.expectFmt("1:12: error: missing required field qux\n", "{f}", .{errors});
4437 }4438 }
44384439
4439 // Updating an optional that starts out non-null should preserve any values we leave off. It's4440 // Updating an optional that starts out non-null should preserve any values we leave off. It's
...@@ -4446,7 +4447,7 @@ test "std.zon update optionals" {...@@ -4446,7 +4447,7 @@ test "std.zon update optionals" {
4446 try updateFromSlice(MyStruct, &found, .{4447 try updateFromSlice(MyStruct, &found, .{
4447 .gpa = gpa,4448 .gpa = gpa,
4448 .source = ".{ .foo = .{ .baz = 200 } }",4449 .source = ".{ .foo = .{ .baz = 200 } }",
4449 .diag = null,4450 .errors = null,
4450 });4451 });
4451 expected.foo.?.baz = 200;4452 expected.foo.?.baz = 200;
4452 try std.testing.expectEqual(expected, found);4453 try std.testing.expectEqual(expected, found);
...@@ -4471,7 +4472,7 @@ test "std.zon update optional pointers" {...@@ -4471,7 +4472,7 @@ test "std.zon update optional pointers" {
4471 .gpa = gpa,4472 .gpa = gpa,
4472 .arena = arena,4473 .arena = arena,
4473 .source = ".{ .foo = .{ .qux = 3 } }",4474 .source = ".{ .foo = .{ .qux = 3 } }",
4474 .diag = null,4475 .errors = null,
4475 });4476 });
4476 expected.foo = &.{ .qux = 3 };4477 expected.foo = &.{ .qux = 3 };
4477 try std.testing.expectEqualDeep(expected, found);4478 try std.testing.expectEqualDeep(expected, found);
...@@ -4496,7 +4497,7 @@ test "std.zon update pointers" {...@@ -4496,7 +4497,7 @@ test "std.zon update pointers" {
4496 .gpa = gpa,4497 .gpa = gpa,
4497 .arena = arena,4498 .arena = arena,
4498 .source = ".{ .foo = .{ .bar = 100 } }",4499 .source = ".{ .foo = .{ .bar = 100 } }",
4499 .diag = null,4500 .errors = null,
4500 });4501 });
4501 expected.foo.bar = 100;4502 expected.foo.bar = 100;
4502 try std.testing.expectEqualDeep(expected, found);4503 try std.testing.expectEqualDeep(expected, found);
...@@ -4513,7 +4514,7 @@ test "std.zon update pointers" {...@@ -4513,7 +4514,7 @@ test "std.zon update pointers" {
4513 .gpa = gpa,4514 .gpa = gpa,
4514 .arena = arena,4515 .arena = arena,
4515 .source = ".{ .foo = .{ .bar = 100 } }",4516 .source = ".{ .foo = .{ .bar = 100 } }",
4516 .diag = null,4517 .errors = null,
4517 });4518 });
4518 expected.foo = &.{ .bar = 100, .baz = 20, .qux = 3 };4519 expected.foo = &.{ .bar = 100, .baz = 20, .qux = 3 };
4519 try std.testing.expectEqualDeep(expected, found);4520 try std.testing.expectEqualDeep(expected, found);
...@@ -4538,7 +4539,7 @@ test "std.zon update unions" {...@@ -4538,7 +4539,7 @@ test "std.zon update unions" {
4538 try updateFromSlice(MyUnion, &found, .{4539 try updateFromSlice(MyUnion, &found, .{
4539 .gpa = gpa,4540 .gpa = gpa,
4540 .source = ".{ .foo = .{ .qux = 3 } }",4541 .source = ".{ .foo = .{ .qux = 3 } }",
4541 .diag = null,4542 .errors = null,
4542 });4543 });
4543 expected = .{ .foo = .{ .qux = 3 } };4544 expected = .{ .foo = .{ .qux = 3 } };
4544 try std.testing.expectEqual(expected, found);4545 try std.testing.expectEqual(expected, found);
...@@ -4547,13 +4548,13 @@ test "std.zon update unions" {...@@ -4547,13 +4548,13 @@ test "std.zon update unions" {
4547 // Updating a union to a new field should error if we leave off required sub-fields4548 // Updating a union to a new field should error if we leave off required sub-fields
4548 {4549 {
4549 var found: MyUnion = .none;4550 var found: MyUnion = .none;
4550 var diag: Diagnostics = .init(arena);4551 var errors: Errors = .init(arena);
4551 try std.testing.expectError(error.ParseZon, updateFromSlice(MyUnion, &found, .{4552 try std.testing.expectError(error.ParseZon, updateFromSlice(MyUnion, &found, .{
4552 .gpa = gpa,4553 .gpa = gpa,
4553 .source = ".{ .foo = .{} }",4554 .source = ".{ .foo = .{} }",
4554 .diag = &diag,4555 .errors = &errors,
4555 }));4556 }));
4556 try std.testing.expectFmt("1:12: error: missing required field qux\n", "{f}", .{diag});4557 try std.testing.expectFmt("1:12: error: missing required field qux\n", "{f}", .{errors});
4557 }4558 }
45584559
4559 // Updating a union should preseve any sub-fields that we left off. It's also okay to leave off4560 // Updating a union should preseve any sub-fields that we left off. It's also okay to leave off
...@@ -4566,7 +4567,7 @@ test "std.zon update unions" {...@@ -4566,7 +4567,7 @@ test "std.zon update unions" {
4566 try updateFromSlice(MyUnion, &found, .{4567 try updateFromSlice(MyUnion, &found, .{
4567 .gpa = gpa,4568 .gpa = gpa,
4568 .source = ".{ .foo = .{ .baz = 200 } }",4569 .source = ".{ .foo = .{ .baz = 200 } }",
4569 .diag = null,4570 .errors = null,
4570 });4571 });
4571 expected.foo.baz = 200;4572 expected.foo.baz = 200;
4572 try std.testing.expectEqual(expected, found);4573 try std.testing.expectEqual(expected, found);
...@@ -4597,7 +4598,7 @@ test "std.zon variants" {...@@ -4597,7 +4598,7 @@ test "std.zon variants" {
4597 try updateFromSlice(Struct, &curr, .{4598 try updateFromSlice(Struct, &curr, .{
4598 .gpa = gpa,4599 .gpa = gpa,
4599 .source = ".{ .a = 100 }",4600 .source = ".{ .a = 100 }",
4600 .diag = null,4601 .errors = null,
4601 });4602 });
4602 try std.testing.expectEqual(end, curr);4603 try std.testing.expectEqual(end, curr);
46034604
...@@ -4606,7 +4607,7 @@ test "std.zon variants" {...@@ -4606,7 +4607,7 @@ test "std.zon variants" {
4606 .gpa = gpa,4607 .gpa = gpa,
4607 .arena = arena,4608 .arena = arena,
4608 .source = ".{ .a = 100 }",4609 .source = ".{ .a = 100 }",
4609 .diag = null,4610 .errors = null,
4610 });4611 });
4611 try std.testing.expectEqual(end, curr);4612 try std.testing.expectEqual(end, curr);
46124613
...@@ -4614,7 +4615,7 @@ test "std.zon variants" {...@@ -4614,7 +4615,7 @@ test "std.zon variants" {
4614 try updateFromZoir(Struct, &curr, .{4615 try updateFromZoir(Struct, &curr, .{
4615 .ast = &ast,4616 .ast = &ast,
4616 .zoir = &zoir,4617 .zoir = &zoir,
4617 .diag = null,4618 .errors = null,
4618 });4619 });
4619 try std.testing.expectEqual(end, curr);4620 try std.testing.expectEqual(end, curr);
46204621
...@@ -4623,7 +4624,7 @@ test "std.zon variants" {...@@ -4623,7 +4624,7 @@ test "std.zon variants" {
4623 .arena = arena,4624 .arena = arena,
4624 .ast = &ast,4625 .ast = &ast,
4625 .zoir = &zoir,4626 .zoir = &zoir,
4626 .diag = null,4627 .errors = null,
4627 });4628 });
4628 try std.testing.expectEqual(end, curr);4629 try std.testing.expectEqual(end, curr);
4629 }4630 }
...@@ -4640,7 +4641,7 @@ test "std.zon variants" {...@@ -4640,7 +4641,7 @@ test "std.zon variants" {
4640 try fromSlice(Struct, .{4641 try fromSlice(Struct, .{
4641 .gpa = gpa,4642 .gpa = gpa,
4642 .source = ".{ .a = 100, .b = 20 }",4643 .source = ".{ .a = 100, .b = 20 }",
4643 .diag = null,4644 .errors = null,
4644 }),4645 }),
4645 );4646 );
4646 try std.testing.expectEqual(4647 try std.testing.expectEqual(
...@@ -4649,14 +4650,14 @@ test "std.zon variants" {...@@ -4649,14 +4650,14 @@ test "std.zon variants" {
4649 .gpa = gpa,4650 .gpa = gpa,
4650 .arena = arena,4651 .arena = arena,
4651 .source = ".{ .a = 100, .b = 20 }",4652 .source = ".{ .a = 100, .b = 20 }",
4652 .diag = null,4653 .errors = null,
4653 }),4654 }),
4654 );4655 );
4655 try std.testing.expectEqual(4656 try std.testing.expectEqual(
4656 try fromZoir(Struct, .{4657 try fromZoir(Struct, .{
4657 .ast = &ast,4658 .ast = &ast,
4658 .zoir = &zoir,4659 .zoir = &zoir,
4659 .diag = null,4660 .errors = null,
4660 }),4661 }),
4661 end,4662 end,
4662 );4663 );
...@@ -4665,7 +4666,7 @@ test "std.zon variants" {...@@ -4665,7 +4666,7 @@ test "std.zon variants" {
4665 .arena = arena,4666 .arena = arena,
4666 .ast = &ast,4667 .ast = &ast,
4667 .zoir = &zoir,4668 .zoir = &zoir,
4668 .diag = null,4669 .errors = null,
4669 }),4670 }),
4670 end,4671 end,
4671 );4672 );