| ... | ... | @@ -23,82 +23,14 @@ const ArenaAllocator = std.heap.ArenaAllocator; |
| 23 | 23 | /// Rename when adding or removing support for a type. |
| 24 | 24 | const valid_types = {}; |
| 25 | 25 | |
| 26 | | /// An error encountered while parsing ZON. |
| 27 | | pub const Error = struct { |
| 28 | | msg: []const u8, |
| 29 | | loc: Ast.Location, |
| 30 | | token: Ast.OptionalTokenIndex, |
| 31 | | /// If `token == .none`, this is an `Ast.Node.Index`. |
| 32 | | /// Otherwise, this is a byte offset into `token`. |
| 33 | | node_or_offset: u32, |
| 34 | | notes: []Note, |
| 35 | | |
| 36 | | const Options = struct { |
| 37 | | msg: []const u8, |
| 38 | | token: Ast.OptionalTokenIndex, |
| 39 | | node_or_offset: u32, |
| 40 | | notes: []Note, |
| 41 | | }; |
| 42 | | |
| 43 | | fn init(ast: *const Ast, options: Error.Options) Error { |
| 44 | | return .{ |
| 45 | | .msg = options.msg, |
| 46 | | .loc = astLoc(ast, options.token, options.node_or_offset), |
| 47 | | .token = options.token, |
| 48 | | .node_or_offset = options.node_or_offset, |
| 49 | | .notes = options.notes, |
| 50 | | }; |
| 51 | | } |
| 52 | | |
| 53 | | fn astLoc( |
| 54 | | ast: *const Ast, |
| 55 | | maybe_token: Ast.OptionalTokenIndex, |
| 56 | | node_or_offset: u32, |
| 57 | | ) Ast.Location { |
| 58 | | if (maybe_token.unwrap()) |token| { |
| 59 | | var loc = ast.tokenLocation(0, token); |
| 60 | | loc.column += node_or_offset; |
| 61 | | return loc; |
| 62 | | } else { |
| 63 | | const ast_node: Ast.Node.Index = @fromBackingInt(@intCast(node_or_offset)); |
| 64 | | const token = ast.nodeMainToken(ast_node); |
| 65 | | return ast.tokenLocation(0, token); |
| 66 | | } |
| 67 | | } |
| 68 | | |
| 69 | | pub const Note = struct { |
| 70 | | msg: []const u8, |
| 71 | | loc: Ast.Location, |
| 72 | | token: Ast.OptionalTokenIndex, |
| 73 | | /// If `token == .none`, this is an `Ast.Node.Index`. |
| 74 | | /// Otherwise, this is a byte offset into `token`. |
| 75 | | node_or_offset: u32, |
| 76 | | |
| 77 | | const Options = struct { |
| 78 | | msg: []const u8, |
| 79 | | token: Ast.OptionalTokenIndex, |
| 80 | | node_or_offset: u32, |
| 81 | | }; |
| 82 | | |
| 83 | | fn init(ast: *const Ast, options: Note.Options) @This() { |
| 84 | | return .{ |
| 85 | | .msg = options.msg, |
| 86 | | .loc = astLoc(ast, options.token, options.node_or_offset), |
| 87 | | .token = options.token, |
| 88 | | .node_or_offset = options.node_or_offset, |
| 89 | | }; |
| 90 | | } |
| 91 | | }; |
| 92 | | }; |
| 93 | | |
| 94 | 26 | /// Errors encountered while parsing ZON. See `log` and `fatal` for reporting errors to the user. |
| 95 | | pub const Errors = struct { |
| 96 | | items: []const Error, |
| 27 | pub const Diagnostics = struct { |
| 28 | errors: []const Error, |
| 97 | 29 | |
| 98 | | pub const empty: Errors = .{ .items = &.{} }; |
| 30 | pub const empty: Diagnostics = .{ .errors = &.{} }; |
| 99 | 31 | |
| 100 | 32 | /// Log the failure with `std.log.err`. |
| 101 | | pub fn log(self: *const Errors, path: []const u8) void { |
| 33 | pub fn log(self: *const Diagnostics, path: []const u8) void { |
| 102 | 34 | std.log.err("{f}", .{self.fmt(path)}); |
| 103 | 35 | } |
| 104 | 36 | |
| ... | ... | @@ -107,7 +39,7 @@ pub const Errors = struct { |
| 107 | 39 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 108 | 40 | defer arena_allocator.deinit(); |
| 109 | 41 | const arena = arena_allocator.allocator(); |
| 110 | | var errors: Errors = .empty; |
| 42 | var diagnostics: Diagnostics = .empty; |
| 111 | 43 | |
| 112 | 44 | const MyType = struct { |
| 113 | 45 | foo: u32, |
| ... | ... | @@ -118,11 +50,11 @@ pub const Errors = struct { |
| 118 | 50 | .gpa = gpa, |
| 119 | 51 | .arena = arena, |
| 120 | 52 | .source = ".{ .foo = 1, .bar = 2 }", |
| 121 | | .errors = &errors, |
| 53 | .diagnostics = &diagnostics, |
| 122 | 54 | }) catch |err| switch (err) { |
| 123 | 55 | error.OutOfMemory => return error.OutOfMemory, |
| 124 | 56 | error.ParseZon => b: { |
| 125 | | errors.log("input.zon"); |
| 57 | diagnostics.log("input.zon"); |
| 126 | 58 | break :b .{ .foo = 0, .bar = 0 }; |
| 127 | 59 | }, |
| 128 | 60 | }; |
| ... | ... | @@ -130,7 +62,7 @@ pub const Errors = struct { |
| 130 | 62 | } |
| 131 | 63 | |
| 132 | 64 | /// Log the failure with `std.log.err`, and then terminate the process with exit code 1. |
| 133 | | pub fn fatal(self: *const Errors, path: []const u8) noreturn { |
| 65 | pub fn fatal(self: *const Diagnostics, path: []const u8) noreturn { |
| 134 | 66 | std.process.fatal("{f}", .{self.fmt(path)}); |
| 135 | 67 | } |
| 136 | 68 | |
| ... | ... | @@ -139,7 +71,7 @@ pub const Errors = struct { |
| 139 | 71 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 140 | 72 | defer arena_allocator.deinit(); |
| 141 | 73 | const arena = arena_allocator.allocator(); |
| 142 | | var errors: Errors = .empty; |
| 74 | var diagnostics: Diagnostics = .empty; |
| 143 | 75 | |
| 144 | 76 | const MyType = struct { |
| 145 | 77 | foo: u32, |
| ... | ... | @@ -150,27 +82,44 @@ pub const Errors = struct { |
| 150 | 82 | .gpa = gpa, |
| 151 | 83 | .arena = arena, |
| 152 | 84 | .source = ".{ .foo = 1, .bar = 2 }", |
| 153 | | .errors = &errors, |
| 85 | .diagnostics = &diagnostics, |
| 154 | 86 | }) catch |err| switch (err) { |
| 155 | 87 | error.OutOfMemory => return error.OutOfMemory, |
| 156 | | error.ParseZon => errors.fatal("input.zon"), |
| 88 | error.ParseZon => diagnostics.fatal("input.zon"), |
| 157 | 89 | }; |
| 158 | 90 | _ = parsed; |
| 159 | 91 | } |
| 160 | 92 | |
| 161 | | pub fn fmt(self: *const Errors, path: []const u8) Formatter { |
| 93 | /// Formats a human readable description of any errors. |
| 94 | pub fn fmt(self: *const Diagnostics, path: []const u8) Formatter { |
| 162 | 95 | return .{ |
| 163 | | .items = self.items, |
| 96 | .errors = self.errors, |
| 164 | 97 | .path = path, |
| 165 | 98 | }; |
| 166 | 99 | } |
| 167 | 100 | |
| 101 | fn astLoc( |
| 102 | ast: *const Ast, |
| 103 | maybe_token: Ast.OptionalTokenIndex, |
| 104 | node_or_offset: u32, |
| 105 | ) Ast.Location { |
| 106 | if (maybe_token.unwrap()) |token| { |
| 107 | var loc = ast.tokenLocation(0, token); |
| 108 | loc.column += node_or_offset; |
| 109 | return loc; |
| 110 | } else { |
| 111 | const ast_node: Ast.Node.Index = @fromBackingInt(@intCast(node_or_offset)); |
| 112 | const token = ast.nodeMainToken(ast_node); |
| 113 | return ast.tokenLocation(0, token); |
| 114 | } |
| 115 | } |
| 116 | |
| 168 | 117 | pub const Formatter = struct { |
| 169 | 118 | path: []const u8, |
| 170 | | items: []const Error, |
| 119 | errors: []const Error, |
| 171 | 120 | |
| 172 | 121 | pub fn format(self: *const @This(), w: *std.Io.Writer) std.Io.Writer.Error!void { |
| 173 | | for (self.items) |e| { |
| 122 | for (self.errors) |e| { |
| 174 | 123 | try w.print("{s}:", .{self.path}); |
| 175 | 124 | try w.print("{d}:{d}: error: {s}\n", .{ |
| 176 | 125 | e.loc.line + 1, |
| ... | ... | @@ -189,23 +138,74 @@ pub const Errors = struct { |
| 189 | 138 | } |
| 190 | 139 | } |
| 191 | 140 | }; |
| 141 | |
| 142 | pub const Error = struct { |
| 143 | msg: []const u8, |
| 144 | loc: Ast.Location, |
| 145 | token: Ast.OptionalTokenIndex, |
| 146 | /// If `token == .none`, this is an `Ast.Node.Index`. |
| 147 | /// Otherwise, this is a byte offset into `token`. |
| 148 | node_or_offset: u32, |
| 149 | notes: []Note, |
| 150 | |
| 151 | const Options = struct { |
| 152 | msg: []const u8, |
| 153 | token: Ast.OptionalTokenIndex, |
| 154 | node_or_offset: u32, |
| 155 | notes: []Note, |
| 156 | }; |
| 157 | |
| 158 | fn init(ast: *const Ast, options: Error.Options) Error { |
| 159 | return .{ |
| 160 | .msg = options.msg, |
| 161 | .loc = astLoc(ast, options.token, options.node_or_offset), |
| 162 | .token = options.token, |
| 163 | .node_or_offset = options.node_or_offset, |
| 164 | .notes = options.notes, |
| 165 | }; |
| 166 | } |
| 167 | }; |
| 168 | |
| 169 | pub const Note = struct { |
| 170 | msg: []const u8, |
| 171 | loc: Ast.Location, |
| 172 | token: Ast.OptionalTokenIndex, |
| 173 | /// If `token == .none`, this is an `Ast.Node.Index`. |
| 174 | /// Otherwise, this is a byte offset into `token`. |
| 175 | node_or_offset: u32, |
| 176 | |
| 177 | const Options = struct { |
| 178 | msg: []const u8, |
| 179 | token: Ast.OptionalTokenIndex, |
| 180 | node_or_offset: u32, |
| 181 | }; |
| 182 | |
| 183 | fn init(ast: *const Ast, options: Note.Options) @This() { |
| 184 | return .{ |
| 185 | .msg = options.msg, |
| 186 | .loc = astLoc(ast, options.token, options.node_or_offset), |
| 187 | .token = options.token, |
| 188 | .node_or_offset = options.node_or_offset, |
| 189 | }; |
| 190 | } |
| 191 | }; |
| 192 | 192 | }; |
| 193 | 193 | |
| 194 | 194 | pub const Options = struct { |
| 195 | 195 | /// Used for scratch allocations. |
| 196 | 196 | gpa: Allocator, |
| 197 | | /// Used for allocating errors and results. |
| 197 | /// Used for allocating diagnostics and results. |
| 198 | 198 | arena: Allocator, |
| 199 | 199 | /// The ZON source to parse. |
| 200 | 200 | source: [:0]const u8, |
| 201 | 201 | /// When an error is returned from the parser, a human readable error description of the failure |
| 202 | 202 | /// is stored here. |
| 203 | | errors: *Errors, |
| 203 | diagnostics: *Diagnostics, |
| 204 | 204 | /// If true, unknown fields do not error. |
| 205 | 205 | ignore_unknown_fields: bool = false, |
| 206 | 206 | }; |
| 207 | 207 | |
| 208 | | /// Parses the given slice as ZON, writing any errors to `options.errors`. |
| 208 | /// Parses the given slice as ZON, writing any errors to `options.diagnostics`. |
| 209 | 209 | pub fn fromSlice(T: type, options: Options) error{ OutOfMemory, ParseZon }!T { |
| 210 | 210 | var value: T = undefined; |
| 211 | 211 | try fromSliceInner(T, &value, false, options); |
| ... | ... | @@ -232,16 +232,16 @@ test fromSlice { |
| 232 | 232 | \\} |
| 233 | 233 | ; |
| 234 | 234 | |
| 235 | | var errors: Errors = .empty; |
| 235 | var diagnostics: Diagnostics = .empty; |
| 236 | 236 | const options = fromSlice(TextureOptions, .{ |
| 237 | 237 | .gpa = gpa, |
| 238 | 238 | .arena = arena, |
| 239 | 239 | .source = source, |
| 240 | | .errors = &errors, |
| 240 | .diagnostics = &diagnostics, |
| 241 | 241 | }) catch |err| switch (err) { |
| 242 | 242 | error.OutOfMemory => return err, |
| 243 | 243 | error.ParseZon => { |
| 244 | | errors.log("texture_options.zon"); |
| 244 | diagnostics.log("texture_options.zon"); |
| 245 | 245 | return err; |
| 246 | 246 | }, |
| 247 | 247 | }; |
| ... | ... | @@ -307,16 +307,16 @@ test updateFromSlice { |
| 307 | 307 | .theme = "default", |
| 308 | 308 | }; |
| 309 | 309 | |
| 310 | | var errors: Errors = .empty; |
| 310 | var diagnostics: Diagnostics = .empty; |
| 311 | 311 | updateFromSlice(MyTextEditorConfig, &config, .{ |
| 312 | 312 | .gpa = gpa, |
| 313 | 313 | .arena = arena, |
| 314 | 314 | .source = global_config, |
| 315 | | .errors = &errors, |
| 315 | .diagnostics = &diagnostics, |
| 316 | 316 | }) catch |err| switch (err) { |
| 317 | 317 | error.OutOfMemory => return err, |
| 318 | 318 | error.ParseZon => { |
| 319 | | errors.log("global_config.zon"); |
| 319 | diagnostics.log("global_config.zon"); |
| 320 | 320 | return err; |
| 321 | 321 | }, |
| 322 | 322 | }; |
| ... | ... | @@ -324,11 +324,11 @@ test updateFromSlice { |
| 324 | 324 | .gpa = gpa, |
| 325 | 325 | .arena = arena, |
| 326 | 326 | .source = project_config, |
| 327 | | .errors = &errors, |
| 327 | .diagnostics = &diagnostics, |
| 328 | 328 | }) catch |err| switch (err) { |
| 329 | 329 | error.OutOfMemory => return err, |
| 330 | 330 | error.ParseZon => { |
| 331 | | errors.log("project_config.zon"); |
| 331 | diagnostics.log("project_config.zon"); |
| 332 | 332 | return err; |
| 333 | 333 | }, |
| 334 | 334 | }; |
| ... | ... | @@ -358,8 +358,8 @@ fn fromSliceInner( |
| 358 | 358 | initialized: bool, |
| 359 | 359 | options: Options, |
| 360 | 360 | ) error{ OutOfMemory, ParseZon }!void { |
| 361 | | var errors: std.ArrayList(Error) = .empty; |
| 362 | | defer options.errors.items = errors.items; |
| 361 | var errors: std.ArrayList(Diagnostics.Error) = .empty; |
| 362 | defer options.diagnostics.errors = errors.items; |
| 363 | 363 | |
| 364 | 364 | var ast = try std.zig.Ast.parse(options.gpa, options.source, .{ .mode = .zon }); |
| 365 | 365 | defer ast.deinit(options.gpa); |
| ... | ... | @@ -378,7 +378,7 @@ fn fromSliceInner( |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | pub const FromZoirOptions = struct { |
| 381 | | /// Used for allocating errors and results. |
| 381 | /// Used for allocating diagnostics and results. |
| 382 | 382 | arena: Allocator, |
| 383 | 383 | /// The AST for this ZON value. |
| 384 | 384 | ast: *const Ast, |
| ... | ... | @@ -388,7 +388,7 @@ pub const FromZoirOptions = struct { |
| 388 | 388 | node: Zoir.Node.Index = .root, |
| 389 | 389 | /// When an error is returned from the parser, a human readable error description of the failure |
| 390 | 390 | /// is stored here. |
| 391 | | errors: *Errors, |
| 391 | diagnostics: *Diagnostics, |
| 392 | 392 | /// If true, unknown fields do not error. |
| 393 | 393 | ignore_unknown_fields: bool = false, |
| 394 | 394 | }; |
| ... | ... | @@ -431,8 +431,8 @@ fn fromZoirInner( |
| 431 | 431 | initialized: bool, |
| 432 | 432 | options: FromZoirOptions, |
| 433 | 433 | ) error{ OutOfMemory, ParseZon }!void { |
| 434 | | var errors: std.ArrayList(Error) = .empty; |
| 435 | | defer options.errors.items = errors.items; |
| 434 | var errors: std.ArrayList(Diagnostics.Error) = .empty; |
| 435 | defer options.diagnostics.errors = errors.items; |
| 436 | 436 | return inner(T, value, initialized, .{ |
| 437 | 437 | .arena = options.arena, |
| 438 | 438 | .ast = options.ast, |
| ... | ... | @@ -447,7 +447,7 @@ const InnerOptions = struct { |
| 447 | 447 | ast: *const Ast, |
| 448 | 448 | zoir: *const Zoir, |
| 449 | 449 | node: Zoir.Node.Index = .root, |
| 450 | | errors: *std.ArrayList(Error), |
| 450 | errors: *std.ArrayList(Diagnostics.Error), |
| 451 | 451 | ignore_unknown_fields: bool, |
| 452 | 452 | }; |
| 453 | 453 | |
| ... | ... | @@ -461,7 +461,7 @@ fn inner( |
| 461 | 461 | |
| 462 | 462 | if (options.zoir.hasCompileErrors()) { |
| 463 | 463 | for (options.zoir.compile_errors) |e| { |
| 464 | | var notes: std.ArrayList(Error.Note) = .empty; |
| 464 | var notes: std.ArrayList(Diagnostics.Note) = .empty; |
| 465 | 465 | for (e.getNotes(options.zoir)) |note| { |
| 466 | 466 | try notes.append(options.arena, .init(options.ast, .{ |
| 467 | 467 | .msg = try options.arena.dupe(u8, note.msg.get(options.zoir)), |
| ... | ... | @@ -515,7 +515,7 @@ const Parser = struct { |
| 515 | 515 | arena: Allocator, |
| 516 | 516 | ast: *const Ast, |
| 517 | 517 | zoir: *const Zoir, |
| 518 | | errors: *std.ArrayList(Error), |
| 518 | errors: *std.ArrayList(Diagnostics.Error), |
| 519 | 519 | ignore_unknown_fields: bool, |
| 520 | 520 | |
| 521 | 521 | const ParseExprError = error{ ParseZon, OutOfMemory }; |
| ... | ... | @@ -1086,7 +1086,7 @@ const Parser = struct { |
| 1086 | 1086 | offset: u32, |
| 1087 | 1087 | comptime fmt: []const u8, |
| 1088 | 1088 | args: anytype, |
| 1089 | | notes: []Error.Note, |
| 1089 | notes: []Diagnostics.Note, |
| 1090 | 1090 | ) error{ OutOfMemory, ParseZon } { |
| 1091 | 1091 | @branchHint(.cold); |
| 1092 | 1092 | comptime assert(args.len > 0); |
| ... | ... | @@ -1112,7 +1112,7 @@ const Parser = struct { |
| 1112 | 1112 | |
| 1113 | 1113 | fn failToken( |
| 1114 | 1114 | self: Parser, |
| 1115 | | failure: Error, |
| 1115 | failure: Diagnostics.Error, |
| 1116 | 1116 | ) error{ OutOfMemory, ParseZon } { |
| 1117 | 1117 | @branchHint(.cold); |
| 1118 | 1118 | try self.errors.append(self.arena, failure); |
| ... | ... | @@ -1160,7 +1160,7 @@ const Parser = struct { |
| 1160 | 1160 | } else self.ast.nodeMainToken(node.getAstNode(self.zoir)); |
| 1161 | 1161 | switch (@typeInfo(T)) { |
| 1162 | 1162 | inline .@"struct", .@"union", .@"enum" => |info| { |
| 1163 | | var notes: std.ArrayList(Error.Note) = .empty; |
| 1163 | var notes: std.ArrayList(Diagnostics.Note) = .empty; |
| 1164 | 1164 | if (info.field_names.len == 0) { |
| 1165 | 1165 | try notes.append(self.arena, .init(self.ast, .{ |
| 1166 | 1166 | .token = .fromToken(token), |
| ... | ... | @@ -1384,20 +1384,20 @@ test "std.zon ast errors" { |
| 1384 | 1384 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 1385 | 1385 | defer arena_allocator.deinit(); |
| 1386 | 1386 | const arena = arena_allocator.allocator(); |
| 1387 | | var errors: Errors = .empty; |
| 1387 | var diagnostics: Diagnostics = .empty; |
| 1388 | 1388 | try std.testing.expectError( |
| 1389 | 1389 | error.ParseZon, |
| 1390 | 1390 | fromSliceNoAlloc(struct {}, .{ |
| 1391 | 1391 | .gpa = gpa, |
| 1392 | 1392 | .arena = arena, |
| 1393 | 1393 | .source = ".{.x = 1 .y = 2}", |
| 1394 | | .errors = &errors, |
| 1394 | .diagnostics = &diagnostics, |
| 1395 | 1395 | }), |
| 1396 | 1396 | ); |
| 1397 | 1397 | try std.testing.expectFmt( |
| 1398 | 1398 | \\input.zon:1:13: error: expected ',' after initializer |
| 1399 | 1399 | \\ |
| 1400 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1400 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1401 | 1401 | } |
| 1402 | 1402 | |
| 1403 | 1403 | test "std.zon comments" { |
| ... | ... | @@ -1405,7 +1405,7 @@ test "std.zon comments" { |
| 1405 | 1405 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 1406 | 1406 | defer arena_allocator.deinit(); |
| 1407 | 1407 | const arena = arena_allocator.allocator(); |
| 1408 | | var errors: Errors = .empty; |
| 1408 | var diagnostics: Diagnostics = .empty; |
| 1409 | 1409 | |
| 1410 | 1410 | try std.testing.expectEqual(@as(u8, 10), fromSliceNoAlloc(u8, .{ |
| 1411 | 1411 | .gpa = gpa, |
| ... | ... | @@ -1415,7 +1415,7 @@ test "std.zon comments" { |
| 1415 | 1415 | \\10 // comment |
| 1416 | 1416 | \\// comment |
| 1417 | 1417 | , |
| 1418 | | .errors = &errors, |
| 1418 | .diagnostics = &diagnostics, |
| 1419 | 1419 | })); |
| 1420 | 1420 | |
| 1421 | 1421 | { |
| ... | ... | @@ -1427,12 +1427,12 @@ test "std.zon comments" { |
| 1427 | 1427 | \\10 // comment |
| 1428 | 1428 | \\// comment |
| 1429 | 1429 | , |
| 1430 | | .errors = &errors, |
| 1430 | .diagnostics = &diagnostics, |
| 1431 | 1431 | })); |
| 1432 | 1432 | try std.testing.expectFmt( |
| 1433 | 1433 | \\input.zon:1:1: error: expected expression, found 'a document comment' |
| 1434 | 1434 | \\ |
| 1435 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1435 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1436 | 1436 | } |
| 1437 | 1437 | } |
| 1438 | 1438 | |
| ... | ... | @@ -1441,17 +1441,17 @@ test "std.zon failure/oom formatting" { |
| 1441 | 1441 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 1442 | 1442 | defer arena_allocator.deinit(); |
| 1443 | 1443 | const arena = arena_allocator.allocator(); |
| 1444 | | var errors: Errors = .empty; |
| 1444 | var diagnostics: Diagnostics = .empty; |
| 1445 | 1445 | |
| 1446 | 1446 | try std.testing.expectError(error.OutOfMemory, fromSlice([]const u8, .{ |
| 1447 | 1447 | .gpa = .failing, |
| 1448 | 1448 | .arena = arena, |
| 1449 | 1449 | .source = "\"foo\"", |
| 1450 | | .errors = &errors, |
| 1450 | .diagnostics = &diagnostics, |
| 1451 | 1451 | })); |
| 1452 | 1452 | try std.testing.expectFmt( |
| 1453 | 1453 | \\ |
| 1454 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1454 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | 1457 | test "std.zon fromSlice syntax error" { |
| ... | ... | @@ -1459,20 +1459,20 @@ test "std.zon fromSlice syntax error" { |
| 1459 | 1459 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 1460 | 1460 | defer arena_allocator.deinit(); |
| 1461 | 1461 | const arena = arena_allocator.allocator(); |
| 1462 | | var errors: Errors = .empty; |
| 1462 | var diagnostics: Diagnostics = .empty; |
| 1463 | 1463 | try std.testing.expectError( |
| 1464 | 1464 | error.ParseZon, |
| 1465 | 1465 | fromSliceNoAlloc(u8, .{ |
| 1466 | 1466 | .gpa = gpa, |
| 1467 | 1467 | .arena = arena, |
| 1468 | 1468 | .source = ".{", |
| 1469 | | .errors = &errors, |
| 1469 | .diagnostics = &diagnostics, |
| 1470 | 1470 | }), |
| 1471 | 1471 | ); |
| 1472 | 1472 | try std.testing.expectFmt( |
| 1473 | 1473 | \\input.zon:1:3: error: expected expression, found 'EOF' |
| 1474 | 1474 | \\ |
| 1475 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1475 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1476 | 1476 | } |
| 1477 | 1477 | |
| 1478 | 1478 | test "std.zon optional" { |
| ... | ... | @@ -1480,7 +1480,7 @@ test "std.zon optional" { |
| 1480 | 1480 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 1481 | 1481 | defer arena_allocator.deinit(); |
| 1482 | 1482 | const arena = arena_allocator.allocator(); |
| 1483 | | var errors: Errors = .empty; |
| 1483 | var diagnostics: Diagnostics = .empty; |
| 1484 | 1484 | |
| 1485 | 1485 | // Basic usage |
| 1486 | 1486 | { |
| ... | ... | @@ -1488,14 +1488,14 @@ test "std.zon optional" { |
| 1488 | 1488 | .gpa = gpa, |
| 1489 | 1489 | .arena = arena, |
| 1490 | 1490 | .source = "null", |
| 1491 | | .errors = &errors, |
| 1491 | .diagnostics = &diagnostics, |
| 1492 | 1492 | }); |
| 1493 | 1493 | try std.testing.expect(none == null); |
| 1494 | 1494 | const some = try fromSliceNoAlloc(?u32, .{ |
| 1495 | 1495 | .gpa = gpa, |
| 1496 | 1496 | .arena = arena, |
| 1497 | 1497 | .source = "1", |
| 1498 | | .errors = &errors, |
| 1498 | .diagnostics = &diagnostics, |
| 1499 | 1499 | }); |
| 1500 | 1500 | try std.testing.expect(some.? == 1); |
| 1501 | 1501 | } |
| ... | ... | @@ -1506,14 +1506,14 @@ test "std.zon optional" { |
| 1506 | 1506 | .gpa = gpa, |
| 1507 | 1507 | .arena = arena, |
| 1508 | 1508 | .source = "null", |
| 1509 | | .errors = &errors, |
| 1509 | .diagnostics = &diagnostics, |
| 1510 | 1510 | }); |
| 1511 | 1511 | try std.testing.expect(none == null); |
| 1512 | 1512 | const some = try fromSlice(?[]const u8, .{ |
| 1513 | 1513 | .gpa = gpa, |
| 1514 | 1514 | .arena = arena, |
| 1515 | 1515 | .source = "\"foo\"", |
| 1516 | | .errors = &errors, |
| 1516 | .diagnostics = &diagnostics, |
| 1517 | 1517 | }); |
| 1518 | 1518 | try std.testing.expectEqualStrings("foo", some.?); |
| 1519 | 1519 | } |
| ... | ... | @@ -1524,7 +1524,7 @@ test "std.zon unions" { |
| 1524 | 1524 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 1525 | 1525 | defer arena_allocator.deinit(); |
| 1526 | 1526 | const arena = arena_allocator.allocator(); |
| 1527 | | var errors: Errors = .empty; |
| 1527 | var diagnostics: Diagnostics = .empty; |
| 1528 | 1528 | |
| 1529 | 1529 | // Unions |
| 1530 | 1530 | { |
| ... | ... | @@ -1535,28 +1535,28 @@ test "std.zon unions" { |
| 1535 | 1535 | .gpa = gpa, |
| 1536 | 1536 | .arena = arena, |
| 1537 | 1537 | .source = ".{.x = 1.5}", |
| 1538 | | .errors = &errors, |
| 1538 | .diagnostics = &diagnostics, |
| 1539 | 1539 | }); |
| 1540 | 1540 | try std.testing.expectEqual(Tagged{ .x = 1.5 }, tagged_x); |
| 1541 | 1541 | const tagged_y = try fromSliceNoAlloc(Tagged, .{ |
| 1542 | 1542 | .gpa = gpa, |
| 1543 | 1543 | .arena = arena, |
| 1544 | 1544 | .source = ".{.@\"y y\" = true}", |
| 1545 | | .errors = &errors, |
| 1545 | .diagnostics = &diagnostics, |
| 1546 | 1546 | }); |
| 1547 | 1547 | try std.testing.expectEqual(Tagged{ .@"y y" = true }, tagged_y); |
| 1548 | 1548 | const tagged_z_shorthand = try fromSliceNoAlloc(Tagged, .{ |
| 1549 | 1549 | .gpa = gpa, |
| 1550 | 1550 | .arena = arena, |
| 1551 | 1551 | .source = ".z", |
| 1552 | | .errors = &errors, |
| 1552 | .diagnostics = &diagnostics, |
| 1553 | 1553 | }); |
| 1554 | 1554 | try std.testing.expectEqual(@as(Tagged, .z), tagged_z_shorthand); |
| 1555 | 1555 | const tagged_zz_shorthand = try fromSliceNoAlloc(Tagged, .{ |
| 1556 | 1556 | .gpa = gpa, |
| 1557 | 1557 | .arena = arena, |
| 1558 | 1558 | .source = ".@\"z z\"", |
| 1559 | | .errors = &errors, |
| 1559 | .diagnostics = &diagnostics, |
| 1560 | 1560 | }); |
| 1561 | 1561 | try std.testing.expectEqual(@as(Tagged, .@"z z"), tagged_zz_shorthand); |
| 1562 | 1562 | |
| ... | ... | @@ -1564,14 +1564,14 @@ test "std.zon unions" { |
| 1564 | 1564 | .gpa = gpa, |
| 1565 | 1565 | .arena = arena, |
| 1566 | 1566 | .source = ".{.x = 1.5}", |
| 1567 | | .errors = &errors, |
| 1567 | .diagnostics = &diagnostics, |
| 1568 | 1568 | }); |
| 1569 | 1569 | try std.testing.expect(untagged_x.x == 1.5); |
| 1570 | 1570 | const untagged_y = try fromSliceNoAlloc(Untagged, .{ |
| 1571 | 1571 | .gpa = gpa, |
| 1572 | 1572 | .arena = arena, |
| 1573 | 1573 | .source = ".{.@\"y y\" = true}", |
| 1574 | | .errors = &errors, |
| 1574 | .diagnostics = &diagnostics, |
| 1575 | 1575 | }); |
| 1576 | 1576 | try std.testing.expect(untagged_y.@"y y"); |
| 1577 | 1577 | } |
| ... | ... | @@ -1584,7 +1584,7 @@ test "std.zon unions" { |
| 1584 | 1584 | .gpa = gpa, |
| 1585 | 1585 | .arena = arena, |
| 1586 | 1586 | .source = ".{.baz = false}", |
| 1587 | | .errors = &errors, |
| 1587 | .diagnostics = &diagnostics, |
| 1588 | 1588 | }); |
| 1589 | 1589 | try std.testing.expectEqual(Union{ .baz = false }, noalloc); |
| 1590 | 1590 | |
| ... | ... | @@ -1592,7 +1592,7 @@ test "std.zon unions" { |
| 1592 | 1592 | .gpa = gpa, |
| 1593 | 1593 | .arena = arena, |
| 1594 | 1594 | .source = ".{.bar = \"qux\"}", |
| 1595 | | .errors = &errors, |
| 1595 | .diagnostics = &diagnostics, |
| 1596 | 1596 | }); |
| 1597 | 1597 | try std.testing.expectEqualDeep(Union{ .bar = "qux" }, alloc); |
| 1598 | 1598 | } |
| ... | ... | @@ -1606,14 +1606,14 @@ test "std.zon unions" { |
| 1606 | 1606 | .gpa = gpa, |
| 1607 | 1607 | .arena = arena, |
| 1608 | 1608 | .source = ".{.z=2.5}", |
| 1609 | | .errors = &errors, |
| 1609 | .diagnostics = &diagnostics, |
| 1610 | 1610 | }), |
| 1611 | 1611 | ); |
| 1612 | 1612 | try std.testing.expectFmt( |
| 1613 | 1613 | \\input.zon:1:4: error: unexpected field 'z' |
| 1614 | 1614 | \\input.zon:1:4: note: supported: 'x', 'y' |
| 1615 | 1615 | \\ |
| 1616 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1616 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1617 | 1617 | } |
| 1618 | 1618 | |
| 1619 | 1619 | // Explicit void field |
| ... | ... | @@ -1625,13 +1625,13 @@ test "std.zon unions" { |
| 1625 | 1625 | .gpa = gpa, |
| 1626 | 1626 | .arena = arena, |
| 1627 | 1627 | .source = ".{.x=1}", |
| 1628 | | .errors = &errors, |
| 1628 | .diagnostics = &diagnostics, |
| 1629 | 1629 | }), |
| 1630 | 1630 | ); |
| 1631 | 1631 | try std.testing.expectFmt( |
| 1632 | 1632 | \\input.zon:1:6: error: expected type 'void' |
| 1633 | 1633 | \\ |
| 1634 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1634 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1635 | 1635 | } |
| 1636 | 1636 | |
| 1637 | 1637 | // Extra field |
| ... | ... | @@ -1643,13 +1643,13 @@ test "std.zon unions" { |
| 1643 | 1643 | .gpa = gpa, |
| 1644 | 1644 | .arena = arena, |
| 1645 | 1645 | .source = ".{.x = 1.5, .y = true}", |
| 1646 | | .errors = &errors, |
| 1646 | .diagnostics = &diagnostics, |
| 1647 | 1647 | }), |
| 1648 | 1648 | ); |
| 1649 | 1649 | try std.testing.expectFmt( |
| 1650 | 1650 | \\input.zon:1:2: error: expected union |
| 1651 | 1651 | \\ |
| 1652 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1652 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1653 | 1653 | } |
| 1654 | 1654 | |
| 1655 | 1655 | // No fields |
| ... | ... | @@ -1661,13 +1661,13 @@ test "std.zon unions" { |
| 1661 | 1661 | .gpa = gpa, |
| 1662 | 1662 | .arena = arena, |
| 1663 | 1663 | .source = ".{}", |
| 1664 | | .errors = &errors, |
| 1664 | .diagnostics = &diagnostics, |
| 1665 | 1665 | }), |
| 1666 | 1666 | ); |
| 1667 | 1667 | try std.testing.expectFmt( |
| 1668 | 1668 | \\input.zon:1:2: error: expected union |
| 1669 | 1669 | \\ |
| 1670 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1670 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1671 | 1671 | } |
| 1672 | 1672 | |
| 1673 | 1673 | // Enum literals cannot coerce into untagged unions |
| ... | ... | @@ -1677,12 +1677,12 @@ test "std.zon unions" { |
| 1677 | 1677 | .gpa = gpa, |
| 1678 | 1678 | .arena = arena, |
| 1679 | 1679 | .source = ".x", |
| 1680 | | .errors = &errors, |
| 1680 | .diagnostics = &diagnostics, |
| 1681 | 1681 | })); |
| 1682 | 1682 | try std.testing.expectFmt( |
| 1683 | 1683 | \\input.zon:1:2: error: expected union |
| 1684 | 1684 | \\ |
| 1685 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1685 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1686 | 1686 | } |
| 1687 | 1687 | |
| 1688 | 1688 | // Unknown field for enum literal coercion |
| ... | ... | @@ -1692,13 +1692,13 @@ test "std.zon unions" { |
| 1692 | 1692 | .gpa = gpa, |
| 1693 | 1693 | .arena = arena, |
| 1694 | 1694 | .source = ".y", |
| 1695 | | .errors = &errors, |
| 1695 | .diagnostics = &diagnostics, |
| 1696 | 1696 | })); |
| 1697 | 1697 | try std.testing.expectFmt( |
| 1698 | 1698 | \\input.zon:1:2: error: unexpected field 'y' |
| 1699 | 1699 | \\input.zon:1:2: note: supported: 'x' |
| 1700 | 1700 | \\ |
| 1701 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1701 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1702 | 1702 | } |
| 1703 | 1703 | |
| 1704 | 1704 | // Non void field for enum literal coercion |
| ... | ... | @@ -1708,12 +1708,12 @@ test "std.zon unions" { |
| 1708 | 1708 | .gpa = gpa, |
| 1709 | 1709 | .arena = arena, |
| 1710 | 1710 | .source = ".x", |
| 1711 | | .errors = &errors, |
| 1711 | .diagnostics = &diagnostics, |
| 1712 | 1712 | })); |
| 1713 | 1713 | try std.testing.expectFmt( |
| 1714 | 1714 | \\input.zon:1:2: error: expected union |
| 1715 | 1715 | \\ |
| 1716 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1716 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1717 | 1717 | } |
| 1718 | 1718 | } |
| 1719 | 1719 | |
| ... | ... | @@ -1722,7 +1722,7 @@ test "std.zon structs" { |
| 1722 | 1722 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 1723 | 1723 | defer arena_allocator.deinit(); |
| 1724 | 1724 | const arena = arena_allocator.allocator(); |
| 1725 | | var errors: Errors = .empty; |
| 1725 | var diagnostics: Diagnostics = .empty; |
| 1726 | 1726 | |
| 1727 | 1727 | // Structs (various sizes tested since they're parsed differently) |
| 1728 | 1728 | { |
| ... | ... | @@ -1735,7 +1735,7 @@ test "std.zon structs" { |
| 1735 | 1735 | .gpa = gpa, |
| 1736 | 1736 | .arena = arena, |
| 1737 | 1737 | .source = ".{}", |
| 1738 | | .errors = &errors, |
| 1738 | .diagnostics = &diagnostics, |
| 1739 | 1739 | }); |
| 1740 | 1740 | try std.testing.expectEqual(Vec0{}, zero); |
| 1741 | 1741 | |
| ... | ... | @@ -1743,7 +1743,7 @@ test "std.zon structs" { |
| 1743 | 1743 | .gpa = gpa, |
| 1744 | 1744 | .arena = arena, |
| 1745 | 1745 | .source = ".{.x = 1.2}", |
| 1746 | | .errors = &errors, |
| 1746 | .diagnostics = &diagnostics, |
| 1747 | 1747 | }); |
| 1748 | 1748 | try std.testing.expectEqual(Vec1{ .x = 1.2 }, one); |
| 1749 | 1749 | |
| ... | ... | @@ -1751,7 +1751,7 @@ test "std.zon structs" { |
| 1751 | 1751 | .gpa = gpa, |
| 1752 | 1752 | .arena = arena, |
| 1753 | 1753 | .source = ".{.x = 1.2, .y = 3.4}", |
| 1754 | | .errors = &errors, |
| 1754 | .diagnostics = &diagnostics, |
| 1755 | 1755 | }); |
| 1756 | 1756 | try std.testing.expectEqual(Vec2{ .x = 1.2, .y = 3.4 }, two); |
| 1757 | 1757 | |
| ... | ... | @@ -1759,7 +1759,7 @@ test "std.zon structs" { |
| 1759 | 1759 | .gpa = gpa, |
| 1760 | 1760 | .arena = arena, |
| 1761 | 1761 | .source = ".{.x = 1.2, .y = 3.4, .z = 5.6}", |
| 1762 | | .errors = &errors, |
| 1762 | .diagnostics = &diagnostics, |
| 1763 | 1763 | }); |
| 1764 | 1764 | try std.testing.expectEqual(Vec3{ .x = 1.2, .y = 3.4, .z = 5.6 }, three); |
| 1765 | 1765 | } |
| ... | ... | @@ -1772,7 +1772,7 @@ test "std.zon structs" { |
| 1772 | 1772 | .gpa = gpa, |
| 1773 | 1773 | .arena = arena, |
| 1774 | 1774 | .source = ".{.bar = \"qux\", .baz = .{\"a\", \"b\"}}", |
| 1775 | | .errors = &errors, |
| 1775 | .diagnostics = &diagnostics, |
| 1776 | 1776 | }); |
| 1777 | 1777 | try std.testing.expectEqualDeep(Foo{ .bar = "qux", .baz = &.{ "a", "b" } }, parsed); |
| 1778 | 1778 | } |
| ... | ... | @@ -1786,14 +1786,14 @@ test "std.zon structs" { |
| 1786 | 1786 | .gpa = gpa, |
| 1787 | 1787 | .arena = arena, |
| 1788 | 1788 | .source = ".{.x=1.5, .z=2.5}", |
| 1789 | | .errors = &errors, |
| 1789 | .diagnostics = &diagnostics, |
| 1790 | 1790 | }), |
| 1791 | 1791 | ); |
| 1792 | 1792 | try std.testing.expectFmt( |
| 1793 | 1793 | \\input.zon:1:12: error: unexpected field 'z' |
| 1794 | 1794 | \\input.zon:1:12: note: supported: 'x', 'y' |
| 1795 | 1795 | \\ |
| 1796 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1796 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1797 | 1797 | } |
| 1798 | 1798 | |
| 1799 | 1799 | // Duplicate field |
| ... | ... | @@ -1805,14 +1805,14 @@ test "std.zon structs" { |
| 1805 | 1805 | .gpa = gpa, |
| 1806 | 1806 | .arena = arena, |
| 1807 | 1807 | .source = ".{.x=1.5, .x=2.5, .x=3.5}", |
| 1808 | | .errors = &errors, |
| 1808 | .diagnostics = &diagnostics, |
| 1809 | 1809 | }), |
| 1810 | 1810 | ); |
| 1811 | 1811 | try std.testing.expectFmt( |
| 1812 | 1812 | \\input.zon:1:4: error: duplicate struct field name |
| 1813 | 1813 | \\input.zon:1:12: note: duplicate name here |
| 1814 | 1814 | \\ |
| 1815 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1815 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1816 | 1816 | } |
| 1817 | 1817 | |
| 1818 | 1818 | // Ignore unknown fields |
| ... | ... | @@ -1823,7 +1823,7 @@ test "std.zon structs" { |
| 1823 | 1823 | .arena = arena, |
| 1824 | 1824 | .source = ".{ .x = 1.0, .z = 3.0 }", |
| 1825 | 1825 | .ignore_unknown_fields = true, |
| 1826 | | .errors = &errors, |
| 1826 | .diagnostics = &diagnostics, |
| 1827 | 1827 | }); |
| 1828 | 1828 | try std.testing.expectEqual(Vec2{ .x = 1.0, .y = 2.0 }, parsed); |
| 1829 | 1829 | } |
| ... | ... | @@ -1837,14 +1837,14 @@ test "std.zon structs" { |
| 1837 | 1837 | .gpa = gpa, |
| 1838 | 1838 | .arena = arena, |
| 1839 | 1839 | .source = ".{.x=1.5, .z=2.5}", |
| 1840 | | .errors = &errors, |
| 1840 | .diagnostics = &diagnostics, |
| 1841 | 1841 | }), |
| 1842 | 1842 | ); |
| 1843 | 1843 | try std.testing.expectFmt( |
| 1844 | 1844 | \\input.zon:1:4: error: unexpected field 'x' |
| 1845 | 1845 | \\input.zon:1:4: note: none expected |
| 1846 | 1846 | \\ |
| 1847 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1847 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1848 | 1848 | } |
| 1849 | 1849 | |
| 1850 | 1850 | // Missing field |
| ... | ... | @@ -1856,13 +1856,13 @@ test "std.zon structs" { |
| 1856 | 1856 | .gpa = gpa, |
| 1857 | 1857 | .arena = arena, |
| 1858 | 1858 | .source = ".{.x=1.5}", |
| 1859 | | .errors = &errors, |
| 1859 | .diagnostics = &diagnostics, |
| 1860 | 1860 | }), |
| 1861 | 1861 | ); |
| 1862 | 1862 | try std.testing.expectFmt( |
| 1863 | 1863 | \\input.zon:1:2: error: missing required field y |
| 1864 | 1864 | \\ |
| 1865 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1865 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1866 | 1866 | } |
| 1867 | 1867 | |
| 1868 | 1868 | // Default field |
| ... | ... | @@ -1872,7 +1872,7 @@ test "std.zon structs" { |
| 1872 | 1872 | .gpa = gpa, |
| 1873 | 1873 | .arena = arena, |
| 1874 | 1874 | .source = ".{.x = 1.2}", |
| 1875 | | .errors = &errors, |
| 1875 | .diagnostics = &diagnostics, |
| 1876 | 1876 | }); |
| 1877 | 1877 | try std.testing.expectEqual(Vec2{ .x = 1.2, .y = 1.5 }, parsed); |
| 1878 | 1878 | } |
| ... | ... | @@ -1884,7 +1884,7 @@ test "std.zon structs" { |
| 1884 | 1884 | .gpa = gpa, |
| 1885 | 1885 | .arena = arena, |
| 1886 | 1886 | .source = ".{.x = 1.2}", |
| 1887 | | .errors = &errors, |
| 1887 | .diagnostics = &diagnostics, |
| 1888 | 1888 | }); |
| 1889 | 1889 | try std.testing.expectEqual(Vec2{ .x = 1.2, .y = 1.5 }, parsed); |
| 1890 | 1890 | } |
| ... | ... | @@ -1896,13 +1896,13 @@ test "std.zon structs" { |
| 1896 | 1896 | .gpa = gpa, |
| 1897 | 1897 | .arena = arena, |
| 1898 | 1898 | .source = ".{.x = 1.2, .y = 1.5}", |
| 1899 | | .errors = &errors, |
| 1899 | .diagnostics = &diagnostics, |
| 1900 | 1900 | }); |
| 1901 | 1901 | try std.testing.expectError(error.ParseZon, parsed); |
| 1902 | 1902 | try std.testing.expectFmt( |
| 1903 | 1903 | \\input.zon:1:18: error: cannot initialize comptime field |
| 1904 | 1904 | \\ |
| 1905 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1905 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1906 | 1906 | } |
| 1907 | 1907 | |
| 1908 | 1908 | // Enum field (regression test, we were previously getting the field name in an |
| ... | ... | @@ -1913,7 +1913,7 @@ test "std.zon structs" { |
| 1913 | 1913 | .gpa = gpa, |
| 1914 | 1914 | .arena = arena, |
| 1915 | 1915 | .source = ".{ .x = .x }", |
| 1916 | | .errors = &errors, |
| 1916 | .diagnostics = &diagnostics, |
| 1917 | 1917 | }); |
| 1918 | 1918 | try std.testing.expectEqual(Vec0{ .x = .x }, parsed); |
| 1919 | 1919 | } |
| ... | ... | @@ -1925,7 +1925,7 @@ test "std.zon structs" { |
| 1925 | 1925 | .gpa = gpa, |
| 1926 | 1926 | .arena = arena, |
| 1927 | 1927 | .source = ".{ .@\"x x\" = .@\"x x\" }", |
| 1928 | | .errors = &errors, |
| 1928 | .diagnostics = &diagnostics, |
| 1929 | 1929 | }); |
| 1930 | 1930 | try std.testing.expectEqual(Vec0{ .@"x x" = .@"x x" }, parsed); |
| 1931 | 1931 | } |
| ... | ... | @@ -1938,14 +1938,14 @@ test "std.zon structs" { |
| 1938 | 1938 | .gpa = gpa, |
| 1939 | 1939 | .arena = arena, |
| 1940 | 1940 | .source = "Empty{}", |
| 1941 | | .errors = &errors, |
| 1941 | .diagnostics = &diagnostics, |
| 1942 | 1942 | }); |
| 1943 | 1943 | try std.testing.expectError(error.ParseZon, parsed); |
| 1944 | 1944 | try std.testing.expectFmt( |
| 1945 | 1945 | \\input.zon:1:1: error: types are not available in ZON |
| 1946 | 1946 | \\input.zon:1:1: note: replace the type with '.' |
| 1947 | 1947 | \\ |
| 1948 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1948 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1949 | 1949 | } |
| 1950 | 1950 | |
| 1951 | 1951 | // Arrays |
| ... | ... | @@ -1954,14 +1954,14 @@ test "std.zon structs" { |
| 1954 | 1954 | .gpa = gpa, |
| 1955 | 1955 | .arena = arena, |
| 1956 | 1956 | .source = "[3]u8{1, 2, 3}", |
| 1957 | | .errors = &errors, |
| 1957 | .diagnostics = &diagnostics, |
| 1958 | 1958 | }); |
| 1959 | 1959 | try std.testing.expectError(error.ParseZon, parsed); |
| 1960 | 1960 | try std.testing.expectFmt( |
| 1961 | 1961 | \\input.zon:1:1: error: types are not available in ZON |
| 1962 | 1962 | \\input.zon:1:1: note: replace the type with '.' |
| 1963 | 1963 | \\ |
| 1964 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1964 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1965 | 1965 | } |
| 1966 | 1966 | |
| 1967 | 1967 | // Slices |
| ... | ... | @@ -1970,14 +1970,14 @@ test "std.zon structs" { |
| 1970 | 1970 | .gpa = gpa, |
| 1971 | 1971 | .arena = arena, |
| 1972 | 1972 | .source = "[]u8{1, 2, 3}", |
| 1973 | | .errors = &errors, |
| 1973 | .diagnostics = &diagnostics, |
| 1974 | 1974 | }); |
| 1975 | 1975 | try std.testing.expectError(error.ParseZon, parsed); |
| 1976 | 1976 | try std.testing.expectFmt( |
| 1977 | 1977 | \\input.zon:1:1: error: types are not available in ZON |
| 1978 | 1978 | \\input.zon:1:1: note: replace the type with '.' |
| 1979 | 1979 | \\ |
| 1980 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1980 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1981 | 1981 | } |
| 1982 | 1982 | |
| 1983 | 1983 | // Tuples |
| ... | ... | @@ -1986,14 +1986,14 @@ test "std.zon structs" { |
| 1986 | 1986 | .gpa = gpa, |
| 1987 | 1987 | .arena = arena, |
| 1988 | 1988 | .source = "Tuple{1, 2, 3}", |
| 1989 | | .errors = &errors, |
| 1989 | .diagnostics = &diagnostics, |
| 1990 | 1990 | }); |
| 1991 | 1991 | try std.testing.expectError(error.ParseZon, parsed); |
| 1992 | 1992 | try std.testing.expectFmt( |
| 1993 | 1993 | \\input.zon:1:1: error: types are not available in ZON |
| 1994 | 1994 | \\input.zon:1:1: note: replace the type with '.' |
| 1995 | 1995 | \\ |
| 1996 | | , "{f}", .{errors.fmt("input.zon")}); |
| 1996 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 1997 | 1997 | } |
| 1998 | 1998 | |
| 1999 | 1999 | // Nested |
| ... | ... | @@ -2002,14 +2002,14 @@ test "std.zon structs" { |
| 2002 | 2002 | .gpa = gpa, |
| 2003 | 2003 | .arena = arena, |
| 2004 | 2004 | .source = ".{ .x = Tuple{1, 2, 3} }", |
| 2005 | | .errors = &errors, |
| 2005 | .diagnostics = &diagnostics, |
| 2006 | 2006 | }); |
| 2007 | 2007 | try std.testing.expectError(error.ParseZon, parsed); |
| 2008 | 2008 | try std.testing.expectFmt( |
| 2009 | 2009 | \\input.zon:1:9: error: types are not available in ZON |
| 2010 | 2010 | \\input.zon:1:9: note: replace the type with '.' |
| 2011 | 2011 | \\ |
| 2012 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2012 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2013 | 2013 | } |
| 2014 | 2014 | } |
| 2015 | 2015 | } |
| ... | ... | @@ -2019,7 +2019,7 @@ test "std.zon tuples" { |
| 2019 | 2019 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 2020 | 2020 | defer arena_allocator.deinit(); |
| 2021 | 2021 | const arena = arena_allocator.allocator(); |
| 2022 | | var errors: Errors = .empty; |
| 2022 | var diagnostics: Diagnostics = .empty; |
| 2023 | 2023 | |
| 2024 | 2024 | // Structs (various sizes tested since they're parsed differently) |
| 2025 | 2025 | { |
| ... | ... | @@ -2032,7 +2032,7 @@ test "std.zon tuples" { |
| 2032 | 2032 | .gpa = gpa, |
| 2033 | 2033 | .arena = arena, |
| 2034 | 2034 | .source = ".{}", |
| 2035 | | .errors = &errors, |
| 2035 | .diagnostics = &diagnostics, |
| 2036 | 2036 | }); |
| 2037 | 2037 | try std.testing.expectEqual(Tuple0{}, zero); |
| 2038 | 2038 | |
| ... | ... | @@ -2040,7 +2040,7 @@ test "std.zon tuples" { |
| 2040 | 2040 | .gpa = gpa, |
| 2041 | 2041 | .arena = arena, |
| 2042 | 2042 | .source = ".{1.2}", |
| 2043 | | .errors = &errors, |
| 2043 | .diagnostics = &diagnostics, |
| 2044 | 2044 | }); |
| 2045 | 2045 | try std.testing.expectEqual(Tuple1{1.2}, one); |
| 2046 | 2046 | |
| ... | ... | @@ -2048,7 +2048,7 @@ test "std.zon tuples" { |
| 2048 | 2048 | .gpa = gpa, |
| 2049 | 2049 | .arena = arena, |
| 2050 | 2050 | .source = ".{1.2, true}", |
| 2051 | | .errors = &errors, |
| 2051 | .diagnostics = &diagnostics, |
| 2052 | 2052 | }); |
| 2053 | 2053 | try std.testing.expectEqual(Tuple2{ 1.2, true }, two); |
| 2054 | 2054 | |
| ... | ... | @@ -2056,7 +2056,7 @@ test "std.zon tuples" { |
| 2056 | 2056 | .gpa = gpa, |
| 2057 | 2057 | .arena = arena, |
| 2058 | 2058 | .source = ".{1.2, false, 3}", |
| 2059 | | .errors = &errors, |
| 2059 | .diagnostics = &diagnostics, |
| 2060 | 2060 | }); |
| 2061 | 2061 | try std.testing.expectEqual(Tuple3{ 1.2, false, 3 }, three); |
| 2062 | 2062 | } |
| ... | ... | @@ -2068,7 +2068,7 @@ test "std.zon tuples" { |
| 2068 | 2068 | .gpa = gpa, |
| 2069 | 2069 | .arena = arena, |
| 2070 | 2070 | .source = ".{\"hello\", \"world\"}", |
| 2071 | | .errors = &errors, |
| 2071 | .diagnostics = &diagnostics, |
| 2072 | 2072 | }); |
| 2073 | 2073 | try std.testing.expectEqualDeep(Tuple{ "hello", "world" }, parsed); |
| 2074 | 2074 | } |
| ... | ... | @@ -2082,13 +2082,13 @@ test "std.zon tuples" { |
| 2082 | 2082 | .gpa = gpa, |
| 2083 | 2083 | .arena = arena, |
| 2084 | 2084 | .source = ".{0.5, true, 123}", |
| 2085 | | .errors = &errors, |
| 2085 | .diagnostics = &diagnostics, |
| 2086 | 2086 | }), |
| 2087 | 2087 | ); |
| 2088 | 2088 | try std.testing.expectFmt( |
| 2089 | 2089 | \\input.zon:1:14: error: index 2 outside of tuple length 2 |
| 2090 | 2090 | \\ |
| 2091 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2091 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2092 | 2092 | } |
| 2093 | 2093 | |
| 2094 | 2094 | // Extra field |
| ... | ... | @@ -2100,13 +2100,13 @@ test "std.zon tuples" { |
| 2100 | 2100 | .gpa = gpa, |
| 2101 | 2101 | .arena = arena, |
| 2102 | 2102 | .source = ".{0.5}", |
| 2103 | | .errors = &errors, |
| 2103 | .diagnostics = &diagnostics, |
| 2104 | 2104 | }), |
| 2105 | 2105 | ); |
| 2106 | 2106 | try std.testing.expectFmt( |
| 2107 | 2107 | \\input.zon:1:2: error: missing tuple field with index 1 |
| 2108 | 2108 | \\ |
| 2109 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2109 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2110 | 2110 | } |
| 2111 | 2111 | |
| 2112 | 2112 | // Tuple with unexpected field names |
| ... | ... | @@ -2118,13 +2118,13 @@ test "std.zon tuples" { |
| 2118 | 2118 | .gpa = gpa, |
| 2119 | 2119 | .arena = arena, |
| 2120 | 2120 | .source = ".{.foo = 10.0}", |
| 2121 | | .errors = &errors, |
| 2121 | .diagnostics = &diagnostics, |
| 2122 | 2122 | }), |
| 2123 | 2123 | ); |
| 2124 | 2124 | try std.testing.expectFmt( |
| 2125 | 2125 | \\input.zon:1:2: error: expected tuple |
| 2126 | 2126 | \\ |
| 2127 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2127 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2128 | 2128 | } |
| 2129 | 2129 | |
| 2130 | 2130 | // Struct with missing field names |
| ... | ... | @@ -2136,13 +2136,13 @@ test "std.zon tuples" { |
| 2136 | 2136 | .gpa = gpa, |
| 2137 | 2137 | .arena = arena, |
| 2138 | 2138 | .source = ".{10.0}", |
| 2139 | | .errors = &errors, |
| 2139 | .diagnostics = &diagnostics, |
| 2140 | 2140 | }), |
| 2141 | 2141 | ); |
| 2142 | 2142 | try std.testing.expectFmt( |
| 2143 | 2143 | \\input.zon:1:2: error: expected struct |
| 2144 | 2144 | \\ |
| 2145 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2145 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2146 | 2146 | } |
| 2147 | 2147 | |
| 2148 | 2148 | // Comptime field |
| ... | ... | @@ -2152,7 +2152,7 @@ test "std.zon tuples" { |
| 2152 | 2152 | .gpa = gpa, |
| 2153 | 2153 | .arena = arena, |
| 2154 | 2154 | .source = ".{ 1.2 }", |
| 2155 | | .errors = &errors, |
| 2155 | .diagnostics = &diagnostics, |
| 2156 | 2156 | }); |
| 2157 | 2157 | try std.testing.expectEqual(Vec2{ 1.2, 1.5 }, parsed); |
| 2158 | 2158 | } |
| ... | ... | @@ -2164,13 +2164,13 @@ test "std.zon tuples" { |
| 2164 | 2164 | .gpa = gpa, |
| 2165 | 2165 | .arena = arena, |
| 2166 | 2166 | .source = ".{ 1.2, 1.5}", |
| 2167 | | .errors = &errors, |
| 2167 | .diagnostics = &diagnostics, |
| 2168 | 2168 | }); |
| 2169 | 2169 | try std.testing.expectError(error.ParseZon, parsed); |
| 2170 | 2170 | try std.testing.expectFmt( |
| 2171 | 2171 | \\input.zon:1:9: error: cannot initialize comptime field |
| 2172 | 2172 | \\ |
| 2173 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2173 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2174 | 2174 | } |
| 2175 | 2175 | } |
| 2176 | 2176 | |
| ... | ... | @@ -2180,7 +2180,7 @@ test "std.zon arrays and slices" { |
| 2180 | 2180 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 2181 | 2181 | defer arena_allocator.deinit(); |
| 2182 | 2182 | const arena = arena_allocator.allocator(); |
| 2183 | | var errors: Errors = .empty; |
| 2183 | var diagnostics: Diagnostics = .empty; |
| 2184 | 2184 | |
| 2185 | 2185 | // Literals |
| 2186 | 2186 | { |
| ... | ... | @@ -2190,7 +2190,7 @@ test "std.zon arrays and slices" { |
| 2190 | 2190 | .gpa = gpa, |
| 2191 | 2191 | .arena = arena, |
| 2192 | 2192 | .source = ".{}", |
| 2193 | | .errors = &errors, |
| 2193 | .diagnostics = &diagnostics, |
| 2194 | 2194 | }); |
| 2195 | 2195 | try std.testing.expectEqualSlices(u8, &@as([0]u8, .{}), &zero); |
| 2196 | 2196 | |
| ... | ... | @@ -2198,7 +2198,7 @@ test "std.zon arrays and slices" { |
| 2198 | 2198 | .gpa = gpa, |
| 2199 | 2199 | .arena = arena, |
| 2200 | 2200 | .source = ".{'a'}", |
| 2201 | | .errors = &errors, |
| 2201 | .diagnostics = &diagnostics, |
| 2202 | 2202 | }); |
| 2203 | 2203 | try std.testing.expectEqualSlices(u8, &@as([1]u8, .{'a'}), &one); |
| 2204 | 2204 | |
| ... | ... | @@ -2206,7 +2206,7 @@ test "std.zon arrays and slices" { |
| 2206 | 2206 | .gpa = gpa, |
| 2207 | 2207 | .arena = arena, |
| 2208 | 2208 | .source = ".{'a', 'b'}", |
| 2209 | | .errors = &errors, |
| 2209 | .diagnostics = &diagnostics, |
| 2210 | 2210 | }); |
| 2211 | 2211 | try std.testing.expectEqualSlices(u8, &@as([2]u8, .{ 'a', 'b' }), &two); |
| 2212 | 2212 | |
| ... | ... | @@ -2214,7 +2214,7 @@ test "std.zon arrays and slices" { |
| 2214 | 2214 | .gpa = gpa, |
| 2215 | 2215 | .arena = arena, |
| 2216 | 2216 | .source = ".{'a', 'b',}", |
| 2217 | | .errors = &errors, |
| 2217 | .diagnostics = &diagnostics, |
| 2218 | 2218 | }); |
| 2219 | 2219 | try std.testing.expectEqualSlices(u8, &@as([2]u8, .{ 'a', 'b' }), &two_comma); |
| 2220 | 2220 | |
| ... | ... | @@ -2222,7 +2222,7 @@ test "std.zon arrays and slices" { |
| 2222 | 2222 | .gpa = gpa, |
| 2223 | 2223 | .arena = arena, |
| 2224 | 2224 | .source = ".{'a', 'b', 'c'}", |
| 2225 | | .errors = &errors, |
| 2225 | .diagnostics = &diagnostics, |
| 2226 | 2226 | }); |
| 2227 | 2227 | try std.testing.expectEqualSlices(u8, &.{ 'a', 'b', 'c' }, &three); |
| 2228 | 2228 | |
| ... | ... | @@ -2230,7 +2230,7 @@ test "std.zon arrays and slices" { |
| 2230 | 2230 | .gpa = gpa, |
| 2231 | 2231 | .arena = arena, |
| 2232 | 2232 | .source = ".{'a', 'b', 'c'}", |
| 2233 | | .errors = &errors, |
| 2233 | .diagnostics = &diagnostics, |
| 2234 | 2234 | }); |
| 2235 | 2235 | const expected_sentinel: [3:'z']u8 = .{ 'a', 'b', 'c' }; |
| 2236 | 2236 | try std.testing.expectEqualSlices(u8, &expected_sentinel, &sentinel); |
| ... | ... | @@ -2242,7 +2242,7 @@ test "std.zon arrays and slices" { |
| 2242 | 2242 | .gpa = gpa, |
| 2243 | 2243 | .arena = arena, |
| 2244 | 2244 | .source = ".{}", |
| 2245 | | .errors = &errors, |
| 2245 | .diagnostics = &diagnostics, |
| 2246 | 2246 | }); |
| 2247 | 2247 | try std.testing.expectEqualSlices(u8, @as([]const u8, &.{}), zero); |
| 2248 | 2248 | |
| ... | ... | @@ -2250,7 +2250,7 @@ test "std.zon arrays and slices" { |
| 2250 | 2250 | .gpa = gpa, |
| 2251 | 2251 | .arena = arena, |
| 2252 | 2252 | .source = ".{'a'}", |
| 2253 | | .errors = &errors, |
| 2253 | .diagnostics = &diagnostics, |
| 2254 | 2254 | }); |
| 2255 | 2255 | try std.testing.expectEqualSlices(u8, &.{'a'}, one); |
| 2256 | 2256 | |
| ... | ... | @@ -2258,7 +2258,7 @@ test "std.zon arrays and slices" { |
| 2258 | 2258 | .gpa = gpa, |
| 2259 | 2259 | .arena = arena, |
| 2260 | 2260 | .source = ".{'a', 'b'}", |
| 2261 | | .errors = &errors, |
| 2261 | .diagnostics = &diagnostics, |
| 2262 | 2262 | }); |
| 2263 | 2263 | try std.testing.expectEqualSlices(u8, &.{ 'a', 'b' }, two); |
| 2264 | 2264 | |
| ... | ... | @@ -2266,7 +2266,7 @@ test "std.zon arrays and slices" { |
| 2266 | 2266 | .gpa = gpa, |
| 2267 | 2267 | .arena = arena, |
| 2268 | 2268 | .source = ".{'a', 'b',}", |
| 2269 | | .errors = &errors, |
| 2269 | .diagnostics = &diagnostics, |
| 2270 | 2270 | }); |
| 2271 | 2271 | try std.testing.expectEqualSlices(u8, &.{ 'a', 'b' }, two_comma); |
| 2272 | 2272 | |
| ... | ... | @@ -2274,7 +2274,7 @@ test "std.zon arrays and slices" { |
| 2274 | 2274 | .gpa = gpa, |
| 2275 | 2275 | .arena = arena, |
| 2276 | 2276 | .source = ".{'a', 'b', 'c'}", |
| 2277 | | .errors = &errors, |
| 2277 | .diagnostics = &diagnostics, |
| 2278 | 2278 | }); |
| 2279 | 2279 | try std.testing.expectEqualSlices(u8, &.{ 'a', 'b', 'c' }, three); |
| 2280 | 2280 | |
| ... | ... | @@ -2282,7 +2282,7 @@ test "std.zon arrays and slices" { |
| 2282 | 2282 | .gpa = gpa, |
| 2283 | 2283 | .arena = arena, |
| 2284 | 2284 | .source = ".{'a', 'b', 'c'}", |
| 2285 | | .errors = &errors, |
| 2285 | .diagnostics = &diagnostics, |
| 2286 | 2286 | }); |
| 2287 | 2287 | const expected_sentinel: [:'z']const u8 = &.{ 'a', 'b', 'c' }; |
| 2288 | 2288 | try std.testing.expectEqualSlices(u8, expected_sentinel, sentinel); |
| ... | ... | @@ -2297,7 +2297,7 @@ test "std.zon arrays and slices" { |
| 2297 | 2297 | .gpa = gpa, |
| 2298 | 2298 | .arena = arena, |
| 2299 | 2299 | .source = ".{\"abc\"}", |
| 2300 | | .errors = &errors, |
| 2300 | .diagnostics = &diagnostics, |
| 2301 | 2301 | }); |
| 2302 | 2302 | const expected: [1][]const u8 = .{"abc"}; |
| 2303 | 2303 | try std.testing.expectEqualDeep(expected, parsed); |
| ... | ... | @@ -2309,7 +2309,7 @@ test "std.zon arrays and slices" { |
| 2309 | 2309 | .gpa = gpa, |
| 2310 | 2310 | .arena = arena, |
| 2311 | 2311 | .source = ".{\"abc\"}", |
| 2312 | | .errors = &errors, |
| 2312 | .diagnostics = &diagnostics, |
| 2313 | 2313 | }); |
| 2314 | 2314 | const expected: []const []const u8 = &.{"abc"}; |
| 2315 | 2315 | try std.testing.expectEqualDeep(expected, parsed); |
| ... | ... | @@ -2324,7 +2324,7 @@ test "std.zon arrays and slices" { |
| 2324 | 2324 | .gpa = gpa, |
| 2325 | 2325 | .arena = arena, |
| 2326 | 2326 | .source = ".{1}", |
| 2327 | | .errors = &errors, |
| 2327 | .diagnostics = &diagnostics, |
| 2328 | 2328 | }); |
| 2329 | 2329 | try std.testing.expectEqual(@as(usize, 1), sentinel.len); |
| 2330 | 2330 | try std.testing.expectEqual(@as(u8, 1), sentinel[0]); |
| ... | ... | @@ -2337,7 +2337,7 @@ test "std.zon arrays and slices" { |
| 2337 | 2337 | .gpa = gpa, |
| 2338 | 2338 | .arena = arena, |
| 2339 | 2339 | .source = ".{1}", |
| 2340 | | .errors = &errors, |
| 2340 | .diagnostics = &diagnostics, |
| 2341 | 2341 | }); |
| 2342 | 2342 | try std.testing.expectEqual(@as(usize, 1), sentinel.len); |
| 2343 | 2343 | try std.testing.expectEqual(@as(u8, 1), sentinel[0]); |
| ... | ... | @@ -2353,13 +2353,13 @@ test "std.zon arrays and slices" { |
| 2353 | 2353 | .gpa = gpa, |
| 2354 | 2354 | .arena = arena, |
| 2355 | 2355 | .source = ".{'a', 'b', 'c'}", |
| 2356 | | .errors = &errors, |
| 2356 | .diagnostics = &diagnostics, |
| 2357 | 2357 | }), |
| 2358 | 2358 | ); |
| 2359 | 2359 | try std.testing.expectFmt( |
| 2360 | 2360 | \\input.zon:1:3: error: index 0 outside of array of length 0 |
| 2361 | 2361 | \\ |
| 2362 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2362 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2363 | 2363 | } |
| 2364 | 2364 | |
| 2365 | 2365 | // Expect 1 find 2 |
| ... | ... | @@ -2370,13 +2370,13 @@ test "std.zon arrays and slices" { |
| 2370 | 2370 | .gpa = gpa, |
| 2371 | 2371 | .arena = arena, |
| 2372 | 2372 | .source = ".{'a', 'b'}", |
| 2373 | | .errors = &errors, |
| 2373 | .diagnostics = &diagnostics, |
| 2374 | 2374 | }), |
| 2375 | 2375 | ); |
| 2376 | 2376 | try std.testing.expectFmt( |
| 2377 | 2377 | \\input.zon:1:8: error: index 1 outside of array of length 1 |
| 2378 | 2378 | \\ |
| 2379 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2379 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2380 | 2380 | } |
| 2381 | 2381 | |
| 2382 | 2382 | // Expect 2 find 1 |
| ... | ... | @@ -2387,13 +2387,13 @@ test "std.zon arrays and slices" { |
| 2387 | 2387 | .gpa = gpa, |
| 2388 | 2388 | .arena = arena, |
| 2389 | 2389 | .source = ".{'a'}", |
| 2390 | | .errors = &errors, |
| 2390 | .diagnostics = &diagnostics, |
| 2391 | 2391 | }), |
| 2392 | 2392 | ); |
| 2393 | 2393 | try std.testing.expectFmt( |
| 2394 | 2394 | \\input.zon:1:2: error: expected 2 array elements; found 1 |
| 2395 | 2395 | \\ |
| 2396 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2396 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2397 | 2397 | } |
| 2398 | 2398 | |
| 2399 | 2399 | // Expect 3 find 0 |
| ... | ... | @@ -2404,13 +2404,13 @@ test "std.zon arrays and slices" { |
| 2404 | 2404 | .gpa = gpa, |
| 2405 | 2405 | .arena = arena, |
| 2406 | 2406 | .source = ".{}", |
| 2407 | | .errors = &errors, |
| 2407 | .diagnostics = &diagnostics, |
| 2408 | 2408 | }), |
| 2409 | 2409 | ); |
| 2410 | 2410 | try std.testing.expectFmt( |
| 2411 | 2411 | \\input.zon:1:2: error: expected 3 array elements; found 0 |
| 2412 | 2412 | \\ |
| 2413 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2413 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2414 | 2414 | } |
| 2415 | 2415 | |
| 2416 | 2416 | // Wrong inner type |
| ... | ... | @@ -2423,13 +2423,13 @@ test "std.zon arrays and slices" { |
| 2423 | 2423 | .gpa = gpa, |
| 2424 | 2424 | .arena = arena, |
| 2425 | 2425 | .source = ".{'a', 'b', 'c'}", |
| 2426 | | .errors = &errors, |
| 2426 | .diagnostics = &diagnostics, |
| 2427 | 2427 | }), |
| 2428 | 2428 | ); |
| 2429 | 2429 | try std.testing.expectFmt( |
| 2430 | 2430 | \\input.zon:1:3: error: expected type 'bool' |
| 2431 | 2431 | \\ |
| 2432 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2432 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2433 | 2433 | } |
| 2434 | 2434 | |
| 2435 | 2435 | // Slice |
| ... | ... | @@ -2440,13 +2440,13 @@ test "std.zon arrays and slices" { |
| 2440 | 2440 | .gpa = gpa, |
| 2441 | 2441 | .arena = arena, |
| 2442 | 2442 | .source = ".{'a', 'b', 'c'}", |
| 2443 | | .errors = &errors, |
| 2443 | .diagnostics = &diagnostics, |
| 2444 | 2444 | }), |
| 2445 | 2445 | ); |
| 2446 | 2446 | try std.testing.expectFmt( |
| 2447 | 2447 | \\input.zon:1:3: error: expected type 'bool' |
| 2448 | 2448 | \\ |
| 2449 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2449 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2450 | 2450 | } |
| 2451 | 2451 | } |
| 2452 | 2452 | |
| ... | ... | @@ -2460,25 +2460,25 @@ test "std.zon arrays and slices" { |
| 2460 | 2460 | .gpa = gpa, |
| 2461 | 2461 | .arena = arena, |
| 2462 | 2462 | .source = "'a'", |
| 2463 | | .errors = &errors, |
| 2463 | .diagnostics = &diagnostics, |
| 2464 | 2464 | }), |
| 2465 | 2465 | ); |
| 2466 | 2466 | try std.testing.expectFmt( |
| 2467 | 2467 | \\input.zon:1:1: error: expected array |
| 2468 | 2468 | \\ |
| 2469 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2469 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2470 | 2470 | } |
| 2471 | 2471 | |
| 2472 | 2472 | // Slice |
| 2473 | 2473 | { |
| 2474 | 2474 | try std.testing.expectError( |
| 2475 | 2475 | error.ParseZon, |
| 2476 | | fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = "'a'", .errors = &errors }), |
| 2476 | fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = "'a'", .diagnostics = &diagnostics }), |
| 2477 | 2477 | ); |
| 2478 | 2478 | try std.testing.expectFmt( |
| 2479 | 2479 | \\input.zon:1:1: error: expected array |
| 2480 | 2480 | \\ |
| 2481 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2481 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2482 | 2482 | } |
| 2483 | 2483 | } |
| 2484 | 2484 | |
| ... | ... | @@ -2486,12 +2486,12 @@ test "std.zon arrays and slices" { |
| 2486 | 2486 | { |
| 2487 | 2487 | try std.testing.expectError( |
| 2488 | 2488 | error.ParseZon, |
| 2489 | | fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = " &.{'a', 'b', 'c'}", .errors = &errors }), |
| 2489 | fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = " &.{'a', 'b', 'c'}", .diagnostics = &diagnostics }), |
| 2490 | 2490 | ); |
| 2491 | 2491 | try std.testing.expectFmt( |
| 2492 | 2492 | \\input.zon:1:3: error: pointers are not available in ZON |
| 2493 | 2493 | \\ |
| 2494 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2494 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2495 | 2495 | } |
| 2496 | 2496 | } |
| 2497 | 2497 | |
| ... | ... | @@ -2500,7 +2500,7 @@ test "std.zon string literal" { |
| 2500 | 2500 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 2501 | 2501 | defer arena_allocator.deinit(); |
| 2502 | 2502 | const arena = arena_allocator.allocator(); |
| 2503 | | var errors: Errors = .empty; |
| 2503 | var diagnostics: Diagnostics = .empty; |
| 2504 | 2504 | |
| 2505 | 2505 | // Basic string literal |
| 2506 | 2506 | { |
| ... | ... | @@ -2508,7 +2508,7 @@ test "std.zon string literal" { |
| 2508 | 2508 | .gpa = gpa, |
| 2509 | 2509 | .arena = arena, |
| 2510 | 2510 | .source = "\"abc\"", |
| 2511 | | .errors = &errors, |
| 2511 | .diagnostics = &diagnostics, |
| 2512 | 2512 | }); |
| 2513 | 2513 | try std.testing.expectEqualStrings(@as([]const u8, "abc"), parsed); |
| 2514 | 2514 | } |
| ... | ... | @@ -2519,7 +2519,7 @@ test "std.zon string literal" { |
| 2519 | 2519 | .gpa = gpa, |
| 2520 | 2520 | .arena = arena, |
| 2521 | 2521 | .source = "\"ab\\nc\"", |
| 2522 | | .errors = &errors, |
| 2522 | .diagnostics = &diagnostics, |
| 2523 | 2523 | }); |
| 2524 | 2524 | try std.testing.expectEqualStrings(@as([]const u8, "ab\nc"), parsed); |
| 2525 | 2525 | } |
| ... | ... | @@ -2530,7 +2530,7 @@ test "std.zon string literal" { |
| 2530 | 2530 | .gpa = gpa, |
| 2531 | 2531 | .arena = arena, |
| 2532 | 2532 | .source = "\"ab\\x00c\"", |
| 2533 | | .errors = &errors, |
| 2533 | .diagnostics = &diagnostics, |
| 2534 | 2534 | }); |
| 2535 | 2535 | try std.testing.expectEqualStrings(@as([]const u8, "ab\x00c"), parsed); |
| 2536 | 2536 | } |
| ... | ... | @@ -2540,23 +2540,23 @@ test "std.zon string literal" { |
| 2540 | 2540 | { |
| 2541 | 2541 | try std.testing.expectError( |
| 2542 | 2542 | error.ParseZon, |
| 2543 | | fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = "\"abcd\"", .errors = &errors }), |
| 2543 | fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = "\"abcd\"", .diagnostics = &diagnostics }), |
| 2544 | 2544 | ); |
| 2545 | 2545 | try std.testing.expectFmt( |
| 2546 | 2546 | \\input.zon:1:1: error: expected array |
| 2547 | 2547 | \\ |
| 2548 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2548 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2549 | 2549 | } |
| 2550 | 2550 | |
| 2551 | 2551 | { |
| 2552 | 2552 | try std.testing.expectError( |
| 2553 | 2553 | error.ParseZon, |
| 2554 | | fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\abcd", .errors = &errors }), |
| 2554 | fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\abcd", .diagnostics = &diagnostics }), |
| 2555 | 2555 | ); |
| 2556 | 2556 | try std.testing.expectFmt( |
| 2557 | 2557 | \\input.zon:1:1: error: expected array |
| 2558 | 2558 | \\ |
| 2559 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2559 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2560 | 2560 | } |
| 2561 | 2561 | } |
| 2562 | 2562 | |
| ... | ... | @@ -2573,13 +2573,13 @@ test "std.zon string literal" { |
| 2573 | 2573 | .gpa = gpa, |
| 2574 | 2574 | .arena = arena, |
| 2575 | 2575 | .source = "\"abcd\"", |
| 2576 | | .errors = &errors, |
| 2576 | .diagnostics = &diagnostics, |
| 2577 | 2577 | }), |
| 2578 | 2578 | ); |
| 2579 | 2579 | try std.testing.expectFmt( |
| 2580 | 2580 | \\input.zon:1:1: error: expected array |
| 2581 | 2581 | \\ |
| 2582 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2582 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2583 | 2583 | } |
| 2584 | 2584 | |
| 2585 | 2585 | { |
| ... | ... | @@ -2589,13 +2589,13 @@ test "std.zon string literal" { |
| 2589 | 2589 | .gpa = gpa, |
| 2590 | 2590 | .arena = arena, |
| 2591 | 2591 | .source = "\\\\abcd", |
| 2592 | | .errors = &errors, |
| 2592 | .diagnostics = &diagnostics, |
| 2593 | 2593 | }), |
| 2594 | 2594 | ); |
| 2595 | 2595 | try std.testing.expectFmt( |
| 2596 | 2596 | \\input.zon:1:1: error: expected array |
| 2597 | 2597 | \\ |
| 2598 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2598 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2599 | 2599 | } |
| 2600 | 2600 | } |
| 2601 | 2601 | |
| ... | ... | @@ -2606,7 +2606,7 @@ test "std.zon string literal" { |
| 2606 | 2606 | .gpa = gpa, |
| 2607 | 2607 | .arena = arena, |
| 2608 | 2608 | .source = "\"abc\"", |
| 2609 | | .errors = &errors, |
| 2609 | .diagnostics = &diagnostics, |
| 2610 | 2610 | }); |
| 2611 | 2611 | try std.testing.expectEqualStrings("abc", parsed); |
| 2612 | 2612 | try std.testing.expectEqual(@as(u8, 0), parsed[3]); |
| ... | ... | @@ -2617,7 +2617,7 @@ test "std.zon string literal" { |
| 2617 | 2617 | .gpa = gpa, |
| 2618 | 2618 | .arena = arena, |
| 2619 | 2619 | .source = "\\\\abc", |
| 2620 | | .errors = &errors, |
| 2620 | .diagnostics = &diagnostics, |
| 2621 | 2621 | }); |
| 2622 | 2622 | try std.testing.expectEqualStrings("abc", parsed); |
| 2623 | 2623 | try std.testing.expectEqual(@as(u8, 0), parsed[3]); |
| ... | ... | @@ -2629,23 +2629,23 @@ test "std.zon string literal" { |
| 2629 | 2629 | { |
| 2630 | 2630 | try std.testing.expectError( |
| 2631 | 2631 | error.ParseZon, |
| 2632 | | fromSlice([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\"foo\"", .errors = &errors }), |
| 2632 | fromSlice([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\"foo\"", .diagnostics = &diagnostics }), |
| 2633 | 2633 | ); |
| 2634 | 2634 | try std.testing.expectFmt( |
| 2635 | 2635 | \\input.zon:1:1: error: expected array |
| 2636 | 2636 | \\ |
| 2637 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2637 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2638 | 2638 | } |
| 2639 | 2639 | |
| 2640 | 2640 | { |
| 2641 | 2641 | try std.testing.expectError( |
| 2642 | 2642 | error.ParseZon, |
| 2643 | | fromSlice([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\foo", .errors = &errors }), |
| 2643 | fromSlice([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\foo", .diagnostics = &diagnostics }), |
| 2644 | 2644 | ); |
| 2645 | 2645 | try std.testing.expectFmt( |
| 2646 | 2646 | \\input.zon:1:1: error: expected array |
| 2647 | 2647 | \\ |
| 2648 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2648 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2649 | 2649 | } |
| 2650 | 2650 | } |
| 2651 | 2651 | |
| ... | ... | @@ -2653,36 +2653,36 @@ test "std.zon string literal" { |
| 2653 | 2653 | { |
| 2654 | 2654 | try std.testing.expectError( |
| 2655 | 2655 | error.ParseZon, |
| 2656 | | fromSlice([]const u8, .{ .gpa = gpa, .arena = arena, .source = "true", .errors = &errors }), |
| 2656 | fromSlice([]const u8, .{ .gpa = gpa, .arena = arena, .source = "true", .diagnostics = &diagnostics }), |
| 2657 | 2657 | ); |
| 2658 | 2658 | try std.testing.expectFmt( |
| 2659 | 2659 | \\input.zon:1:1: error: expected string |
| 2660 | 2660 | \\ |
| 2661 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2661 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2662 | 2662 | } |
| 2663 | 2663 | |
| 2664 | 2664 | // Expecting string literal, getting an incompatible tuple |
| 2665 | 2665 | { |
| 2666 | 2666 | try std.testing.expectError( |
| 2667 | 2667 | error.ParseZon, |
| 2668 | | fromSlice([]const u8, .{ .gpa = gpa, .arena = arena, .source = ".{false}", .errors = &errors }), |
| 2668 | fromSlice([]const u8, .{ .gpa = gpa, .arena = arena, .source = ".{false}", .diagnostics = &diagnostics }), |
| 2669 | 2669 | ); |
| 2670 | 2670 | try std.testing.expectFmt( |
| 2671 | 2671 | \\input.zon:1:3: error: expected type 'u8' |
| 2672 | 2672 | \\ |
| 2673 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2673 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2674 | 2674 | } |
| 2675 | 2675 | |
| 2676 | 2676 | // Invalid string literal |
| 2677 | 2677 | { |
| 2678 | 2678 | try std.testing.expectError( |
| 2679 | 2679 | error.ParseZon, |
| 2680 | | fromSlice([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"\\a\"", .errors = &errors }), |
| 2680 | fromSlice([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"\\a\"", .diagnostics = &diagnostics }), |
| 2681 | 2681 | ); |
| 2682 | 2682 | try std.testing.expectFmt( |
| 2683 | 2683 | \\input.zon:1:3: error: invalid escape character: 'a' |
| 2684 | 2684 | \\ |
| 2685 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2685 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2686 | 2686 | } |
| 2687 | 2687 | |
| 2688 | 2688 | // Slice wrong child type |
| ... | ... | @@ -2690,23 +2690,23 @@ test "std.zon string literal" { |
| 2690 | 2690 | { |
| 2691 | 2691 | try std.testing.expectError( |
| 2692 | 2692 | error.ParseZon, |
| 2693 | | fromSlice([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"a\"", .errors = &errors }), |
| 2693 | fromSlice([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"a\"", .diagnostics = &diagnostics }), |
| 2694 | 2694 | ); |
| 2695 | 2695 | try std.testing.expectFmt( |
| 2696 | 2696 | \\input.zon:1:1: error: expected array |
| 2697 | 2697 | \\ |
| 2698 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2698 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2699 | 2699 | } |
| 2700 | 2700 | |
| 2701 | 2701 | { |
| 2702 | 2702 | try std.testing.expectError( |
| 2703 | 2703 | error.ParseZon, |
| 2704 | | fromSlice([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\\\\a", .errors = &errors }), |
| 2704 | fromSlice([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\\\\a", .diagnostics = &diagnostics }), |
| 2705 | 2705 | ); |
| 2706 | 2706 | try std.testing.expectFmt( |
| 2707 | 2707 | \\input.zon:1:1: error: expected array |
| 2708 | 2708 | \\ |
| 2709 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2709 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2710 | 2710 | } |
| 2711 | 2711 | } |
| 2712 | 2712 | |
| ... | ... | @@ -2719,13 +2719,13 @@ test "std.zon string literal" { |
| 2719 | 2719 | .gpa = gpa, |
| 2720 | 2720 | .arena = arena, |
| 2721 | 2721 | .source = "\"abc\"", |
| 2722 | | .errors = &errors, |
| 2722 | .diagnostics = &diagnostics, |
| 2723 | 2723 | }), |
| 2724 | 2724 | ); |
| 2725 | 2725 | try std.testing.expectFmt( |
| 2726 | 2726 | \\input.zon:1:1: error: expected array |
| 2727 | 2727 | \\ |
| 2728 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2728 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2729 | 2729 | } |
| 2730 | 2730 | |
| 2731 | 2731 | { |
| ... | ... | @@ -2735,13 +2735,13 @@ test "std.zon string literal" { |
| 2735 | 2735 | .gpa = gpa, |
| 2736 | 2736 | .arena = arena, |
| 2737 | 2737 | .source = "\\\\abc", |
| 2738 | | .errors = &errors, |
| 2738 | .diagnostics = &diagnostics, |
| 2739 | 2739 | }), |
| 2740 | 2740 | ); |
| 2741 | 2741 | try std.testing.expectFmt( |
| 2742 | 2742 | \\input.zon:1:1: error: expected array |
| 2743 | 2743 | \\ |
| 2744 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2744 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2745 | 2745 | } |
| 2746 | 2746 | } |
| 2747 | 2747 | |
| ... | ... | @@ -2775,7 +2775,7 @@ test "std.zon string literal" { |
| 2775 | 2775 | \\ \\and this. |
| 2776 | 2776 | \\} |
| 2777 | 2777 | , |
| 2778 | | .errors = &errors, |
| 2778 | .diagnostics = &diagnostics, |
| 2779 | 2779 | }); |
| 2780 | 2780 | try std.testing.expectEqualStrings( |
| 2781 | 2781 | "hello, world!\nthis is a multiline string!\n\n...", |
| ... | ... | @@ -2792,7 +2792,7 @@ test "std.zon enum literals" { |
| 2792 | 2792 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 2793 | 2793 | defer arena_allocator.deinit(); |
| 2794 | 2794 | const arena = arena_allocator.allocator(); |
| 2795 | | var errors: Errors = .empty; |
| 2795 | var diagnostics: Diagnostics = .empty; |
| 2796 | 2796 | |
| 2797 | 2797 | const Enum = enum { |
| 2798 | 2798 | foo, |
| ... | ... | @@ -2806,19 +2806,19 @@ test "std.zon enum literals" { |
| 2806 | 2806 | .gpa = gpa, |
| 2807 | 2807 | .arena = arena, |
| 2808 | 2808 | .source = ".foo", |
| 2809 | | .errors = &errors, |
| 2809 | .diagnostics = &diagnostics, |
| 2810 | 2810 | })); |
| 2811 | 2811 | try std.testing.expectEqual(Enum.bar, try fromSliceNoAlloc(Enum, .{ |
| 2812 | 2812 | .gpa = gpa, |
| 2813 | 2813 | .arena = arena, |
| 2814 | 2814 | .source = ".bar", |
| 2815 | | .errors = &errors, |
| 2815 | .diagnostics = &diagnostics, |
| 2816 | 2816 | })); |
| 2817 | 2817 | try std.testing.expectEqual(Enum.baz, try fromSliceNoAlloc(Enum, .{ |
| 2818 | 2818 | .gpa = gpa, |
| 2819 | 2819 | .arena = arena, |
| 2820 | 2820 | .source = ".baz", |
| 2821 | | .errors = &errors, |
| 2821 | .diagnostics = &diagnostics, |
| 2822 | 2822 | })); |
| 2823 | 2823 | try std.testing.expectEqual( |
| 2824 | 2824 | Enum.@"ab\nc", |
| ... | ... | @@ -2826,7 +2826,7 @@ test "std.zon enum literals" { |
| 2826 | 2826 | .gpa = gpa, |
| 2827 | 2827 | .arena = arena, |
| 2828 | 2828 | .source = ".@\"ab\\nc\"", |
| 2829 | | .errors = &errors, |
| 2829 | .diagnostics = &diagnostics, |
| 2830 | 2830 | }), |
| 2831 | 2831 | ); |
| 2832 | 2832 | |
| ... | ... | @@ -2838,14 +2838,14 @@ test "std.zon enum literals" { |
| 2838 | 2838 | .gpa = gpa, |
| 2839 | 2839 | .arena = arena, |
| 2840 | 2840 | .source = ".qux", |
| 2841 | | .errors = &errors, |
| 2841 | .diagnostics = &diagnostics, |
| 2842 | 2842 | }), |
| 2843 | 2843 | ); |
| 2844 | 2844 | try std.testing.expectFmt( |
| 2845 | 2845 | \\input.zon:1:2: error: unexpected enum literal 'qux' |
| 2846 | 2846 | \\input.zon:1:2: note: supported: 'foo', 'bar', 'baz', '@"ab\nc"' |
| 2847 | 2847 | \\ |
| 2848 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2848 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2849 | 2849 | } |
| 2850 | 2850 | |
| 2851 | 2851 | // Bad tag that's too long for parser |
| ... | ... | @@ -2856,14 +2856,14 @@ test "std.zon enum literals" { |
| 2856 | 2856 | .gpa = gpa, |
| 2857 | 2857 | .arena = arena, |
| 2858 | 2858 | .source = ".@\"foobarbaz\"", |
| 2859 | | .errors = &errors, |
| 2859 | .diagnostics = &diagnostics, |
| 2860 | 2860 | }), |
| 2861 | 2861 | ); |
| 2862 | 2862 | try std.testing.expectFmt( |
| 2863 | 2863 | \\input.zon:1:2: error: unexpected enum literal 'foobarbaz' |
| 2864 | 2864 | \\input.zon:1:2: note: supported: 'foo', 'bar', 'baz', '@"ab\nc"' |
| 2865 | 2865 | \\ |
| 2866 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2866 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2867 | 2867 | } |
| 2868 | 2868 | |
| 2869 | 2869 | // Bad type |
| ... | ... | @@ -2874,13 +2874,13 @@ test "std.zon enum literals" { |
| 2874 | 2874 | .gpa = gpa, |
| 2875 | 2875 | .arena = arena, |
| 2876 | 2876 | .source = "true", |
| 2877 | | .errors = &errors, |
| 2877 | .diagnostics = &diagnostics, |
| 2878 | 2878 | }), |
| 2879 | 2879 | ); |
| 2880 | 2880 | try std.testing.expectFmt( |
| 2881 | 2881 | \\input.zon:1:1: error: expected enum literal |
| 2882 | 2882 | \\ |
| 2883 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2883 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2884 | 2884 | } |
| 2885 | 2885 | |
| 2886 | 2886 | // Test embedded nulls in an identifier |
| ... | ... | @@ -2891,13 +2891,13 @@ test "std.zon enum literals" { |
| 2891 | 2891 | .gpa = gpa, |
| 2892 | 2892 | .arena = arena, |
| 2893 | 2893 | .source = ".@\"\\x00\"", |
| 2894 | | .errors = &errors, |
| 2894 | .diagnostics = &diagnostics, |
| 2895 | 2895 | }), |
| 2896 | 2896 | ); |
| 2897 | 2897 | try std.testing.expectFmt( |
| 2898 | 2898 | \\input.zon:1:2: error: identifier cannot contain null bytes |
| 2899 | 2899 | \\ |
| 2900 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2900 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2901 | 2901 | } |
| 2902 | 2902 | } |
| 2903 | 2903 | |
| ... | ... | @@ -2906,20 +2906,20 @@ test "std.zon parse bool" { |
| 2906 | 2906 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 2907 | 2907 | defer arena_allocator.deinit(); |
| 2908 | 2908 | const arena = arena_allocator.allocator(); |
| 2909 | | var errors: Errors = .empty; |
| 2909 | var diagnostics: Diagnostics = .empty; |
| 2910 | 2910 | |
| 2911 | 2911 | // Correct bools |
| 2912 | 2912 | try std.testing.expectEqual(true, try fromSliceNoAlloc(bool, .{ |
| 2913 | 2913 | .gpa = gpa, |
| 2914 | 2914 | .arena = arena, |
| 2915 | 2915 | .source = "true", |
| 2916 | | .errors = &errors, |
| 2916 | .diagnostics = &diagnostics, |
| 2917 | 2917 | })); |
| 2918 | 2918 | try std.testing.expectEqual(false, try fromSliceNoAlloc(bool, .{ |
| 2919 | 2919 | .gpa = gpa, |
| 2920 | 2920 | .arena = arena, |
| 2921 | 2921 | .source = "false", |
| 2922 | | .errors = &errors, |
| 2922 | .diagnostics = &diagnostics, |
| 2923 | 2923 | })); |
| 2924 | 2924 | |
| 2925 | 2925 | // Errors |
| ... | ... | @@ -2930,7 +2930,7 @@ test "std.zon parse bool" { |
| 2930 | 2930 | .gpa = gpa, |
| 2931 | 2931 | .arena = arena, |
| 2932 | 2932 | .source = " foo", |
| 2933 | | .errors = &errors, |
| 2933 | .diagnostics = &diagnostics, |
| 2934 | 2934 | }), |
| 2935 | 2935 | ); |
| 2936 | 2936 | try std.testing.expectFmt( |
| ... | ... | @@ -2938,19 +2938,19 @@ test "std.zon parse bool" { |
| 2938 | 2938 | \\input.zon:1:2: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan' |
| 2939 | 2939 | \\input.zon:1:2: note: precede identifier with '.' for an enum literal |
| 2940 | 2940 | \\ |
| 2941 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2941 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2942 | 2942 | } |
| 2943 | 2943 | { |
| 2944 | 2944 | try std.testing.expectError(error.ParseZon, fromSliceNoAlloc(bool, .{ |
| 2945 | 2945 | .gpa = gpa, |
| 2946 | 2946 | .arena = arena, |
| 2947 | 2947 | .source = "123", |
| 2948 | | .errors = &errors, |
| 2948 | .diagnostics = &diagnostics, |
| 2949 | 2949 | })); |
| 2950 | 2950 | try std.testing.expectFmt( |
| 2951 | 2951 | \\input.zon:1:1: error: expected type 'bool' |
| 2952 | 2952 | \\ |
| 2953 | | , "{f}", .{errors.fmt("input.zon")}); |
| 2953 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 2954 | 2954 | } |
| 2955 | 2955 | } |
| 2956 | 2956 | |
| ... | ... | @@ -2981,32 +2981,32 @@ test "std.zon parse int" { |
| 2981 | 2981 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 2982 | 2982 | defer arena_allocator.deinit(); |
| 2983 | 2983 | const arena = arena_allocator.allocator(); |
| 2984 | | var errors: Errors = .empty; |
| 2984 | var diagnostics: Diagnostics = .empty; |
| 2985 | 2985 | |
| 2986 | 2986 | // Test various numbers and types |
| 2987 | 2987 | try std.testing.expectEqual(@as(u8, 10), try fromSliceNoAlloc(u8, .{ |
| 2988 | 2988 | .gpa = gpa, |
| 2989 | 2989 | .arena = arena, |
| 2990 | 2990 | .source = "10", |
| 2991 | | .errors = &errors, |
| 2991 | .diagnostics = &diagnostics, |
| 2992 | 2992 | })); |
| 2993 | 2993 | try std.testing.expectEqual(@as(i16, 24), try fromSliceNoAlloc(i16, .{ |
| 2994 | 2994 | .gpa = gpa, |
| 2995 | 2995 | .arena = arena, |
| 2996 | 2996 | .source = "24", |
| 2997 | | .errors = &errors, |
| 2997 | .diagnostics = &diagnostics, |
| 2998 | 2998 | })); |
| 2999 | 2999 | try std.testing.expectEqual(@as(i14, -4), try fromSliceNoAlloc(i14, .{ |
| 3000 | 3000 | .gpa = gpa, |
| 3001 | 3001 | .arena = arena, |
| 3002 | 3002 | .source = "-4", |
| 3003 | | .errors = &errors, |
| 3003 | .diagnostics = &diagnostics, |
| 3004 | 3004 | })); |
| 3005 | 3005 | try std.testing.expectEqual(@as(i32, -123), try fromSliceNoAlloc(i32, .{ |
| 3006 | 3006 | .gpa = gpa, |
| 3007 | 3007 | .arena = arena, |
| 3008 | 3008 | .source = "-123", |
| 3009 | | .errors = &errors, |
| 3009 | .diagnostics = &diagnostics, |
| 3010 | 3010 | })); |
| 3011 | 3011 | |
| 3012 | 3012 | // Test limits |
| ... | ... | @@ -3014,13 +3014,13 @@ test "std.zon parse int" { |
| 3014 | 3014 | .gpa = gpa, |
| 3015 | 3015 | .arena = arena, |
| 3016 | 3016 | .source = "127", |
| 3017 | | .errors = &errors, |
| 3017 | .diagnostics = &diagnostics, |
| 3018 | 3018 | })); |
| 3019 | 3019 | try std.testing.expectEqual(@as(i8, -128), try fromSliceNoAlloc(i8, .{ |
| 3020 | 3020 | .gpa = gpa, |
| 3021 | 3021 | .arena = arena, |
| 3022 | 3022 | .source = "-128", |
| 3023 | | .errors = &errors, |
| 3023 | .diagnostics = &diagnostics, |
| 3024 | 3024 | })); |
| 3025 | 3025 | |
| 3026 | 3026 | // Test characters |
| ... | ... | @@ -3028,13 +3028,13 @@ test "std.zon parse int" { |
| 3028 | 3028 | .gpa = gpa, |
| 3029 | 3029 | .arena = arena, |
| 3030 | 3030 | .source = "'a'", |
| 3031 | | .errors = &errors, |
| 3031 | .diagnostics = &diagnostics, |
| 3032 | 3032 | })); |
| 3033 | 3033 | try std.testing.expectEqual(@as(u8, 'z'), try fromSliceNoAlloc(u8, .{ |
| 3034 | 3034 | .gpa = gpa, |
| 3035 | 3035 | .arena = arena, |
| 3036 | 3036 | .source = "'z'", |
| 3037 | | .errors = &errors, |
| 3037 | .diagnostics = &diagnostics, |
| 3038 | 3038 | })); |
| 3039 | 3039 | |
| 3040 | 3040 | // Test big integers |
| ... | ... | @@ -3044,7 +3044,7 @@ test "std.zon parse int" { |
| 3044 | 3044 | .gpa = gpa, |
| 3045 | 3045 | .arena = arena, |
| 3046 | 3046 | .source = "36893488147419103231", |
| 3047 | | .errors = &errors, |
| 3047 | .diagnostics = &diagnostics, |
| 3048 | 3048 | }), |
| 3049 | 3049 | ); |
| 3050 | 3050 | try std.testing.expectEqual( |
| ... | ... | @@ -3053,7 +3053,7 @@ test "std.zon parse int" { |
| 3053 | 3053 | .gpa = gpa, |
| 3054 | 3054 | .arena = arena, |
| 3055 | 3055 | .source = "368934_881_474191032_31", |
| 3056 | | .errors = &errors, |
| 3056 | .diagnostics = &diagnostics, |
| 3057 | 3057 | }), |
| 3058 | 3058 | ); |
| 3059 | 3059 | try std.testing.expectEqual( |
| ... | ... | @@ -3062,7 +3062,7 @@ test "std.zon parse int" { |
| 3062 | 3062 | .gpa = gpa, |
| 3063 | 3063 | .arena = arena, |
| 3064 | 3064 | .source = "340282366920938463463374607431768211455", |
| 3065 | | .errors = &errors, |
| 3065 | .diagnostics = &diagnostics, |
| 3066 | 3066 | }), |
| 3067 | 3067 | ); |
| 3068 | 3068 | |
| ... | ... | @@ -3073,7 +3073,7 @@ test "std.zon parse int" { |
| 3073 | 3073 | .gpa = gpa, |
| 3074 | 3074 | .arena = arena, |
| 3075 | 3075 | .source = "36893488147419103231", |
| 3076 | | .errors = &errors, |
| 3076 | .diagnostics = &diagnostics, |
| 3077 | 3077 | }), |
| 3078 | 3078 | ); |
| 3079 | 3079 | try std.testing.expectEqual( |
| ... | ... | @@ -3082,7 +3082,7 @@ test "std.zon parse int" { |
| 3082 | 3082 | .gpa = gpa, |
| 3083 | 3083 | .arena = arena, |
| 3084 | 3084 | .source = "-36893488147419103232", |
| 3085 | | .errors = &errors, |
| 3085 | .diagnostics = &diagnostics, |
| 3086 | 3086 | }), |
| 3087 | 3087 | ); |
| 3088 | 3088 | { |
| ... | ... | @@ -3090,24 +3090,24 @@ test "std.zon parse int" { |
| 3090 | 3090 | .gpa = gpa, |
| 3091 | 3091 | .arena = arena, |
| 3092 | 3092 | .source = "36893488147419103232", |
| 3093 | | .errors = &errors, |
| 3093 | .diagnostics = &diagnostics, |
| 3094 | 3094 | })); |
| 3095 | 3095 | try std.testing.expectFmt( |
| 3096 | 3096 | \\input.zon:1:1: error: type 'i66' cannot represent value |
| 3097 | 3097 | \\ |
| 3098 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3098 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3099 | 3099 | } |
| 3100 | 3100 | { |
| 3101 | 3101 | try std.testing.expectError(error.ParseZon, fromSliceNoAlloc(i66, .{ |
| 3102 | 3102 | .gpa = gpa, |
| 3103 | 3103 | .arena = arena, |
| 3104 | 3104 | .source = "-36893488147419103233", |
| 3105 | | .errors = &errors, |
| 3105 | .diagnostics = &diagnostics, |
| 3106 | 3106 | })); |
| 3107 | 3107 | try std.testing.expectFmt( |
| 3108 | 3108 | \\input.zon:1:1: error: type 'i66' cannot represent value |
| 3109 | 3109 | \\ |
| 3110 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3110 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3111 | 3111 | } |
| 3112 | 3112 | |
| 3113 | 3113 | // Test parsing whole number floats as integers |
| ... | ... | @@ -3115,13 +3115,13 @@ test "std.zon parse int" { |
| 3115 | 3115 | .gpa = gpa, |
| 3116 | 3116 | .arena = arena, |
| 3117 | 3117 | .source = "-1.0", |
| 3118 | | .errors = &errors, |
| 3118 | .diagnostics = &diagnostics, |
| 3119 | 3119 | })); |
| 3120 | 3120 | try std.testing.expectEqual(@as(i8, 123), try fromSliceNoAlloc(i8, .{ |
| 3121 | 3121 | .gpa = gpa, |
| 3122 | 3122 | .arena = arena, |
| 3123 | 3123 | .source = "123.0", |
| 3124 | | .errors = &errors, |
| 3124 | .diagnostics = &diagnostics, |
| 3125 | 3125 | })); |
| 3126 | 3126 | |
| 3127 | 3127 | // Test non-decimal integers |
| ... | ... | @@ -3129,37 +3129,37 @@ test "std.zon parse int" { |
| 3129 | 3129 | .gpa = gpa, |
| 3130 | 3130 | .arena = arena, |
| 3131 | 3131 | .source = "0xff", |
| 3132 | | .errors = &errors, |
| 3132 | .diagnostics = &diagnostics, |
| 3133 | 3133 | })); |
| 3134 | 3134 | try std.testing.expectEqual(@as(i16, -0xff), try fromSliceNoAlloc(i16, .{ |
| 3135 | 3135 | .gpa = gpa, |
| 3136 | 3136 | .arena = arena, |
| 3137 | 3137 | .source = "-0xff", |
| 3138 | | .errors = &errors, |
| 3138 | .diagnostics = &diagnostics, |
| 3139 | 3139 | })); |
| 3140 | 3140 | try std.testing.expectEqual(@as(i16, 0o77), try fromSliceNoAlloc(i16, .{ |
| 3141 | 3141 | .gpa = gpa, |
| 3142 | 3142 | .arena = arena, |
| 3143 | 3143 | .source = "0o77", |
| 3144 | | .errors = &errors, |
| 3144 | .diagnostics = &diagnostics, |
| 3145 | 3145 | })); |
| 3146 | 3146 | try std.testing.expectEqual(@as(i16, -0o77), try fromSliceNoAlloc(i16, .{ |
| 3147 | 3147 | .gpa = gpa, |
| 3148 | 3148 | .arena = arena, |
| 3149 | 3149 | .source = "-0o77", |
| 3150 | | .errors = &errors, |
| 3150 | .diagnostics = &diagnostics, |
| 3151 | 3151 | })); |
| 3152 | 3152 | try std.testing.expectEqual(@as(i16, 0b11), try fromSliceNoAlloc(i16, .{ |
| 3153 | 3153 | .gpa = gpa, |
| 3154 | 3154 | .arena = arena, |
| 3155 | 3155 | .source = "0b11", |
| 3156 | | .errors = &errors, |
| 3156 | .diagnostics = &diagnostics, |
| 3157 | 3157 | })); |
| 3158 | 3158 | try std.testing.expectEqual(@as(i16, -0b11), try fromSliceNoAlloc(i16, .{ |
| 3159 | 3159 | .gpa = gpa, |
| 3160 | 3160 | .arena = arena, |
| 3161 | 3161 | .source = "-0b11", |
| 3162 | | .errors = &errors, |
| 3162 | .diagnostics = &diagnostics, |
| 3163 | 3163 | })); |
| 3164 | 3164 | |
| 3165 | 3165 | // Test non-decimal big integers |
| ... | ... | @@ -3167,55 +3167,55 @@ test "std.zon parse int" { |
| 3167 | 3167 | .gpa = gpa, |
| 3168 | 3168 | .arena = arena, |
| 3169 | 3169 | .source = "0x1ffffffffffffffff", |
| 3170 | | .errors = &errors, |
| 3170 | .diagnostics = &diagnostics, |
| 3171 | 3171 | })); |
| 3172 | 3172 | try std.testing.expectEqual(@as(i66, 0x1ffffffffffffffff), try fromSliceNoAlloc(i66, .{ |
| 3173 | 3173 | .gpa = gpa, |
| 3174 | 3174 | .arena = arena, |
| 3175 | 3175 | .source = "0x1ffffffffffffffff", |
| 3176 | | .errors = &errors, |
| 3176 | .diagnostics = &diagnostics, |
| 3177 | 3177 | })); |
| 3178 | 3178 | try std.testing.expectEqual(@as(i66, -0x1ffffffffffffffff), try fromSliceNoAlloc(i66, .{ |
| 3179 | 3179 | .gpa = gpa, |
| 3180 | 3180 | .arena = arena, |
| 3181 | 3181 | .source = "-0x1ffffffffffffffff", |
| 3182 | | .errors = &errors, |
| 3182 | .diagnostics = &diagnostics, |
| 3183 | 3183 | })); |
| 3184 | 3184 | try std.testing.expectEqual(@as(u65, 0x1ffffffffffffffff), try fromSliceNoAlloc(u65, .{ |
| 3185 | 3185 | .gpa = gpa, |
| 3186 | 3186 | .arena = arena, |
| 3187 | 3187 | .source = "0o3777777777777777777777", |
| 3188 | | .errors = &errors, |
| 3188 | .diagnostics = &diagnostics, |
| 3189 | 3189 | })); |
| 3190 | 3190 | try std.testing.expectEqual(@as(i66, 0x1ffffffffffffffff), try fromSliceNoAlloc(i66, .{ |
| 3191 | 3191 | .gpa = gpa, |
| 3192 | 3192 | .arena = arena, |
| 3193 | 3193 | .source = "0o3777777777777777777777", |
| 3194 | | .errors = &errors, |
| 3194 | .diagnostics = &diagnostics, |
| 3195 | 3195 | })); |
| 3196 | 3196 | try std.testing.expectEqual(@as(i66, -0x1ffffffffffffffff), try fromSliceNoAlloc(i66, .{ |
| 3197 | 3197 | .gpa = gpa, |
| 3198 | 3198 | .arena = arena, |
| 3199 | 3199 | .source = "-0o3777777777777777777777", |
| 3200 | | .errors = &errors, |
| 3200 | .diagnostics = &diagnostics, |
| 3201 | 3201 | })); |
| 3202 | 3202 | try std.testing.expectEqual(@as(u65, 0x1ffffffffffffffff), try fromSliceNoAlloc(u65, .{ |
| 3203 | 3203 | .gpa = gpa, |
| 3204 | 3204 | .arena = arena, |
| 3205 | 3205 | .source = "0b11111111111111111111111111111111111111111111111111111111111111111", |
| 3206 | | .errors = &errors, |
| 3206 | .diagnostics = &diagnostics, |
| 3207 | 3207 | })); |
| 3208 | 3208 | try std.testing.expectEqual(@as(i66, 0x1ffffffffffffffff), try fromSliceNoAlloc(i66, .{ |
| 3209 | 3209 | .gpa = gpa, |
| 3210 | 3210 | .arena = arena, |
| 3211 | 3211 | .source = "0b11111111111111111111111111111111111111111111111111111111111111111", |
| 3212 | | .errors = &errors, |
| 3212 | .diagnostics = &diagnostics, |
| 3213 | 3213 | })); |
| 3214 | 3214 | try std.testing.expectEqual(@as(i66, -0x1ffffffffffffffff), try fromSliceNoAlloc(i66, .{ |
| 3215 | 3215 | .gpa = gpa, |
| 3216 | 3216 | .arena = arena, |
| 3217 | 3217 | .source = "-0b11111111111111111111111111111111111111111111111111111111111111111", |
| 3218 | | .errors = &errors, |
| 3218 | .diagnostics = &diagnostics, |
| 3219 | 3219 | })); |
| 3220 | 3220 | |
| 3221 | 3221 | // Number with invalid character in the middle |
| ... | ... | @@ -3224,12 +3224,12 @@ test "std.zon parse int" { |
| 3224 | 3224 | .gpa = gpa, |
| 3225 | 3225 | .arena = arena, |
| 3226 | 3226 | .source = "32a32", |
| 3227 | | .errors = &errors, |
| 3227 | .diagnostics = &diagnostics, |
| 3228 | 3228 | })); |
| 3229 | 3229 | try std.testing.expectFmt( |
| 3230 | 3230 | \\input.zon:1:3: error: invalid digit 'a' for decimal base |
| 3231 | 3231 | \\ |
| 3232 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3232 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3233 | 3233 | } |
| 3234 | 3234 | |
| 3235 | 3235 | // Failing to parse as int |
| ... | ... | @@ -3238,12 +3238,12 @@ test "std.zon parse int" { |
| 3238 | 3238 | .gpa = gpa, |
| 3239 | 3239 | .arena = arena, |
| 3240 | 3240 | .source = "true", |
| 3241 | | .errors = &errors, |
| 3241 | .diagnostics = &diagnostics, |
| 3242 | 3242 | })); |
| 3243 | 3243 | try std.testing.expectFmt( |
| 3244 | 3244 | \\input.zon:1:1: error: expected type 'u8' |
| 3245 | 3245 | \\ |
| 3246 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3246 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3247 | 3247 | } |
| 3248 | 3248 | |
| 3249 | 3249 | // Failing because an int is out of range |
| ... | ... | @@ -3252,12 +3252,12 @@ test "std.zon parse int" { |
| 3252 | 3252 | .gpa = gpa, |
| 3253 | 3253 | .arena = arena, |
| 3254 | 3254 | .source = "256", |
| 3255 | | .errors = &errors, |
| 3255 | .diagnostics = &diagnostics, |
| 3256 | 3256 | })); |
| 3257 | 3257 | try std.testing.expectFmt( |
| 3258 | 3258 | \\input.zon:1:1: error: type 'u8' cannot represent value |
| 3259 | 3259 | \\ |
| 3260 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3260 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3261 | 3261 | } |
| 3262 | 3262 | |
| 3263 | 3263 | // Failing because a negative int is out of range |
| ... | ... | @@ -3266,12 +3266,12 @@ test "std.zon parse int" { |
| 3266 | 3266 | .gpa = gpa, |
| 3267 | 3267 | .arena = arena, |
| 3268 | 3268 | .source = "-129", |
| 3269 | | .errors = &errors, |
| 3269 | .diagnostics = &diagnostics, |
| 3270 | 3270 | })); |
| 3271 | 3271 | try std.testing.expectFmt( |
| 3272 | 3272 | \\input.zon:1:1: error: type 'i8' cannot represent value |
| 3273 | 3273 | \\ |
| 3274 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3274 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3275 | 3275 | } |
| 3276 | 3276 | |
| 3277 | 3277 | // Failing because an unsigned int is negative |
| ... | ... | @@ -3280,12 +3280,12 @@ test "std.zon parse int" { |
| 3280 | 3280 | .gpa = gpa, |
| 3281 | 3281 | .arena = arena, |
| 3282 | 3282 | .source = "-1", |
| 3283 | | .errors = &errors, |
| 3283 | .diagnostics = &diagnostics, |
| 3284 | 3284 | })); |
| 3285 | 3285 | try std.testing.expectFmt( |
| 3286 | 3286 | \\input.zon:1:1: error: type 'u8' cannot represent value |
| 3287 | 3287 | \\ |
| 3288 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3288 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3289 | 3289 | } |
| 3290 | 3290 | |
| 3291 | 3291 | // Failing because a float is non-whole |
| ... | ... | @@ -3294,12 +3294,12 @@ test "std.zon parse int" { |
| 3294 | 3294 | .gpa = gpa, |
| 3295 | 3295 | .arena = arena, |
| 3296 | 3296 | .source = "1.5", |
| 3297 | | .errors = &errors, |
| 3297 | .diagnostics = &diagnostics, |
| 3298 | 3298 | })); |
| 3299 | 3299 | try std.testing.expectFmt( |
| 3300 | 3300 | \\input.zon:1:1: error: type 'u8' cannot represent value |
| 3301 | 3301 | \\ |
| 3302 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3302 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3303 | 3303 | } |
| 3304 | 3304 | |
| 3305 | 3305 | // Failing because a float is negative |
| ... | ... | @@ -3308,12 +3308,12 @@ test "std.zon parse int" { |
| 3308 | 3308 | .gpa = gpa, |
| 3309 | 3309 | .arena = arena, |
| 3310 | 3310 | .source = "-1.0", |
| 3311 | | .errors = &errors, |
| 3311 | .diagnostics = &diagnostics, |
| 3312 | 3312 | })); |
| 3313 | 3313 | try std.testing.expectFmt( |
| 3314 | 3314 | \\input.zon:1:1: error: type 'u8' cannot represent value |
| 3315 | 3315 | \\ |
| 3316 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3316 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3317 | 3317 | } |
| 3318 | 3318 | |
| 3319 | 3319 | // Negative integer zero |
| ... | ... | @@ -3322,14 +3322,14 @@ test "std.zon parse int" { |
| 3322 | 3322 | .gpa = gpa, |
| 3323 | 3323 | .arena = arena, |
| 3324 | 3324 | .source = "-0", |
| 3325 | | .errors = &errors, |
| 3325 | .diagnostics = &diagnostics, |
| 3326 | 3326 | })); |
| 3327 | 3327 | try std.testing.expectFmt( |
| 3328 | 3328 | \\input.zon:1:2: error: integer literal '-0' is ambiguous |
| 3329 | 3329 | \\input.zon:1:2: note: use '0' for an integer zero |
| 3330 | 3330 | \\input.zon:1:2: note: use '-0.0' for a floating-point signed zero |
| 3331 | 3331 | \\ |
| 3332 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3332 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3333 | 3333 | } |
| 3334 | 3334 | |
| 3335 | 3335 | // Negative integer zero casted to float |
| ... | ... | @@ -3338,14 +3338,14 @@ test "std.zon parse int" { |
| 3338 | 3338 | .gpa = gpa, |
| 3339 | 3339 | .arena = arena, |
| 3340 | 3340 | .source = "-0", |
| 3341 | | .errors = &errors, |
| 3341 | .diagnostics = &diagnostics, |
| 3342 | 3342 | })); |
| 3343 | 3343 | try std.testing.expectFmt( |
| 3344 | 3344 | \\input.zon:1:2: error: integer literal '-0' is ambiguous |
| 3345 | 3345 | \\input.zon:1:2: note: use '0' for an integer zero |
| 3346 | 3346 | \\input.zon:1:2: note: use '-0.0' for a floating-point signed zero |
| 3347 | 3347 | \\ |
| 3348 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3348 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3349 | 3349 | } |
| 3350 | 3350 | |
| 3351 | 3351 | // Negative float 0 is allowed |
| ... | ... | @@ -3354,14 +3354,14 @@ test "std.zon parse int" { |
| 3354 | 3354 | .gpa = gpa, |
| 3355 | 3355 | .arena = arena, |
| 3356 | 3356 | .source = "-0.0", |
| 3357 | | .errors = &errors, |
| 3357 | .diagnostics = &diagnostics, |
| 3358 | 3358 | })), |
| 3359 | 3359 | ); |
| 3360 | 3360 | try std.testing.expect(std.math.isPositiveZero(try fromSliceNoAlloc(f32, .{ |
| 3361 | 3361 | .gpa = gpa, |
| 3362 | 3362 | .arena = arena, |
| 3363 | 3363 | .source = "0.0", |
| 3364 | | .errors = &errors, |
| 3364 | .diagnostics = &diagnostics, |
| 3365 | 3365 | }))); |
| 3366 | 3366 | |
| 3367 | 3367 | // Double negation is not allowed |
| ... | ... | @@ -3370,12 +3370,12 @@ test "std.zon parse int" { |
| 3370 | 3370 | .gpa = gpa, |
| 3371 | 3371 | .arena = arena, |
| 3372 | 3372 | .source = "--2", |
| 3373 | | .errors = &errors, |
| 3373 | .diagnostics = &diagnostics, |
| 3374 | 3374 | })); |
| 3375 | 3375 | try std.testing.expectFmt( |
| 3376 | 3376 | \\input.zon:1:1: error: expected number or 'inf' after '-' |
| 3377 | 3377 | \\ |
| 3378 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3378 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3379 | 3379 | } |
| 3380 | 3380 | |
| 3381 | 3381 | { |
| ... | ... | @@ -3385,13 +3385,13 @@ test "std.zon parse int" { |
| 3385 | 3385 | .gpa = gpa, |
| 3386 | 3386 | .arena = arena, |
| 3387 | 3387 | .source = "--2.0", |
| 3388 | | .errors = &errors, |
| 3388 | .diagnostics = &diagnostics, |
| 3389 | 3389 | }), |
| 3390 | 3390 | ); |
| 3391 | 3391 | try std.testing.expectFmt( |
| 3392 | 3392 | \\input.zon:1:1: error: expected number or 'inf' after '-' |
| 3393 | 3393 | \\ |
| 3394 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3394 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3395 | 3395 | } |
| 3396 | 3396 | |
| 3397 | 3397 | // Invalid int literal |
| ... | ... | @@ -3400,12 +3400,12 @@ test "std.zon parse int" { |
| 3400 | 3400 | .gpa = gpa, |
| 3401 | 3401 | .arena = arena, |
| 3402 | 3402 | .source = "0xg", |
| 3403 | | .errors = &errors, |
| 3403 | .diagnostics = &diagnostics, |
| 3404 | 3404 | })); |
| 3405 | 3405 | try std.testing.expectFmt( |
| 3406 | 3406 | \\input.zon:1:3: error: invalid digit 'g' for hex base |
| 3407 | 3407 | \\ |
| 3408 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3408 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3409 | 3409 | } |
| 3410 | 3410 | |
| 3411 | 3411 | // Notes on invalid int literal |
| ... | ... | @@ -3414,13 +3414,13 @@ test "std.zon parse int" { |
| 3414 | 3414 | .gpa = gpa, |
| 3415 | 3415 | .arena = arena, |
| 3416 | 3416 | .source = "0123", |
| 3417 | | .errors = &errors, |
| 3417 | .diagnostics = &diagnostics, |
| 3418 | 3418 | })); |
| 3419 | 3419 | try std.testing.expectFmt( |
| 3420 | 3420 | \\input.zon:1:1: error: number '0123' has leading zero |
| 3421 | 3421 | \\input.zon:1:1: note: use '0o' prefix for octal literals |
| 3422 | 3422 | \\ |
| 3423 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3423 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3424 | 3424 | } |
| 3425 | 3425 | } |
| 3426 | 3426 | |
| ... | ... | @@ -3429,31 +3429,31 @@ test "std.zon negative char" { |
| 3429 | 3429 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 3430 | 3430 | defer arena_allocator.deinit(); |
| 3431 | 3431 | const arena = arena_allocator.allocator(); |
| 3432 | | var errors: Errors = .empty; |
| 3432 | var diagnostics: Diagnostics = .empty; |
| 3433 | 3433 | |
| 3434 | 3434 | { |
| 3435 | 3435 | try std.testing.expectError(error.ParseZon, fromSliceNoAlloc(f32, .{ |
| 3436 | 3436 | .gpa = gpa, |
| 3437 | 3437 | .arena = arena, |
| 3438 | 3438 | .source = "-'a'", |
| 3439 | | .errors = &errors, |
| 3439 | .diagnostics = &diagnostics, |
| 3440 | 3440 | })); |
| 3441 | 3441 | try std.testing.expectFmt( |
| 3442 | 3442 | \\input.zon:1:1: error: expected number or 'inf' after '-' |
| 3443 | 3443 | \\ |
| 3444 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3444 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3445 | 3445 | } |
| 3446 | 3446 | { |
| 3447 | 3447 | try std.testing.expectError(error.ParseZon, fromSliceNoAlloc(i16, .{ |
| 3448 | 3448 | .gpa = gpa, |
| 3449 | 3449 | .arena = arena, |
| 3450 | 3450 | .source = "-'a'", |
| 3451 | | .errors = &errors, |
| 3451 | .diagnostics = &diagnostics, |
| 3452 | 3452 | })); |
| 3453 | 3453 | try std.testing.expectFmt( |
| 3454 | 3454 | \\input.zon:1:1: error: expected number or 'inf' after '-' |
| 3455 | 3455 | \\ |
| 3456 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3456 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3457 | 3457 | } |
| 3458 | 3458 | } |
| 3459 | 3459 | |
| ... | ... | @@ -3464,14 +3464,14 @@ test "std.zon parse float" { |
| 3464 | 3464 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 3465 | 3465 | defer arena_allocator.deinit(); |
| 3466 | 3466 | const arena = arena_allocator.allocator(); |
| 3467 | | var errors: Errors = .empty; |
| 3467 | var diagnostics: Diagnostics = .empty; |
| 3468 | 3468 | |
| 3469 | 3469 | // Test decimals |
| 3470 | 3470 | try std.testing.expectEqual(@as(f16, 0.5), try fromSliceNoAlloc(f16, .{ |
| 3471 | 3471 | .gpa = gpa, |
| 3472 | 3472 | .arena = arena, |
| 3473 | 3473 | .source = "0.5", |
| 3474 | | .errors = &errors, |
| 3474 | .diagnostics = &diagnostics, |
| 3475 | 3475 | })); |
| 3476 | 3476 | try std.testing.expectEqual( |
| 3477 | 3477 | @as(f32, 123.456), |
| ... | ... | @@ -3479,7 +3479,7 @@ test "std.zon parse float" { |
| 3479 | 3479 | .gpa = gpa, |
| 3480 | 3480 | .arena = arena, |
| 3481 | 3481 | .source = "123.456", |
| 3482 | | .errors = &errors, |
| 3482 | .diagnostics = &diagnostics, |
| 3483 | 3483 | }), |
| 3484 | 3484 | ); |
| 3485 | 3485 | try std.testing.expectEqual( |
| ... | ... | @@ -3488,14 +3488,14 @@ test "std.zon parse float" { |
| 3488 | 3488 | .gpa = gpa, |
| 3489 | 3489 | .arena = arena, |
| 3490 | 3490 | .source = "-123.456", |
| 3491 | | .errors = &errors, |
| 3491 | .diagnostics = &diagnostics, |
| 3492 | 3492 | }), |
| 3493 | 3493 | ); |
| 3494 | 3494 | try std.testing.expectEqual(@as(f128, 42.5), try fromSliceNoAlloc(f128, .{ |
| 3495 | 3495 | .gpa = gpa, |
| 3496 | 3496 | .arena = arena, |
| 3497 | 3497 | .source = "42.5", |
| 3498 | | .errors = &errors, |
| 3498 | .diagnostics = &diagnostics, |
| 3499 | 3499 | })); |
| 3500 | 3500 | |
| 3501 | 3501 | // Test whole numbers with and without decimals |
| ... | ... | @@ -3503,25 +3503,25 @@ test "std.zon parse float" { |
| 3503 | 3503 | .gpa = gpa, |
| 3504 | 3504 | .arena = arena, |
| 3505 | 3505 | .source = "5.0", |
| 3506 | | .errors = &errors, |
| 3506 | .diagnostics = &diagnostics, |
| 3507 | 3507 | })); |
| 3508 | 3508 | try std.testing.expectEqual(@as(f16, 5.0), try fromSliceNoAlloc(f16, .{ |
| 3509 | 3509 | .gpa = gpa, |
| 3510 | 3510 | .arena = arena, |
| 3511 | 3511 | .source = "5", |
| 3512 | | .errors = &errors, |
| 3512 | .diagnostics = &diagnostics, |
| 3513 | 3513 | })); |
| 3514 | 3514 | try std.testing.expectEqual(@as(f32, -102), try fromSliceNoAlloc(f32, .{ |
| 3515 | 3515 | .gpa = gpa, |
| 3516 | 3516 | .arena = arena, |
| 3517 | 3517 | .source = "-102.0", |
| 3518 | | .errors = &errors, |
| 3518 | .diagnostics = &diagnostics, |
| 3519 | 3519 | })); |
| 3520 | 3520 | try std.testing.expectEqual(@as(f32, -102), try fromSliceNoAlloc(f32, .{ |
| 3521 | 3521 | .gpa = gpa, |
| 3522 | 3522 | .arena = arena, |
| 3523 | 3523 | .source = "-102", |
| 3524 | | .errors = &errors, |
| 3524 | .diagnostics = &diagnostics, |
| 3525 | 3525 | })); |
| 3526 | 3526 | |
| 3527 | 3527 | // Test characters and negated characters |
| ... | ... | @@ -3529,13 +3529,13 @@ test "std.zon parse float" { |
| 3529 | 3529 | .gpa = gpa, |
| 3530 | 3530 | .arena = arena, |
| 3531 | 3531 | .source = "'a'", |
| 3532 | | .errors = &errors, |
| 3532 | .diagnostics = &diagnostics, |
| 3533 | 3533 | })); |
| 3534 | 3534 | try std.testing.expectEqual(@as(f32, 'z'), try fromSliceNoAlloc(f32, .{ |
| 3535 | 3535 | .gpa = gpa, |
| 3536 | 3536 | .arena = arena, |
| 3537 | 3537 | .source = "'z'", |
| 3538 | | .errors = &errors, |
| 3538 | .diagnostics = &diagnostics, |
| 3539 | 3539 | })); |
| 3540 | 3540 | |
| 3541 | 3541 | // Test big integers |
| ... | ... | @@ -3545,7 +3545,7 @@ test "std.zon parse float" { |
| 3545 | 3545 | .gpa = gpa, |
| 3546 | 3546 | .arena = arena, |
| 3547 | 3547 | .source = "36893488147419103231", |
| 3548 | | .errors = &errors, |
| 3548 | .diagnostics = &diagnostics, |
| 3549 | 3549 | }), |
| 3550 | 3550 | ); |
| 3551 | 3551 | try std.testing.expectEqual( |
| ... | ... | @@ -3554,20 +3554,20 @@ test "std.zon parse float" { |
| 3554 | 3554 | .gpa = gpa, |
| 3555 | 3555 | .arena = arena, |
| 3556 | 3556 | .source = "-36893488147419103231", |
| 3557 | | .errors = &errors, |
| 3557 | .diagnostics = &diagnostics, |
| 3558 | 3558 | }), |
| 3559 | 3559 | ); |
| 3560 | 3560 | try std.testing.expectEqual(@as(f128, 0x1ffffffffffffffff), try fromSliceNoAlloc(f128, .{ |
| 3561 | 3561 | .gpa = gpa, |
| 3562 | 3562 | .arena = arena, |
| 3563 | 3563 | .source = "0x1ffffffffffffffff", |
| 3564 | | .errors = &errors, |
| 3564 | .diagnostics = &diagnostics, |
| 3565 | 3565 | })); |
| 3566 | 3566 | try std.testing.expectEqual(@as(f32, @floatFromInt(0x1ffffffffffffffff)), try fromSliceNoAlloc(f32, .{ |
| 3567 | 3567 | .gpa = gpa, |
| 3568 | 3568 | .arena = arena, |
| 3569 | 3569 | .source = "0x1ffffffffffffffff", |
| 3570 | | .errors = &errors, |
| 3570 | .diagnostics = &diagnostics, |
| 3571 | 3571 | })); |
| 3572 | 3572 | |
| 3573 | 3573 | // Exponents, underscores |
| ... | ... | @@ -3577,7 +3577,7 @@ test "std.zon parse float" { |
| 3577 | 3577 | .gpa = gpa, |
| 3578 | 3578 | .arena = arena, |
| 3579 | 3579 | .source = "12_3.0E+77", |
| 3580 | | .errors = &errors, |
| 3580 | .diagnostics = &diagnostics, |
| 3581 | 3581 | }), |
| 3582 | 3582 | ); |
| 3583 | 3583 | |
| ... | ... | @@ -3588,7 +3588,7 @@ test "std.zon parse float" { |
| 3588 | 3588 | .gpa = gpa, |
| 3589 | 3589 | .arena = arena, |
| 3590 | 3590 | .source = "0x103.70p-5", |
| 3591 | | .errors = &errors, |
| 3591 | .diagnostics = &diagnostics, |
| 3592 | 3592 | }), |
| 3593 | 3593 | ); |
| 3594 | 3594 | try std.testing.expectEqual( |
| ... | ... | @@ -3597,7 +3597,7 @@ test "std.zon parse float" { |
| 3597 | 3597 | .gpa = gpa, |
| 3598 | 3598 | .arena = arena, |
| 3599 | 3599 | .source = "-0x103.70", |
| 3600 | | .errors = &errors, |
| 3600 | .diagnostics = &diagnostics, |
| 3601 | 3601 | }), |
| 3602 | 3602 | ); |
| 3603 | 3603 | try std.testing.expectEqual( |
| ... | ... | @@ -3606,7 +3606,7 @@ test "std.zon parse float" { |
| 3606 | 3606 | .gpa = gpa, |
| 3607 | 3607 | .arena = arena, |
| 3608 | 3608 | .source = "0x1234_5678.9ABC_CDEFp-10", |
| 3609 | | .errors = &errors, |
| 3609 | .diagnostics = &diagnostics, |
| 3610 | 3610 | }), |
| 3611 | 3611 | ); |
| 3612 | 3612 | |
| ... | ... | @@ -3615,19 +3615,19 @@ test "std.zon parse float" { |
| 3615 | 3615 | .gpa = gpa, |
| 3616 | 3616 | .arena = arena, |
| 3617 | 3617 | .source = "inf", |
| 3618 | | .errors = &errors, |
| 3618 | .diagnostics = &diagnostics, |
| 3619 | 3619 | }))); |
| 3620 | 3620 | try std.testing.expect(std.math.isNegativeInf(try fromSliceNoAlloc(f32, .{ |
| 3621 | 3621 | .gpa = gpa, |
| 3622 | 3622 | .arena = arena, |
| 3623 | 3623 | .source = "-inf", |
| 3624 | | .errors = &errors, |
| 3624 | .diagnostics = &diagnostics, |
| 3625 | 3625 | }))); |
| 3626 | 3626 | try std.testing.expect(std.math.isNan(try fromSliceNoAlloc(f32, .{ |
| 3627 | 3627 | .gpa = gpa, |
| 3628 | 3628 | .arena = arena, |
| 3629 | 3629 | .source = "nan", |
| 3630 | | .errors = &errors, |
| 3630 | .diagnostics = &diagnostics, |
| 3631 | 3631 | }))); |
| 3632 | 3632 | |
| 3633 | 3633 | // Negative nan not allowed |
| ... | ... | @@ -3636,12 +3636,12 @@ test "std.zon parse float" { |
| 3636 | 3636 | .gpa = gpa, |
| 3637 | 3637 | .arena = arena, |
| 3638 | 3638 | .source = "-nan", |
| 3639 | | .errors = &errors, |
| 3639 | .diagnostics = &diagnostics, |
| 3640 | 3640 | })); |
| 3641 | 3641 | try std.testing.expectFmt( |
| 3642 | 3642 | \\input.zon:1:1: error: expected number or 'inf' after '-' |
| 3643 | 3643 | \\ |
| 3644 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3644 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3645 | 3645 | } |
| 3646 | 3646 | |
| 3647 | 3647 | // nan as int not allowed |
| ... | ... | @@ -3650,12 +3650,12 @@ test "std.zon parse float" { |
| 3650 | 3650 | .gpa = gpa, |
| 3651 | 3651 | .arena = arena, |
| 3652 | 3652 | .source = "nan", |
| 3653 | | .errors = &errors, |
| 3653 | .diagnostics = &diagnostics, |
| 3654 | 3654 | })); |
| 3655 | 3655 | try std.testing.expectFmt( |
| 3656 | 3656 | \\input.zon:1:1: error: expected type 'i8' |
| 3657 | 3657 | \\ |
| 3658 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3658 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3659 | 3659 | } |
| 3660 | 3660 | |
| 3661 | 3661 | // nan as int not allowed |
| ... | ... | @@ -3664,12 +3664,12 @@ test "std.zon parse float" { |
| 3664 | 3664 | .gpa = gpa, |
| 3665 | 3665 | .arena = arena, |
| 3666 | 3666 | .source = "nan", |
| 3667 | | .errors = &errors, |
| 3667 | .diagnostics = &diagnostics, |
| 3668 | 3668 | })); |
| 3669 | 3669 | try std.testing.expectFmt( |
| 3670 | 3670 | \\input.zon:1:1: error: expected type 'i8' |
| 3671 | 3671 | \\ |
| 3672 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3672 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3673 | 3673 | } |
| 3674 | 3674 | |
| 3675 | 3675 | // inf as int not allowed |
| ... | ... | @@ -3678,12 +3678,12 @@ test "std.zon parse float" { |
| 3678 | 3678 | .gpa = gpa, |
| 3679 | 3679 | .arena = arena, |
| 3680 | 3680 | .source = "inf", |
| 3681 | | .errors = &errors, |
| 3681 | .diagnostics = &diagnostics, |
| 3682 | 3682 | })); |
| 3683 | 3683 | try std.testing.expectFmt( |
| 3684 | 3684 | \\input.zon:1:1: error: expected type 'i8' |
| 3685 | 3685 | \\ |
| 3686 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3686 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3687 | 3687 | } |
| 3688 | 3688 | |
| 3689 | 3689 | // -inf as int not allowed |
| ... | ... | @@ -3692,12 +3692,12 @@ test "std.zon parse float" { |
| 3692 | 3692 | .gpa = gpa, |
| 3693 | 3693 | .arena = arena, |
| 3694 | 3694 | .source = "-inf", |
| 3695 | | .errors = &errors, |
| 3695 | .diagnostics = &diagnostics, |
| 3696 | 3696 | })); |
| 3697 | 3697 | try std.testing.expectFmt( |
| 3698 | 3698 | \\input.zon:1:1: error: expected type 'i8' |
| 3699 | 3699 | \\ |
| 3700 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3700 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3701 | 3701 | } |
| 3702 | 3702 | |
| 3703 | 3703 | // Bad identifier as float |
| ... | ... | @@ -3706,14 +3706,14 @@ test "std.zon parse float" { |
| 3706 | 3706 | .gpa = gpa, |
| 3707 | 3707 | .arena = arena, |
| 3708 | 3708 | .source = "foo", |
| 3709 | | .errors = &errors, |
| 3709 | .diagnostics = &diagnostics, |
| 3710 | 3710 | })); |
| 3711 | 3711 | try std.testing.expectFmt( |
| 3712 | 3712 | \\input.zon:1:1: error: invalid expression |
| 3713 | 3713 | \\input.zon:1:1: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan' |
| 3714 | 3714 | \\input.zon:1:1: note: precede identifier with '.' for an enum literal |
| 3715 | 3715 | \\ |
| 3716 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3716 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3717 | 3717 | } |
| 3718 | 3718 | |
| 3719 | 3719 | { |
| ... | ... | @@ -3721,12 +3721,12 @@ test "std.zon parse float" { |
| 3721 | 3721 | .gpa = gpa, |
| 3722 | 3722 | .arena = arena, |
| 3723 | 3723 | .source = "-foo", |
| 3724 | | .errors = &errors, |
| 3724 | .diagnostics = &diagnostics, |
| 3725 | 3725 | })); |
| 3726 | 3726 | try std.testing.expectFmt( |
| 3727 | 3727 | \\input.zon:1:1: error: expected number or 'inf' after '-' |
| 3728 | 3728 | \\ |
| 3729 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3729 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3730 | 3730 | } |
| 3731 | 3731 | |
| 3732 | 3732 | // Non float as float |
| ... | ... | @@ -3737,13 +3737,13 @@ test "std.zon parse float" { |
| 3737 | 3737 | .gpa = gpa, |
| 3738 | 3738 | .arena = arena, |
| 3739 | 3739 | .source = "\"foo\"", |
| 3740 | | .errors = &errors, |
| 3740 | .diagnostics = &diagnostics, |
| 3741 | 3741 | }), |
| 3742 | 3742 | ); |
| 3743 | 3743 | try std.testing.expectFmt( |
| 3744 | 3744 | \\input.zon:1:1: error: expected type 'f32' |
| 3745 | 3745 | \\ |
| 3746 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3746 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3747 | 3747 | } |
| 3748 | 3748 | } |
| 3749 | 3749 | |
| ... | ... | @@ -3752,7 +3752,7 @@ test "std.zon free on error" { |
| 3752 | 3752 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 3753 | 3753 | defer arena_allocator.deinit(); |
| 3754 | 3754 | const arena = arena_allocator.allocator(); |
| 3755 | | var errors: Errors = .empty; |
| 3755 | var diagnostics: Diagnostics = .empty; |
| 3756 | 3756 | |
| 3757 | 3757 | // Test freeing partially allocated structs |
| 3758 | 3758 | { |
| ... | ... | @@ -3771,7 +3771,7 @@ test "std.zon free on error" { |
| 3771 | 3771 | \\ .z = "fail", |
| 3772 | 3772 | \\} |
| 3773 | 3773 | , |
| 3774 | | .errors = &errors, |
| 3774 | .diagnostics = &diagnostics, |
| 3775 | 3775 | })); |
| 3776 | 3776 | } |
| 3777 | 3777 | |
| ... | ... | @@ -3792,7 +3792,7 @@ test "std.zon free on error" { |
| 3792 | 3792 | \\ "fail", |
| 3793 | 3793 | \\} |
| 3794 | 3794 | , |
| 3795 | | .errors = &errors, |
| 3795 | .diagnostics = &diagnostics, |
| 3796 | 3796 | })); |
| 3797 | 3797 | } |
| 3798 | 3798 | |
| ... | ... | @@ -3809,7 +3809,7 @@ test "std.zon free on error" { |
| 3809 | 3809 | \\ .x = "hello", |
| 3810 | 3810 | \\} |
| 3811 | 3811 | , |
| 3812 | | .errors = &errors, |
| 3812 | .diagnostics = &diagnostics, |
| 3813 | 3813 | })); |
| 3814 | 3814 | |
| 3815 | 3815 | // Test freeing partially allocated arrays |
| ... | ... | @@ -3823,7 +3823,7 @@ test "std.zon free on error" { |
| 3823 | 3823 | \\ false, |
| 3824 | 3824 | \\} |
| 3825 | 3825 | , |
| 3826 | | .errors = &errors, |
| 3826 | .diagnostics = &diagnostics, |
| 3827 | 3827 | })); |
| 3828 | 3828 | |
| 3829 | 3829 | // Test freeing partially allocated slices |
| ... | ... | @@ -3837,7 +3837,7 @@ test "std.zon free on error" { |
| 3837 | 3837 | \\ false, |
| 3838 | 3838 | \\} |
| 3839 | 3839 | , |
| 3840 | | .errors = &errors, |
| 3840 | .diagnostics = &diagnostics, |
| 3841 | 3841 | })); |
| 3842 | 3842 | |
| 3843 | 3843 | // We can parse types that can't be freed, as long as they contain no allocations, e.g. untagged |
| ... | ... | @@ -3848,7 +3848,7 @@ test "std.zon free on error" { |
| 3848 | 3848 | .gpa = gpa, |
| 3849 | 3849 | .arena = arena, |
| 3850 | 3850 | .source = ".{ .x = 1.5 }", |
| 3851 | | .errors = &errors, |
| 3851 | .diagnostics = &diagnostics, |
| 3852 | 3852 | })).x, |
| 3853 | 3853 | ); |
| 3854 | 3854 | |
| ... | ... | @@ -3859,7 +3859,7 @@ test "std.zon free on error" { |
| 3859 | 3859 | .gpa = gpa, |
| 3860 | 3860 | .arena = arena, |
| 3861 | 3861 | .source = ".{ .x = \"foo\" }", |
| 3862 | | .errors = &errors, |
| 3862 | .diagnostics = &diagnostics, |
| 3863 | 3863 | }); |
| 3864 | 3864 | try std.testing.expectEqualStrings("foo", result.x); |
| 3865 | 3865 | } |
| ... | ... | @@ -3873,7 +3873,7 @@ test "std.zon vector" { |
| 3873 | 3873 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 3874 | 3874 | defer arena_allocator.deinit(); |
| 3875 | 3875 | const arena = arena_allocator.allocator(); |
| 3876 | | var errors: Errors = .empty; |
| 3876 | var diagnostics: Diagnostics = .empty; |
| 3877 | 3877 | |
| 3878 | 3878 | // Passing cases |
| 3879 | 3879 | try std.testing.expectEqual( |
| ... | ... | @@ -3882,7 +3882,7 @@ test "std.zon vector" { |
| 3882 | 3882 | .gpa = gpa, |
| 3883 | 3883 | .arena = arena, |
| 3884 | 3884 | .source = ".{}", |
| 3885 | | .errors = &errors, |
| 3885 | .diagnostics = &diagnostics, |
| 3886 | 3886 | }), |
| 3887 | 3887 | ); |
| 3888 | 3888 | try std.testing.expectEqual( |
| ... | ... | @@ -3891,7 +3891,7 @@ test "std.zon vector" { |
| 3891 | 3891 | .gpa = gpa, |
| 3892 | 3892 | .arena = arena, |
| 3893 | 3893 | .source = ".{true, false, true}", |
| 3894 | | .errors = &errors, |
| 3894 | .diagnostics = &diagnostics, |
| 3895 | 3895 | }), |
| 3896 | 3896 | ); |
| 3897 | 3897 | |
| ... | ... | @@ -3901,7 +3901,7 @@ test "std.zon vector" { |
| 3901 | 3901 | .gpa = gpa, |
| 3902 | 3902 | .arena = arena, |
| 3903 | 3903 | .source = ".{}", |
| 3904 | | .errors = &errors, |
| 3904 | .diagnostics = &diagnostics, |
| 3905 | 3905 | }), |
| 3906 | 3906 | ); |
| 3907 | 3907 | try std.testing.expectEqual( |
| ... | ... | @@ -3910,7 +3910,7 @@ test "std.zon vector" { |
| 3910 | 3910 | .gpa = gpa, |
| 3911 | 3911 | .arena = arena, |
| 3912 | 3912 | .source = ".{1.5, 2.5, 3.5}", |
| 3913 | | .errors = &errors, |
| 3913 | .diagnostics = &diagnostics, |
| 3914 | 3914 | }), |
| 3915 | 3915 | ); |
| 3916 | 3916 | |
| ... | ... | @@ -3920,7 +3920,7 @@ test "std.zon vector" { |
| 3920 | 3920 | .gpa = gpa, |
| 3921 | 3921 | .arena = arena, |
| 3922 | 3922 | .source = ".{}", |
| 3923 | | .errors = &errors, |
| 3923 | .diagnostics = &diagnostics, |
| 3924 | 3924 | }), |
| 3925 | 3925 | ); |
| 3926 | 3926 | try std.testing.expectEqual( |
| ... | ... | @@ -3929,7 +3929,7 @@ test "std.zon vector" { |
| 3929 | 3929 | .gpa = gpa, |
| 3930 | 3930 | .arena = arena, |
| 3931 | 3931 | .source = ".{2, 4, 6}", |
| 3932 | | .errors = &errors, |
| 3932 | .diagnostics = &diagnostics, |
| 3933 | 3933 | }), |
| 3934 | 3934 | ); |
| 3935 | 3935 | |
| ... | ... | @@ -3940,14 +3940,14 @@ test "std.zon vector" { |
| 3940 | 3940 | .gpa = gpa, |
| 3941 | 3941 | .arena = arena, |
| 3942 | 3942 | .source = ".{}", |
| 3943 | | .errors = &errors, |
| 3943 | .diagnostics = &diagnostics, |
| 3944 | 3944 | }), |
| 3945 | 3945 | ); |
| 3946 | 3946 | const pointers = try fromSlice(@Vector(3, *const u8), .{ |
| 3947 | 3947 | .gpa = gpa, |
| 3948 | 3948 | .arena = arena, |
| 3949 | 3949 | .source = ".{2, 4, 6}", |
| 3950 | | .errors = &errors, |
| 3950 | .diagnostics = &diagnostics, |
| 3951 | 3951 | }); |
| 3952 | 3952 | try std.testing.expectEqualDeep(@Vector(3, *const u8){ &2, &4, &6 }, pointers); |
| 3953 | 3953 | } |
| ... | ... | @@ -3959,14 +3959,14 @@ test "std.zon vector" { |
| 3959 | 3959 | .gpa = gpa, |
| 3960 | 3960 | .arena = arena, |
| 3961 | 3961 | .source = ".{}", |
| 3962 | | .errors = &errors, |
| 3962 | .diagnostics = &diagnostics, |
| 3963 | 3963 | }), |
| 3964 | 3964 | ); |
| 3965 | 3965 | const pointers = try fromSlice(@Vector(3, ?*const u8), .{ |
| 3966 | 3966 | .gpa = gpa, |
| 3967 | 3967 | .arena = arena, |
| 3968 | 3968 | .source = ".{2, null, 6}", |
| 3969 | | .errors = &errors, |
| 3969 | .diagnostics = &diagnostics, |
| 3970 | 3970 | }); |
| 3971 | 3971 | try std.testing.expectEqualDeep(@Vector(3, ?*const u8){ &2, null, &6 }, pointers); |
| 3972 | 3972 | } |
| ... | ... | @@ -3979,13 +3979,13 @@ test "std.zon vector" { |
| 3979 | 3979 | .gpa = gpa, |
| 3980 | 3980 | .arena = arena, |
| 3981 | 3981 | .source = ".{0.5}", |
| 3982 | | .errors = &errors, |
| 3982 | .diagnostics = &diagnostics, |
| 3983 | 3983 | }), |
| 3984 | 3984 | ); |
| 3985 | 3985 | try std.testing.expectFmt( |
| 3986 | 3986 | \\input.zon:1:2: error: expected 2 array elements; found 1 |
| 3987 | 3987 | \\ |
| 3988 | | , "{f}", .{errors.fmt("input.zon")}); |
| 3988 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 3989 | 3989 | } |
| 3990 | 3990 | |
| 3991 | 3991 | // Too many fields |
| ... | ... | @@ -3996,13 +3996,13 @@ test "std.zon vector" { |
| 3996 | 3996 | .gpa = gpa, |
| 3997 | 3997 | .arena = arena, |
| 3998 | 3998 | .source = ".{0.5, 1.5, 2.5}", |
| 3999 | | .errors = &errors, |
| 3999 | .diagnostics = &diagnostics, |
| 4000 | 4000 | }), |
| 4001 | 4001 | ); |
| 4002 | 4002 | try std.testing.expectFmt( |
| 4003 | 4003 | \\input.zon:1:13: error: index 2 outside of array of length 2 |
| 4004 | 4004 | \\ |
| 4005 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4005 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4006 | 4006 | } |
| 4007 | 4007 | |
| 4008 | 4008 | // Wrong type fields |
| ... | ... | @@ -4013,13 +4013,13 @@ test "std.zon vector" { |
| 4013 | 4013 | .gpa = gpa, |
| 4014 | 4014 | .arena = arena, |
| 4015 | 4015 | .source = ".{0.5, true, 2.5}", |
| 4016 | | .errors = &errors, |
| 4016 | .diagnostics = &diagnostics, |
| 4017 | 4017 | }), |
| 4018 | 4018 | ); |
| 4019 | 4019 | try std.testing.expectFmt( |
| 4020 | 4020 | \\input.zon:1:8: error: expected type 'f32' |
| 4021 | 4021 | \\ |
| 4022 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4022 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4023 | 4023 | } |
| 4024 | 4024 | |
| 4025 | 4025 | // Wrong type |
| ... | ... | @@ -4030,13 +4030,13 @@ test "std.zon vector" { |
| 4030 | 4030 | .gpa = gpa, |
| 4031 | 4031 | .arena = arena, |
| 4032 | 4032 | .source = "true", |
| 4033 | | .errors = &errors, |
| 4033 | .diagnostics = &diagnostics, |
| 4034 | 4034 | }), |
| 4035 | 4035 | ); |
| 4036 | 4036 | try std.testing.expectFmt( |
| 4037 | 4037 | \\input.zon:1:1: error: expected type '@Vector(3, u8)' |
| 4038 | 4038 | \\ |
| 4039 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4039 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4040 | 4040 | } |
| 4041 | 4041 | |
| 4042 | 4042 | // Elements should get freed on error |
| ... | ... | @@ -4047,13 +4047,13 @@ test "std.zon vector" { |
| 4047 | 4047 | .gpa = gpa, |
| 4048 | 4048 | .arena = arena, |
| 4049 | 4049 | .source = ".{1, true, 3}", |
| 4050 | | .errors = &errors, |
| 4050 | .diagnostics = &diagnostics, |
| 4051 | 4051 | }), |
| 4052 | 4052 | ); |
| 4053 | 4053 | try std.testing.expectFmt( |
| 4054 | 4054 | \\input.zon:1:6: error: expected type 'u8' |
| 4055 | 4055 | \\ |
| 4056 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4056 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4057 | 4057 | } |
| 4058 | 4058 | } |
| 4059 | 4059 | |
| ... | ... | @@ -4062,7 +4062,7 @@ test "std.zon add pointers" { |
| 4062 | 4062 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 4063 | 4063 | defer arena_allocator.deinit(); |
| 4064 | 4064 | const arena = arena_allocator.allocator(); |
| 4065 | | var errors: Errors = .empty; |
| 4065 | var diagnostics: Diagnostics = .empty; |
| 4066 | 4066 | |
| 4067 | 4067 | // Primitive with varying levels of pointers |
| 4068 | 4068 | { |
| ... | ... | @@ -4070,7 +4070,7 @@ test "std.zon add pointers" { |
| 4070 | 4070 | .gpa = gpa, |
| 4071 | 4071 | .arena = arena, |
| 4072 | 4072 | .source = "10", |
| 4073 | | .errors = &errors, |
| 4073 | .diagnostics = &diagnostics, |
| 4074 | 4074 | }); |
| 4075 | 4075 | try std.testing.expectEqual(@as(u32, 10), result.*); |
| 4076 | 4076 | } |
| ... | ... | @@ -4080,7 +4080,7 @@ test "std.zon add pointers" { |
| 4080 | 4080 | .gpa = gpa, |
| 4081 | 4081 | .arena = arena, |
| 4082 | 4082 | .source = "10", |
| 4083 | | .errors = &errors, |
| 4083 | .diagnostics = &diagnostics, |
| 4084 | 4084 | }); |
| 4085 | 4085 | try std.testing.expectEqual(@as(u32, 10), result.*.*); |
| 4086 | 4086 | } |
| ... | ... | @@ -4090,7 +4090,7 @@ test "std.zon add pointers" { |
| 4090 | 4090 | .gpa = gpa, |
| 4091 | 4091 | .arena = arena, |
| 4092 | 4092 | .source = "10", |
| 4093 | | .errors = &errors, |
| 4093 | .diagnostics = &diagnostics, |
| 4094 | 4094 | }); |
| 4095 | 4095 | try std.testing.expectEqual(@as(u32, 10), result.*.*.*); |
| 4096 | 4096 | } |
| ... | ... | @@ -4101,7 +4101,7 @@ test "std.zon add pointers" { |
| 4101 | 4101 | .gpa = gpa, |
| 4102 | 4102 | .arena = arena, |
| 4103 | 4103 | .source = "10", |
| 4104 | | .errors = &errors, |
| 4104 | .diagnostics = &diagnostics, |
| 4105 | 4105 | }); |
| 4106 | 4106 | try std.testing.expectEqual(@as(u32, 10), some.?.*); |
| 4107 | 4107 | |
| ... | ... | @@ -4109,7 +4109,7 @@ test "std.zon add pointers" { |
| 4109 | 4109 | .gpa = gpa, |
| 4110 | 4110 | .arena = arena, |
| 4111 | 4111 | .source = "null", |
| 4112 | | .errors = &errors, |
| 4112 | .diagnostics = &diagnostics, |
| 4113 | 4113 | }); |
| 4114 | 4114 | try std.testing.expectEqual(null, none); |
| 4115 | 4115 | } |
| ... | ... | @@ -4119,7 +4119,7 @@ test "std.zon add pointers" { |
| 4119 | 4119 | .gpa = gpa, |
| 4120 | 4120 | .arena = arena, |
| 4121 | 4121 | .source = "10", |
| 4122 | | .errors = &errors, |
| 4122 | .diagnostics = &diagnostics, |
| 4123 | 4123 | }); |
| 4124 | 4124 | try std.testing.expectEqual(@as(u32, 10), some.*.?); |
| 4125 | 4125 | |
| ... | ... | @@ -4127,7 +4127,7 @@ test "std.zon add pointers" { |
| 4127 | 4127 | .gpa = gpa, |
| 4128 | 4128 | .arena = arena, |
| 4129 | 4129 | .source = "null", |
| 4130 | | .errors = &errors, |
| 4130 | .diagnostics = &diagnostics, |
| 4131 | 4131 | }); |
| 4132 | 4132 | try std.testing.expectEqual(null, none.*); |
| 4133 | 4133 | } |
| ... | ... | @@ -4137,7 +4137,7 @@ test "std.zon add pointers" { |
| 4137 | 4137 | .gpa = gpa, |
| 4138 | 4138 | .arena = arena, |
| 4139 | 4139 | .source = "10", |
| 4140 | | .errors = &errors, |
| 4140 | .diagnostics = &diagnostics, |
| 4141 | 4141 | }); |
| 4142 | 4142 | try std.testing.expectEqual(@as(u32, 10), some.?.*.*); |
| 4143 | 4143 | |
| ... | ... | @@ -4145,7 +4145,7 @@ test "std.zon add pointers" { |
| 4145 | 4145 | .gpa = gpa, |
| 4146 | 4146 | .arena = arena, |
| 4147 | 4147 | .source = "null", |
| 4148 | | .errors = &errors, |
| 4148 | .diagnostics = &diagnostics, |
| 4149 | 4149 | }); |
| 4150 | 4150 | try std.testing.expectEqual(null, none); |
| 4151 | 4151 | } |
| ... | ... | @@ -4155,7 +4155,7 @@ test "std.zon add pointers" { |
| 4155 | 4155 | .gpa = gpa, |
| 4156 | 4156 | .arena = arena, |
| 4157 | 4157 | .source = "10", |
| 4158 | | .errors = &errors, |
| 4158 | .diagnostics = &diagnostics, |
| 4159 | 4159 | }); |
| 4160 | 4160 | try std.testing.expectEqual(@as(u32, 10), some.*.?.*); |
| 4161 | 4161 | |
| ... | ... | @@ -4163,7 +4163,7 @@ test "std.zon add pointers" { |
| 4163 | 4163 | .gpa = gpa, |
| 4164 | 4164 | .arena = arena, |
| 4165 | 4165 | .source = "null", |
| 4166 | | .errors = &errors, |
| 4166 | .diagnostics = &diagnostics, |
| 4167 | 4167 | }); |
| 4168 | 4168 | try std.testing.expectEqual(null, none.*); |
| 4169 | 4169 | } |
| ... | ... | @@ -4173,7 +4173,7 @@ test "std.zon add pointers" { |
| 4173 | 4173 | .gpa = gpa, |
| 4174 | 4174 | .arena = arena, |
| 4175 | 4175 | .source = "10", |
| 4176 | | .errors = &errors, |
| 4176 | .diagnostics = &diagnostics, |
| 4177 | 4177 | }); |
| 4178 | 4178 | try std.testing.expectEqual(@as(u32, 10), some.*.*.?); |
| 4179 | 4179 | |
| ... | ... | @@ -4181,7 +4181,7 @@ test "std.zon add pointers" { |
| 4181 | 4181 | .gpa = gpa, |
| 4182 | 4182 | .arena = arena, |
| 4183 | 4183 | .source = "null", |
| 4184 | | .errors = &errors, |
| 4184 | .diagnostics = &diagnostics, |
| 4185 | 4185 | }); |
| 4186 | 4186 | try std.testing.expectEqual(null, none.*.*); |
| 4187 | 4187 | } |
| ... | ... | @@ -4192,7 +4192,7 @@ test "std.zon add pointers" { |
| 4192 | 4192 | .gpa = gpa, |
| 4193 | 4193 | .arena = arena, |
| 4194 | 4194 | .source = ".{ 1, 2, 3 }", |
| 4195 | | .errors = &errors, |
| 4195 | .diagnostics = &diagnostics, |
| 4196 | 4196 | }); |
| 4197 | 4197 | try std.testing.expectEqual([3]u8{ 1, 2, 3 }, result.*); |
| 4198 | 4198 | } |
| ... | ... | @@ -4227,7 +4227,7 @@ test "std.zon add pointers" { |
| 4227 | 4227 | \\ .f2 = null, |
| 4228 | 4228 | \\} |
| 4229 | 4229 | , |
| 4230 | | .errors = &errors, |
| 4230 | .diagnostics = &diagnostics, |
| 4231 | 4231 | }); |
| 4232 | 4232 | |
| 4233 | 4233 | try std.testing.expectEqualDeep(expected, found.?.*); |
| ... | ... | @@ -4241,13 +4241,13 @@ test "std.zon add pointers" { |
| 4241 | 4241 | .gpa = gpa, |
| 4242 | 4242 | .arena = arena, |
| 4243 | 4243 | .source = "true", |
| 4244 | | .errors = &errors, |
| 4244 | .diagnostics = &diagnostics, |
| 4245 | 4245 | }), |
| 4246 | 4246 | ); |
| 4247 | 4247 | try std.testing.expectFmt( |
| 4248 | 4248 | \\input.zon:1:1: error: expected type '?u8' |
| 4249 | 4249 | \\ |
| 4250 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4250 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4251 | 4251 | } |
| 4252 | 4252 | |
| 4253 | 4253 | { |
| ... | ... | @@ -4257,13 +4257,13 @@ test "std.zon add pointers" { |
| 4257 | 4257 | .gpa = gpa, |
| 4258 | 4258 | .arena = arena, |
| 4259 | 4259 | .source = "true", |
| 4260 | | .errors = &errors, |
| 4260 | .diagnostics = &diagnostics, |
| 4261 | 4261 | }), |
| 4262 | 4262 | ); |
| 4263 | 4263 | try std.testing.expectFmt( |
| 4264 | 4264 | \\input.zon:1:1: error: expected type '?f32' |
| 4265 | 4265 | \\ |
| 4266 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4266 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4267 | 4267 | } |
| 4268 | 4268 | |
| 4269 | 4269 | { |
| ... | ... | @@ -4273,13 +4273,13 @@ test "std.zon add pointers" { |
| 4273 | 4273 | .gpa = gpa, |
| 4274 | 4274 | .arena = arena, |
| 4275 | 4275 | .source = "true", |
| 4276 | | .errors = &errors, |
| 4276 | .diagnostics = &diagnostics, |
| 4277 | 4277 | }), |
| 4278 | 4278 | ); |
| 4279 | 4279 | try std.testing.expectFmt( |
| 4280 | 4280 | \\input.zon:1:1: error: expected type '?@Vector(3, u8)' |
| 4281 | 4281 | \\ |
| 4282 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4282 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4283 | 4283 | } |
| 4284 | 4284 | |
| 4285 | 4285 | { |
| ... | ... | @@ -4289,13 +4289,13 @@ test "std.zon add pointers" { |
| 4289 | 4289 | .gpa = gpa, |
| 4290 | 4290 | .arena = arena, |
| 4291 | 4291 | .source = "10", |
| 4292 | | .errors = &errors, |
| 4292 | .diagnostics = &diagnostics, |
| 4293 | 4293 | }), |
| 4294 | 4294 | ); |
| 4295 | 4295 | try std.testing.expectFmt( |
| 4296 | 4296 | \\input.zon:1:1: error: expected type '?bool' |
| 4297 | 4297 | \\ |
| 4298 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4298 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4299 | 4299 | } |
| 4300 | 4300 | |
| 4301 | 4301 | { |
| ... | ... | @@ -4305,13 +4305,13 @@ test "std.zon add pointers" { |
| 4305 | 4305 | .gpa = gpa, |
| 4306 | 4306 | .arena = arena, |
| 4307 | 4307 | .source = "true", |
| 4308 | | .errors = &errors, |
| 4308 | .diagnostics = &diagnostics, |
| 4309 | 4309 | }), |
| 4310 | 4310 | ); |
| 4311 | 4311 | try std.testing.expectFmt( |
| 4312 | 4312 | \\input.zon:1:1: error: expected optional struct |
| 4313 | 4313 | \\ |
| 4314 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4314 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4315 | 4315 | } |
| 4316 | 4316 | |
| 4317 | 4317 | { |
| ... | ... | @@ -4321,13 +4321,13 @@ test "std.zon add pointers" { |
| 4321 | 4321 | .gpa = gpa, |
| 4322 | 4322 | .arena = arena, |
| 4323 | 4323 | .source = "true", |
| 4324 | | .errors = &errors, |
| 4324 | .diagnostics = &diagnostics, |
| 4325 | 4325 | }), |
| 4326 | 4326 | ); |
| 4327 | 4327 | try std.testing.expectFmt( |
| 4328 | 4328 | \\input.zon:1:1: error: expected optional tuple |
| 4329 | 4329 | \\ |
| 4330 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4330 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4331 | 4331 | } |
| 4332 | 4332 | |
| 4333 | 4333 | { |
| ... | ... | @@ -4337,13 +4337,13 @@ test "std.zon add pointers" { |
| 4337 | 4337 | .gpa = gpa, |
| 4338 | 4338 | .arena = arena, |
| 4339 | 4339 | .source = "true", |
| 4340 | | .errors = &errors, |
| 4340 | .diagnostics = &diagnostics, |
| 4341 | 4341 | }), |
| 4342 | 4342 | ); |
| 4343 | 4343 | try std.testing.expectFmt( |
| 4344 | 4344 | \\input.zon:1:1: error: expected optional union |
| 4345 | 4345 | \\ |
| 4346 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4346 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4347 | 4347 | } |
| 4348 | 4348 | |
| 4349 | 4349 | { |
| ... | ... | @@ -4353,13 +4353,13 @@ test "std.zon add pointers" { |
| 4353 | 4353 | .gpa = gpa, |
| 4354 | 4354 | .arena = arena, |
| 4355 | 4355 | .source = "true", |
| 4356 | | .errors = &errors, |
| 4356 | .diagnostics = &diagnostics, |
| 4357 | 4357 | }), |
| 4358 | 4358 | ); |
| 4359 | 4359 | try std.testing.expectFmt( |
| 4360 | 4360 | \\input.zon:1:1: error: expected optional array |
| 4361 | 4361 | \\ |
| 4362 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4362 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4363 | 4363 | } |
| 4364 | 4364 | |
| 4365 | 4365 | { |
| ... | ... | @@ -4369,13 +4369,13 @@ test "std.zon add pointers" { |
| 4369 | 4369 | .gpa = gpa, |
| 4370 | 4370 | .arena = arena, |
| 4371 | 4371 | .source = "true", |
| 4372 | | .errors = &errors, |
| 4372 | .diagnostics = &diagnostics, |
| 4373 | 4373 | }), |
| 4374 | 4374 | ); |
| 4375 | 4375 | try std.testing.expectFmt( |
| 4376 | 4376 | \\input.zon:1:1: error: expected optional array |
| 4377 | 4377 | \\ |
| 4378 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4378 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4379 | 4379 | } |
| 4380 | 4380 | |
| 4381 | 4381 | { |
| ... | ... | @@ -4385,13 +4385,13 @@ test "std.zon add pointers" { |
| 4385 | 4385 | .gpa = gpa, |
| 4386 | 4386 | .arena = arena, |
| 4387 | 4387 | .source = "true", |
| 4388 | | .errors = &errors, |
| 4388 | .diagnostics = &diagnostics, |
| 4389 | 4389 | }), |
| 4390 | 4390 | ); |
| 4391 | 4391 | try std.testing.expectFmt( |
| 4392 | 4392 | \\input.zon:1:1: error: expected optional array |
| 4393 | 4393 | \\ |
| 4394 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4394 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4395 | 4395 | } |
| 4396 | 4396 | |
| 4397 | 4397 | { |
| ... | ... | @@ -4401,13 +4401,13 @@ test "std.zon add pointers" { |
| 4401 | 4401 | .gpa = gpa, |
| 4402 | 4402 | .arena = arena, |
| 4403 | 4403 | .source = "true", |
| 4404 | | .errors = &errors, |
| 4404 | .diagnostics = &diagnostics, |
| 4405 | 4405 | }), |
| 4406 | 4406 | ); |
| 4407 | 4407 | try std.testing.expectFmt( |
| 4408 | 4408 | \\input.zon:1:1: error: expected optional array |
| 4409 | 4409 | \\ |
| 4410 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4410 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4411 | 4411 | } |
| 4412 | 4412 | |
| 4413 | 4413 | { |
| ... | ... | @@ -4417,13 +4417,13 @@ test "std.zon add pointers" { |
| 4417 | 4417 | .gpa = gpa, |
| 4418 | 4418 | .arena = arena, |
| 4419 | 4419 | .source = "true", |
| 4420 | | .errors = &errors, |
| 4420 | .diagnostics = &diagnostics, |
| 4421 | 4421 | }), |
| 4422 | 4422 | ); |
| 4423 | 4423 | try std.testing.expectFmt( |
| 4424 | 4424 | \\input.zon:1:1: error: expected optional string |
| 4425 | 4425 | \\ |
| 4426 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4426 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4427 | 4427 | } |
| 4428 | 4428 | |
| 4429 | 4429 | { |
| ... | ... | @@ -4433,13 +4433,13 @@ test "std.zon add pointers" { |
| 4433 | 4433 | .gpa = gpa, |
| 4434 | 4434 | .arena = arena, |
| 4435 | 4435 | .source = "true", |
| 4436 | | .errors = &errors, |
| 4436 | .diagnostics = &diagnostics, |
| 4437 | 4437 | }), |
| 4438 | 4438 | ); |
| 4439 | 4439 | try std.testing.expectFmt( |
| 4440 | 4440 | \\input.zon:1:1: error: expected optional enum literal |
| 4441 | 4441 | \\ |
| 4442 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4442 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4443 | 4443 | } |
| 4444 | 4444 | } |
| 4445 | 4445 | |
| ... | ... | @@ -4448,7 +4448,7 @@ test "std.zon stop on node" { |
| 4448 | 4448 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 4449 | 4449 | defer arena_allocator.deinit(); |
| 4450 | 4450 | const arena = arena_allocator.allocator(); |
| 4451 | | var errors: Errors = .empty; |
| 4451 | var diagnostics: Diagnostics = .empty; |
| 4452 | 4452 | |
| 4453 | 4453 | { |
| 4454 | 4454 | const Vec2 = struct { |
| ... | ... | @@ -4466,7 +4466,7 @@ test "std.zon stop on node" { |
| 4466 | 4466 | .arena = arena, |
| 4467 | 4467 | .ast = &ast, |
| 4468 | 4468 | .zoir = &zoir, |
| 4469 | | .errors = &errors, |
| 4469 | .diagnostics = &diagnostics, |
| 4470 | 4470 | }); |
| 4471 | 4471 | |
| 4472 | 4472 | try std.testing.expectEqual(result.y, 2.5); |
| ... | ... | @@ -4484,7 +4484,7 @@ test "std.zon stop on node" { |
| 4484 | 4484 | .arena = arena, |
| 4485 | 4485 | .ast = &ast, |
| 4486 | 4486 | .zoir = &zoir, |
| 4487 | | .errors = &errors, |
| 4487 | .diagnostics = &diagnostics, |
| 4488 | 4488 | }); |
| 4489 | 4489 | try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.23 }, result.get(&zoir)); |
| 4490 | 4490 | } |
| ... | ... | @@ -4495,7 +4495,7 @@ test "std.zon no alloc" { |
| 4495 | 4495 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 4496 | 4496 | defer arena_allocator.deinit(); |
| 4497 | 4497 | const arena = arena_allocator.allocator(); |
| 4498 | | var errors: Errors = .empty; |
| 4498 | var diagnostics: Diagnostics = .empty; |
| 4499 | 4499 | |
| 4500 | 4500 | try std.testing.expectEqual( |
| 4501 | 4501 | [3]u8{ 1, 2, 3 }, |
| ... | ... | @@ -4503,7 +4503,7 @@ test "std.zon no alloc" { |
| 4503 | 4503 | .gpa = gpa, |
| 4504 | 4504 | .arena = arena, |
| 4505 | 4505 | .source = ".{ 1, 2, 3 }", |
| 4506 | | .errors = &errors, |
| 4506 | .diagnostics = &diagnostics, |
| 4507 | 4507 | }), |
| 4508 | 4508 | ); |
| 4509 | 4509 | |
| ... | ... | @@ -4521,64 +4521,17 @@ test "std.zon no alloc" { |
| 4521 | 4521 | .arena = arena, |
| 4522 | 4522 | .ast = &ast, |
| 4523 | 4523 | .zoir = &zoir, |
| 4524 | | .errors = &errors, |
| 4524 | .diagnostics = &diagnostics, |
| 4525 | 4525 | }), |
| 4526 | 4526 | ); |
| 4527 | 4527 | } |
| 4528 | 4528 | |
| 4529 | | test "std.zon errors without errorsnostics" { |
| 4530 | | const gpa = std.testing.allocator; |
| 4531 | | var arena_allocator: ArenaAllocator = .init(gpa); |
| 4532 | | defer arena_allocator.deinit(); |
| 4533 | | const arena = arena_allocator.allocator(); |
| 4534 | | var errors: Errors = .empty; |
| 4535 | | |
| 4536 | | const Enum = enum { |
| 4537 | | foo, |
| 4538 | | bar, |
| 4539 | | baz, |
| 4540 | | }; |
| 4541 | | try std.testing.expectError(error.ParseZon, fromSlice(Enum, .{ |
| 4542 | | .gpa = gpa, |
| 4543 | | .arena = arena, |
| 4544 | | .source = ".nothing", |
| 4545 | | .errors = &errors, |
| 4546 | | })); |
| 4547 | | |
| 4548 | | const Struct = struct { |
| 4549 | | name: []const u8, |
| 4550 | | }; |
| 4551 | | try std.testing.expectError(error.ParseZon, fromSlice(Struct, .{ |
| 4552 | | .gpa = gpa, |
| 4553 | | .arena = arena, |
| 4554 | | .source = ".{ .name = \"Alice\", .age = 25 }", |
| 4555 | | .errors = &errors, |
| 4556 | | })); |
| 4557 | | |
| 4558 | | const Union = union(enum) { |
| 4559 | | x, |
| 4560 | | y: u32, |
| 4561 | | }; |
| 4562 | | try std.testing.expectError(error.ParseZon, fromSlice(Union, .{ |
| 4563 | | .gpa = gpa, |
| 4564 | | .arena = arena, |
| 4565 | | .source = ".a", |
| 4566 | | .errors = &errors, |
| 4567 | | })); |
| 4568 | | try std.testing.expectError(error.ParseZon, fromSlice(Union, .{ |
| 4569 | | .gpa = gpa, |
| 4570 | | .arena = arena, |
| 4571 | | .source = ".{ .b = 8 }", |
| 4572 | | .errors = &errors, |
| 4573 | | })); |
| 4574 | | } |
| 4575 | | |
| 4576 | 4529 | test "std.zon aligned pointers" { |
| 4577 | 4530 | const gpa = std.testing.allocator; |
| 4578 | 4531 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 4579 | 4532 | defer arena_allocator.deinit(); |
| 4580 | 4533 | const arena = arena_allocator.allocator(); |
| 4581 | | var errors: Errors = .empty; |
| 4534 | var diagnostics: Diagnostics = .empty; |
| 4582 | 4535 | |
| 4583 | 4536 | const n: u8 align(8) = 10; |
| 4584 | 4537 | const Foo = struct { |
| ... | ... | @@ -4592,7 +4545,7 @@ test "std.zon aligned pointers" { |
| 4592 | 4545 | .gpa = gpa, |
| 4593 | 4546 | .arena = arena, |
| 4594 | 4547 | .source = ".{ .inner = 10 }", |
| 4595 | | .errors = &errors, |
| 4548 | .diagnostics = &diagnostics, |
| 4596 | 4549 | }); |
| 4597 | 4550 | try std.testing.expectEqualDeep(expected.inner, found.inner); |
| 4598 | 4551 | } |
| ... | ... | @@ -4602,7 +4555,7 @@ test "std.zon update basic" { |
| 4602 | 4555 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 4603 | 4556 | defer arena_allocator.deinit(); |
| 4604 | 4557 | const arena = arena_allocator.allocator(); |
| 4605 | | var errors: Errors = .empty; |
| 4558 | var diagnostics: Diagnostics = .empty; |
| 4606 | 4559 | |
| 4607 | 4560 | const Vector = struct { x: f32, y: f32, z: f32 }; |
| 4608 | 4561 | const MyStruct = struct { |
| ... | ... | @@ -4638,7 +4591,7 @@ test "std.zon update basic" { |
| 4638 | 4591 | .gpa = gpa, |
| 4639 | 4592 | .arena = arena, |
| 4640 | 4593 | .source = ".{}", |
| 4641 | | .errors = &errors, |
| 4594 | .diagnostics = &diagnostics, |
| 4642 | 4595 | }); |
| 4643 | 4596 | try std.testing.expectEqualDeep(expected, found); |
| 4644 | 4597 | |
| ... | ... | @@ -4646,7 +4599,7 @@ test "std.zon update basic" { |
| 4646 | 4599 | .gpa = gpa, |
| 4647 | 4600 | .arena = arena, |
| 4648 | 4601 | .source = ".{ .bar = false }", |
| 4649 | | .errors = &errors, |
| 4602 | .diagnostics = &diagnostics, |
| 4650 | 4603 | }); |
| 4651 | 4604 | expected.bar = false; |
| 4652 | 4605 | try std.testing.expectEqualDeep(expected, found); |
| ... | ... | @@ -4655,7 +4608,7 @@ test "std.zon update basic" { |
| 4655 | 4608 | .gpa = gpa, |
| 4656 | 4609 | .arena = arena, |
| 4657 | 4610 | .source = ".{ .baz = .{ .a = .{ 2, 4 } } }", |
| 4658 | | .errors = &errors, |
| 4611 | .diagnostics = &diagnostics, |
| 4659 | 4612 | }); |
| 4660 | 4613 | expected.baz.a[0] = 2; |
| 4661 | 4614 | expected.baz.a[1] = 4; |
| ... | ... | @@ -4665,7 +4618,7 @@ test "std.zon update basic" { |
| 4665 | 4618 | .gpa = gpa, |
| 4666 | 4619 | .arena = arena, |
| 4667 | 4620 | .source = ".{ .foo = 11, .baz = .{ .b = .d } }", |
| 4668 | | .errors = &errors, |
| 4621 | .diagnostics = &diagnostics, |
| 4669 | 4622 | }); |
| 4670 | 4623 | expected.foo = 11; |
| 4671 | 4624 | expected.baz.b = .d; |
| ... | ... | @@ -4675,7 +4628,7 @@ test "std.zon update basic" { |
| 4675 | 4628 | .gpa = gpa, |
| 4676 | 4629 | .arena = arena, |
| 4677 | 4630 | .source = ".{ .optional = 10 }", |
| 4678 | | .errors = &errors, |
| 4631 | .diagnostics = &diagnostics, |
| 4679 | 4632 | }); |
| 4680 | 4633 | expected.optional = 10; |
| 4681 | 4634 | try std.testing.expectEqualDeep(expected, found); |
| ... | ... | @@ -4684,7 +4637,7 @@ test "std.zon update basic" { |
| 4684 | 4637 | .gpa = gpa, |
| 4685 | 4638 | .arena = arena, |
| 4686 | 4639 | .source = ".{ .optional = null }", |
| 4687 | | .errors = &errors, |
| 4640 | .diagnostics = &diagnostics, |
| 4688 | 4641 | }); |
| 4689 | 4642 | expected.optional = null; |
| 4690 | 4643 | try std.testing.expectEqualDeep(expected, found); |
| ... | ... | @@ -4693,7 +4646,7 @@ test "std.zon update basic" { |
| 4693 | 4646 | .gpa = gpa, |
| 4694 | 4647 | .arena = arena, |
| 4695 | 4648 | .source = ".{ .ptr = .{ .x = 10, .y = 20, .z = 30 } }", |
| 4696 | | .errors = &errors, |
| 4649 | .diagnostics = &diagnostics, |
| 4697 | 4650 | }); |
| 4698 | 4651 | expected.ptr.x = 10; |
| 4699 | 4652 | expected.ptr.y = 20; |
| ... | ... | @@ -4704,7 +4657,7 @@ test "std.zon update basic" { |
| 4704 | 4657 | .gpa = gpa, |
| 4705 | 4658 | .arena = arena, |
| 4706 | 4659 | .source = ".{ .str = \"foo\" }", |
| 4707 | | .errors = &errors, |
| 4660 | .diagnostics = &diagnostics, |
| 4708 | 4661 | }); |
| 4709 | 4662 | expected.str = "foo"; |
| 4710 | 4663 | try std.testing.expectEqualDeep(expected, found); |
| ... | ... | @@ -4715,7 +4668,7 @@ test "std.zon update optionals" { |
| 4715 | 4668 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 4716 | 4669 | defer arena_allocator.deinit(); |
| 4717 | 4670 | const arena = arena_allocator.allocator(); |
| 4718 | | var errors: Errors = .empty; |
| 4671 | var diagnostics: Diagnostics = .empty; |
| 4719 | 4672 | |
| 4720 | 4673 | const MyStruct = struct { |
| 4721 | 4674 | foo: ?struct { bar: u32 = 1, baz: u32 = 2, qux: u32 }, |
| ... | ... | @@ -4729,7 +4682,7 @@ test "std.zon update optionals" { |
| 4729 | 4682 | .gpa = gpa, |
| 4730 | 4683 | .arena = arena, |
| 4731 | 4684 | .source = ".{ .foo = .{ .qux = 3 } }", |
| 4732 | | .errors = &errors, |
| 4685 | .diagnostics = &diagnostics, |
| 4733 | 4686 | }); |
| 4734 | 4687 | expected.foo = .{ .qux = 3 }; |
| 4735 | 4688 | try std.testing.expectEqual(expected, found); |
| ... | ... | @@ -4742,12 +4695,12 @@ test "std.zon update optionals" { |
| 4742 | 4695 | .gpa = gpa, |
| 4743 | 4696 | .arena = arena, |
| 4744 | 4697 | .source = ".{ .foo = .{} }", |
| 4745 | | .errors = &errors, |
| 4698 | .diagnostics = &diagnostics, |
| 4746 | 4699 | })); |
| 4747 | 4700 | try std.testing.expectFmt( |
| 4748 | 4701 | \\input.zon:1:12: error: missing required field qux |
| 4749 | 4702 | \\ |
| 4750 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4703 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4751 | 4704 | } |
| 4752 | 4705 | |
| 4753 | 4706 | // Updating an optional that starts out non-null should preserve any values we leave off. It's |
| ... | ... | @@ -4761,7 +4714,7 @@ test "std.zon update optionals" { |
| 4761 | 4714 | .gpa = gpa, |
| 4762 | 4715 | .arena = arena, |
| 4763 | 4716 | .source = ".{ .foo = .{ .baz = 200 } }", |
| 4764 | | .errors = &errors, |
| 4717 | .diagnostics = &diagnostics, |
| 4765 | 4718 | }); |
| 4766 | 4719 | expected.foo.?.baz = 200; |
| 4767 | 4720 | try std.testing.expectEqual(expected, found); |
| ... | ... | @@ -4773,7 +4726,7 @@ test "std.zon update optional pointers" { |
| 4773 | 4726 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 4774 | 4727 | defer arena_allocator.deinit(); |
| 4775 | 4728 | const arena = arena_allocator.allocator(); |
| 4776 | | var errors: Errors = .empty; |
| 4729 | var diagnostics: Diagnostics = .empty; |
| 4777 | 4730 | |
| 4778 | 4731 | const MyStruct = struct { |
| 4779 | 4732 | foo: ?*const struct { bar: u32 = 1, baz: u32 = 2, qux: u32 }, |
| ... | ... | @@ -4787,7 +4740,7 @@ test "std.zon update optional pointers" { |
| 4787 | 4740 | .gpa = gpa, |
| 4788 | 4741 | .arena = arena, |
| 4789 | 4742 | .source = ".{ .foo = .{ .qux = 3 } }", |
| 4790 | | .errors = &errors, |
| 4743 | .diagnostics = &diagnostics, |
| 4791 | 4744 | }); |
| 4792 | 4745 | expected.foo = &.{ .qux = 3 }; |
| 4793 | 4746 | try std.testing.expectEqualDeep(expected, found); |
| ... | ... | @@ -4799,7 +4752,7 @@ test "std.zon update pointers" { |
| 4799 | 4752 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 4800 | 4753 | defer arena_allocator.deinit(); |
| 4801 | 4754 | const arena = arena_allocator.allocator(); |
| 4802 | | var errors: Errors = .empty; |
| 4755 | var diagnostics: Diagnostics = .empty; |
| 4803 | 4756 | |
| 4804 | 4757 | // Updating a pointer should leave fields we don't specify unchanged |
| 4805 | 4758 | { |
| ... | ... | @@ -4813,7 +4766,7 @@ test "std.zon update pointers" { |
| 4813 | 4766 | .gpa = gpa, |
| 4814 | 4767 | .arena = arena, |
| 4815 | 4768 | .source = ".{ .foo = .{ .bar = 100 } }", |
| 4816 | | .errors = &errors, |
| 4769 | .diagnostics = &diagnostics, |
| 4817 | 4770 | }); |
| 4818 | 4771 | expected.foo.bar = 100; |
| 4819 | 4772 | try std.testing.expectEqualDeep(expected, found); |
| ... | ... | @@ -4830,7 +4783,7 @@ test "std.zon update pointers" { |
| 4830 | 4783 | .gpa = gpa, |
| 4831 | 4784 | .arena = arena, |
| 4832 | 4785 | .source = ".{ .foo = .{ .bar = 100 } }", |
| 4833 | | .errors = &errors, |
| 4786 | .diagnostics = &diagnostics, |
| 4834 | 4787 | }); |
| 4835 | 4788 | expected.foo = &.{ .bar = 100, .baz = 20, .qux = 3 }; |
| 4836 | 4789 | try std.testing.expectEqualDeep(expected, found); |
| ... | ... | @@ -4842,7 +4795,7 @@ test "std.zon update unions" { |
| 4842 | 4795 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 4843 | 4796 | defer arena_allocator.deinit(); |
| 4844 | 4797 | const arena = arena_allocator.allocator(); |
| 4845 | | var errors: Errors = .empty; |
| 4798 | var diagnostics: Diagnostics = .empty; |
| 4846 | 4799 | |
| 4847 | 4800 | const MyUnion = union(enum) { |
| 4848 | 4801 | none: void, |
| ... | ... | @@ -4857,7 +4810,7 @@ test "std.zon update unions" { |
| 4857 | 4810 | .gpa = gpa, |
| 4858 | 4811 | .arena = arena, |
| 4859 | 4812 | .source = ".{ .foo = .{ .qux = 3 } }", |
| 4860 | | .errors = &errors, |
| 4813 | .diagnostics = &diagnostics, |
| 4861 | 4814 | }); |
| 4862 | 4815 | expected = .{ .foo = .{ .qux = 3 } }; |
| 4863 | 4816 | try std.testing.expectEqual(expected, found); |
| ... | ... | @@ -4870,12 +4823,12 @@ test "std.zon update unions" { |
| 4870 | 4823 | .gpa = gpa, |
| 4871 | 4824 | .arena = arena, |
| 4872 | 4825 | .source = ".{ .foo = .{} }", |
| 4873 | | .errors = &errors, |
| 4826 | .diagnostics = &diagnostics, |
| 4874 | 4827 | })); |
| 4875 | 4828 | try std.testing.expectFmt( |
| 4876 | 4829 | \\input.zon:1:12: error: missing required field qux |
| 4877 | 4830 | \\ |
| 4878 | | , "{f}", .{errors.fmt("input.zon")}); |
| 4831 | , "{f}", .{diagnostics.fmt("input.zon")}); |
| 4879 | 4832 | } |
| 4880 | 4833 | |
| 4881 | 4834 | // Updating a union should preseve any sub-fields that we left off. It's also okay to leave off |
| ... | ... | @@ -4889,7 +4842,7 @@ test "std.zon update unions" { |
| 4889 | 4842 | .gpa = gpa, |
| 4890 | 4843 | .arena = arena, |
| 4891 | 4844 | .source = ".{ .foo = .{ .baz = 200 } }", |
| 4892 | | .errors = &errors, |
| 4845 | .diagnostics = &diagnostics, |
| 4893 | 4846 | }); |
| 4894 | 4847 | expected.foo.baz = 200; |
| 4895 | 4848 | try std.testing.expectEqual(expected, found); |
| ... | ... | @@ -4904,7 +4857,7 @@ test "std.zon variants" { |
| 4904 | 4857 | var arena_allocator: ArenaAllocator = .init(gpa); |
| 4905 | 4858 | defer arena_allocator.deinit(); |
| 4906 | 4859 | const arena = arena_allocator.allocator(); |
| 4907 | | var errors: Errors = .empty; |
| 4860 | var diagnostics: Diagnostics = .empty; |
| 4908 | 4861 | |
| 4909 | 4862 | const Struct = struct { a: u32, b: u32 }; |
| 4910 | 4863 | const start: Struct = .{ .a = 10, .b = 20 }; |
| ... | ... | @@ -4922,7 +4875,7 @@ test "std.zon variants" { |
| 4922 | 4875 | .gpa = gpa, |
| 4923 | 4876 | .arena = arena, |
| 4924 | 4877 | .source = ".{ .a = 100 }", |
| 4925 | | .errors = &errors, |
| 4878 | .diagnostics = &diagnostics, |
| 4926 | 4879 | }); |
| 4927 | 4880 | try std.testing.expectEqual(end, curr); |
| 4928 | 4881 | |
| ... | ... | @@ -4931,7 +4884,7 @@ test "std.zon variants" { |
| 4931 | 4884 | .gpa = gpa, |
| 4932 | 4885 | .arena = arena, |
| 4933 | 4886 | .source = ".{ .a = 100 }", |
| 4934 | | .errors = &errors, |
| 4887 | .diagnostics = &diagnostics, |
| 4935 | 4888 | }); |
| 4936 | 4889 | try std.testing.expectEqual(end, curr); |
| 4937 | 4890 | |
| ... | ... | @@ -4940,7 +4893,7 @@ test "std.zon variants" { |
| 4940 | 4893 | .arena = arena, |
| 4941 | 4894 | .ast = &ast, |
| 4942 | 4895 | .zoir = &zoir, |
| 4943 | | .errors = &errors, |
| 4896 | .diagnostics = &diagnostics, |
| 4944 | 4897 | }); |
| 4945 | 4898 | try std.testing.expectEqual(end, curr); |
| 4946 | 4899 | |
| ... | ... | @@ -4949,7 +4902,7 @@ test "std.zon variants" { |
| 4949 | 4902 | .arena = arena, |
| 4950 | 4903 | .ast = &ast, |
| 4951 | 4904 | .zoir = &zoir, |
| 4952 | | .errors = &errors, |
| 4905 | .diagnostics = &diagnostics, |
| 4953 | 4906 | }); |
| 4954 | 4907 | try std.testing.expectEqual(end, curr); |
| 4955 | 4908 | } |
| ... | ... | @@ -4967,7 +4920,7 @@ test "std.zon variants" { |
| 4967 | 4920 | .gpa = gpa, |
| 4968 | 4921 | .arena = arena, |
| 4969 | 4922 | .source = ".{ .a = 100, .b = 20 }", |
| 4970 | | .errors = &errors, |
| 4923 | .diagnostics = &diagnostics, |
| 4971 | 4924 | }), |
| 4972 | 4925 | ); |
| 4973 | 4926 | try std.testing.expectEqual( |
| ... | ... | @@ -4976,7 +4929,7 @@ test "std.zon variants" { |
| 4976 | 4929 | .gpa = gpa, |
| 4977 | 4930 | .arena = arena, |
| 4978 | 4931 | .source = ".{ .a = 100, .b = 20 }", |
| 4979 | | .errors = &errors, |
| 4932 | .diagnostics = &diagnostics, |
| 4980 | 4933 | }), |
| 4981 | 4934 | ); |
| 4982 | 4935 | try std.testing.expectEqual( |
| ... | ... | @@ -4984,7 +4937,7 @@ test "std.zon variants" { |
| 4984 | 4937 | .arena = arena, |
| 4985 | 4938 | .ast = &ast, |
| 4986 | 4939 | .zoir = &zoir, |
| 4987 | | .errors = &errors, |
| 4940 | .diagnostics = &diagnostics, |
| 4988 | 4941 | }), |
| 4989 | 4942 | end, |
| 4990 | 4943 | ); |
| ... | ... | @@ -4993,7 +4946,7 @@ test "std.zon variants" { |
| 4993 | 4946 | .arena = arena, |
| 4994 | 4947 | .ast = &ast, |
| 4995 | 4948 | .zoir = &zoir, |
| 4996 | | .errors = &errors, |
| 4949 | .diagnostics = &diagnostics, |
| 4997 | 4950 | }), |
| 4998 | 4951 | end, |
| 4999 | 4952 | ); |
| ... | ... | @@ -5001,5 +4954,5 @@ test "std.zon variants" { |
| 5001 | 4954 | } |
| 5002 | 4955 | |
| 5003 | 4956 | test { |
| 5004 | | _ = Errors; |
| 4957 | _ = Diagnostics; |
| 5005 | 4958 | } |