| ... | ... | @@ -44,13 +44,13 @@ pub const Error = union(enum) { |
| 44 | 44 | pub const Iterator = struct { |
| 45 | 45 | index: usize = 0, |
| 46 | 46 | err: Error, |
| 47 | | status: *const Status, |
| 47 | diag: *const Diagnostics, |
| 48 | 48 | |
| 49 | 49 | pub fn next(self: *@This()) ?Note { |
| 50 | 50 | switch (self.err) { |
| 51 | 51 | .zoir => |err| { |
| 52 | 52 | if (self.index >= err.note_count) return null; |
| 53 | | const zoir = self.status.zoir.?; |
| 53 | const zoir = self.diag.zoir.?; |
| 54 | 54 | const note = err.getNotes(zoir)[self.index]; |
| 55 | 55 | self.index += 1; |
| 56 | 56 | return .{ .zoir = note }; |
| ... | ... | @@ -80,15 +80,15 @@ pub const Error = union(enum) { |
| 80 | 80 | try writer.writeAll(self); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | | pub fn fmtMessage(self: Note, status: *const Status) std.fmt.Formatter(Note.formatMessage) { |
| 83 | pub fn fmtMessage(self: Note, diag: *const Diagnostics) std.fmt.Formatter(Note.formatMessage) { |
| 84 | 84 | return .{ .data = switch (self) { |
| 85 | | .zoir => |note| note.msg.get(status.zoir.?), |
| 85 | .zoir => |note| note.msg.get(diag.zoir.?), |
| 86 | 86 | .type_check => |note| note.msg, |
| 87 | 87 | } }; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | | pub fn getLocation(self: Note, status: *const Status) Ast.Location { |
| 91 | | const ast = status.ast.?; |
| 90 | pub fn getLocation(self: Note, diag: *const Diagnostics) Ast.Location { |
| 91 | const ast = diag.ast.?; |
| 92 | 92 | switch (self) { |
| 93 | 93 | .zoir => |note| return zoirErrorLocation(ast, note.token, note.node_or_offset), |
| 94 | 94 | .type_check => |note| return ast.tokenLocation(note.offset, note.token), |
| ... | ... | @@ -98,10 +98,10 @@ pub const Error = union(enum) { |
| 98 | 98 | |
| 99 | 99 | pub const Iterator = struct { |
| 100 | 100 | index: usize = 0, |
| 101 | | status: *const Status, |
| 101 | diag: *const Diagnostics, |
| 102 | 102 | |
| 103 | 103 | pub fn next(self: *@This()) ?Error { |
| 104 | | const zoir = self.status.zoir orelse return null; |
| 104 | const zoir = self.diag.zoir orelse return null; |
| 105 | 105 | |
| 106 | 106 | if (self.index < zoir.compile_errors.len) { |
| 107 | 107 | const result: Error = .{ .zoir = zoir.compile_errors[self.index] }; |
| ... | ... | @@ -109,7 +109,7 @@ pub const Error = union(enum) { |
| 109 | 109 | return result; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | | if (self.status.type_check) |err| { |
| 112 | if (self.diag.type_check) |err| { |
| 113 | 113 | if (self.index == zoir.compile_errors.len) { |
| 114 | 114 | const result: Error = .{ .type_check = err }; |
| 115 | 115 | self.index += 1; |
| ... | ... | @@ -156,7 +156,7 @@ pub const Error = union(enum) { |
| 156 | 156 | |
| 157 | 157 | const FormatMessage = struct { |
| 158 | 158 | err: Error, |
| 159 | | status: *const Status, |
| 159 | diag: *const Diagnostics, |
| 160 | 160 | }; |
| 161 | 161 | |
| 162 | 162 | fn formatMessage( |
| ... | ... | @@ -168,23 +168,23 @@ pub const Error = union(enum) { |
| 168 | 168 | _ = f; |
| 169 | 169 | _ = options; |
| 170 | 170 | switch (self.err) { |
| 171 | | .zoir => |err| try writer.writeAll(err.msg.get(self.status.zoir.?)), |
| 171 | .zoir => |err| try writer.writeAll(err.msg.get(self.diag.zoir.?)), |
| 172 | 172 | .type_check => |tc| try writer.writeAll(tc.message), |
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | | pub fn fmtMessage(self: @This(), status: *const Status) std.fmt.Formatter(formatMessage) { |
| 176 | pub fn fmtMessage(self: @This(), diag: *const Diagnostics) std.fmt.Formatter(formatMessage) { |
| 177 | 177 | return .{ .data = .{ |
| 178 | 178 | .err = self, |
| 179 | | .status = status, |
| 179 | .diag = diag, |
| 180 | 180 | } }; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | | pub fn getLocation(self: @This(), status: *const Status) Ast.Location { |
| 184 | | const ast = status.ast.?; |
| 183 | pub fn getLocation(self: @This(), diag: *const Diagnostics) Ast.Location { |
| 184 | const ast = diag.ast.?; |
| 185 | 185 | return switch (self) { |
| 186 | 186 | .zoir => |err| return zoirErrorLocation( |
| 187 | | status.ast.?, |
| 187 | diag.ast.?, |
| 188 | 188 | err.token, |
| 189 | 189 | err.node_or_offset, |
| 190 | 190 | ), |
| ... | ... | @@ -192,8 +192,8 @@ pub const Error = union(enum) { |
| 192 | 192 | }; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | | pub fn iterateNotes(self: @This(), status: *const Status) Note.Iterator { |
| 196 | | return .{ .err = self, .status = status }; |
| 195 | pub fn iterateNotes(self: @This(), diag: *const Diagnostics) Note.Iterator { |
| 196 | return .{ .err = self, .diag = diag }; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | fn zoirErrorLocation(ast: Ast, maybe_token: Ast.OptionalTokenIndex, node_or_offset: u32) Ast.Location { |
| ... | ... | @@ -210,26 +210,26 @@ pub const Error = union(enum) { |
| 210 | 210 | }; |
| 211 | 211 | |
| 212 | 212 | /// Information about the success or failure of a parse. |
| 213 | | pub const Status = struct { |
| 213 | pub const Diagnostics = struct { |
| 214 | 214 | ast: ?Ast = null, |
| 215 | 215 | zoir: ?Zoir = null, |
| 216 | 216 | type_check: ?Error.TypeCheckFailure = null, |
| 217 | 217 | |
| 218 | | fn assertEmpty(self: Status) void { |
| 218 | fn assertEmpty(self: Diagnostics) void { |
| 219 | 219 | assert(self.ast == null); |
| 220 | 220 | assert(self.zoir == null); |
| 221 | 221 | assert(self.type_check == null); |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | | pub fn deinit(self: *Status, gpa: Allocator) void { |
| 224 | pub fn deinit(self: *Diagnostics, gpa: Allocator) void { |
| 225 | 225 | if (self.ast) |*ast| ast.deinit(gpa); |
| 226 | 226 | if (self.zoir) |*zoir| zoir.deinit(gpa); |
| 227 | 227 | if (self.type_check) |tc| tc.deinit(gpa); |
| 228 | 228 | self.* = undefined; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | | pub fn iterateErrors(self: *const Status) Error.Iterator { |
| 232 | | return .{ .status = self }; |
| 231 | pub fn iterateErrors(self: *const Diagnostics) Error.Iterator { |
| 232 | return .{ .diag = self }; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | pub fn format( |
| ... | ... | @@ -266,7 +266,7 @@ pub const Status = struct { |
| 266 | 266 | /// invalid or can not be deserialized into type `T`. |
| 267 | 267 | /// |
| 268 | 268 | /// When the parser returns `error.ParseZon`, it will also store a human readable explanation in |
| 269 | | /// `status` if non null. If status is not null, it must be initialized to `.{}`. |
| 269 | /// `diag` if non null. If diag is not null, it must be initialized to `.{}`. |
| 270 | 270 | pub fn fromSlice( |
| 271 | 271 | /// The type to deserialize into. May not be or contain any of the following types: |
| 272 | 272 | /// * Any comptime-only type, except in a comptime field |
| ... | ... | @@ -283,22 +283,22 @@ pub fn fromSlice( |
| 283 | 283 | T: type, |
| 284 | 284 | gpa: Allocator, |
| 285 | 285 | source: [:0]const u8, |
| 286 | | status: ?*Status, |
| 286 | diag: ?*Diagnostics, |
| 287 | 287 | options: Options, |
| 288 | 288 | ) error{ OutOfMemory, ParseZon }!T { |
| 289 | | if (status) |s| s.assertEmpty(); |
| 289 | if (diag) |s| s.assertEmpty(); |
| 290 | 290 | |
| 291 | 291 | var ast = try std.zig.Ast.parse(gpa, source, .zon); |
| 292 | | defer if (status == null) ast.deinit(gpa); |
| 293 | | if (status) |s| s.ast = ast; |
| 292 | defer if (diag == null) ast.deinit(gpa); |
| 293 | if (diag) |s| s.ast = ast; |
| 294 | 294 | |
| 295 | | // If there's no status, Zoir exists for the lifetime of this function. If there is a status, |
| 296 | | // ownership is transferred to status. |
| 295 | // If there's no diagnostics, Zoir exists for the lifetime of this function. If there is a |
| 296 | // diagnostics, ownership is transferred to diagnostics. |
| 297 | 297 | var zoir = try ZonGen.generate(gpa, ast, .{ .parse_str_lits = false }); |
| 298 | | defer if (status == null) zoir.deinit(gpa); |
| 298 | defer if (diag == null) zoir.deinit(gpa); |
| 299 | 299 | |
| 300 | | if (status) |s| s.* = .{}; |
| 301 | | return fromZoir(T, gpa, ast, zoir, status, options); |
| 300 | if (diag) |s| s.* = .{}; |
| 301 | return fromZoir(T, gpa, ast, zoir, diag, options); |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /// Like `fromSlice`, but operates on `Zoir` instead of ZON source. |
| ... | ... | @@ -307,10 +307,10 @@ pub fn fromZoir( |
| 307 | 307 | gpa: Allocator, |
| 308 | 308 | ast: Ast, |
| 309 | 309 | zoir: Zoir, |
| 310 | | status: ?*Status, |
| 310 | diag: ?*Diagnostics, |
| 311 | 311 | options: Options, |
| 312 | 312 | ) error{ OutOfMemory, ParseZon }!T { |
| 313 | | return fromZoirNode(T, gpa, ast, zoir, .root, status, options); |
| 313 | return fromZoirNode(T, gpa, ast, zoir, .root, diag, options); |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /// Like `fromZoir`, but the parse starts on `node` instead of root. |
| ... | ... | @@ -320,12 +320,12 @@ pub fn fromZoirNode( |
| 320 | 320 | ast: Ast, |
| 321 | 321 | zoir: Zoir, |
| 322 | 322 | node: Zoir.Node.Index, |
| 323 | | status: ?*Status, |
| 323 | diag: ?*Diagnostics, |
| 324 | 324 | options: Options, |
| 325 | 325 | ) error{ OutOfMemory, ParseZon }!T { |
| 326 | 326 | comptime assert(canParseType(T)); |
| 327 | 327 | |
| 328 | | if (status) |s| { |
| 328 | if (diag) |s| { |
| 329 | 329 | s.assertEmpty(); |
| 330 | 330 | s.ast = ast; |
| 331 | 331 | s.zoir = zoir; |
| ... | ... | @@ -340,7 +340,7 @@ pub fn fromZoirNode( |
| 340 | 340 | .ast = ast, |
| 341 | 341 | .zoir = zoir, |
| 342 | 342 | .options = options, |
| 343 | | .status = status, |
| 343 | .diag = diag, |
| 344 | 344 | }; |
| 345 | 345 | |
| 346 | 346 | return parser.parseExpr(T, node); |
| ... | ... | @@ -421,7 +421,7 @@ const Parser = struct { |
| 421 | 421 | gpa: Allocator, |
| 422 | 422 | ast: Ast, |
| 423 | 423 | zoir: Zoir, |
| 424 | | status: ?*Status, |
| 424 | diag: ?*Diagnostics, |
| 425 | 425 | options: Options, |
| 426 | 426 | |
| 427 | 427 | fn parseExpr(self: *@This(), T: type, node: Zoir.Node.Index) error{ ParseZon, OutOfMemory }!T { |
| ... | ... | @@ -988,7 +988,7 @@ const Parser = struct { |
| 988 | 988 | ) error{ OutOfMemory, ParseZon } { |
| 989 | 989 | @branchHint(.cold); |
| 990 | 990 | comptime assert(args.len > 0); |
| 991 | | if (self.status) |s| s.type_check = .{ |
| 991 | if (self.diag) |s| s.type_check = .{ |
| 992 | 992 | .token = token, |
| 993 | 993 | .offset = offset, |
| 994 | 994 | .message = std.fmt.allocPrint(self.gpa, fmt, args) catch |err| { |
| ... | ... | @@ -1017,7 +1017,7 @@ const Parser = struct { |
| 1017 | 1017 | failure: Error.TypeCheckFailure, |
| 1018 | 1018 | ) error{ParseZon} { |
| 1019 | 1019 | @branchHint(.cold); |
| 1020 | | if (self.status) |s| s.type_check = failure; |
| 1020 | if (self.diag) |s| s.type_check = failure; |
| 1021 | 1021 | return error.ParseZon; |
| 1022 | 1022 | } |
| 1023 | 1023 | |
| ... | ... | @@ -1283,13 +1283,13 @@ test "std.zon requiresAllocator" { |
| 1283 | 1283 | |
| 1284 | 1284 | test "std.zon ast errors" { |
| 1285 | 1285 | const gpa = std.testing.allocator; |
| 1286 | | var status: Status = .{}; |
| 1287 | | defer status.deinit(gpa); |
| 1286 | var diag: Diagnostics = .{}; |
| 1287 | defer diag.deinit(gpa); |
| 1288 | 1288 | try std.testing.expectError( |
| 1289 | 1289 | error.ParseZon, |
| 1290 | | fromSlice(struct {}, gpa, ".{.x = 1 .y = 2}", &status, .{}), |
| 1290 | fromSlice(struct {}, gpa, ".{.x = 1 .y = 2}", &diag, .{}), |
| 1291 | 1291 | ); |
| 1292 | | try std.testing.expectFmt("1:13: error: expected ',' after initializer\n", "{}", .{status}); |
| 1292 | try std.testing.expectFmt("1:13: error: expected ',' after initializer\n", "{}", .{diag}); |
| 1293 | 1293 | } |
| 1294 | 1294 | |
| 1295 | 1295 | test "std.zon comments" { |
| ... | ... | @@ -1302,17 +1302,17 @@ test "std.zon comments" { |
| 1302 | 1302 | , null, .{})); |
| 1303 | 1303 | |
| 1304 | 1304 | { |
| 1305 | | var status: Status = .{}; |
| 1306 | | defer status.deinit(gpa); |
| 1305 | var diag: Diagnostics = .{}; |
| 1306 | defer diag.deinit(gpa); |
| 1307 | 1307 | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, |
| 1308 | 1308 | \\//! comment |
| 1309 | 1309 | \\10 // comment |
| 1310 | 1310 | \\// comment |
| 1311 | | , &status, .{})); |
| 1311 | , &diag, .{})); |
| 1312 | 1312 | try std.testing.expectFmt( |
| 1313 | 1313 | "1:1: error: expected expression, found 'a document comment'\n", |
| 1314 | 1314 | "{}", |
| 1315 | | .{status}, |
| 1315 | .{diag}, |
| 1316 | 1316 | ); |
| 1317 | 1317 | } |
| 1318 | 1318 | } |
| ... | ... | @@ -1323,16 +1323,16 @@ test "std.zon failure/oom formatting" { |
| 1323 | 1323 | .fail_index = 0, |
| 1324 | 1324 | .resize_fail_index = 0, |
| 1325 | 1325 | }); |
| 1326 | | var status: Status = .{}; |
| 1327 | | defer status.deinit(gpa); |
| 1326 | var diag: Diagnostics = .{}; |
| 1327 | defer diag.deinit(gpa); |
| 1328 | 1328 | try std.testing.expectError(error.OutOfMemory, fromSlice( |
| 1329 | 1329 | []const u8, |
| 1330 | 1330 | failing_allocator.allocator(), |
| 1331 | 1331 | "\"foo\"", |
| 1332 | | &status, |
| 1332 | &diag, |
| 1333 | 1333 | .{}, |
| 1334 | 1334 | )); |
| 1335 | | try std.testing.expectFmt("", "{}", .{status}); |
| 1335 | try std.testing.expectFmt("", "{}", .{diag}); |
| 1336 | 1336 | } |
| 1337 | 1337 | |
| 1338 | 1338 | test "std.zon fromSlice syntax error" { |
| ... | ... | @@ -1401,11 +1401,11 @@ test "std.zon unions" { |
| 1401 | 1401 | // Unknown field |
| 1402 | 1402 | { |
| 1403 | 1403 | const Union = union { x: f32, y: f32 }; |
| 1404 | | var status: Status = .{}; |
| 1405 | | defer status.deinit(gpa); |
| 1404 | var diag: Diagnostics = .{}; |
| 1405 | defer diag.deinit(gpa); |
| 1406 | 1406 | try std.testing.expectError( |
| 1407 | 1407 | error.ParseZon, |
| 1408 | | fromSlice(Union, gpa, ".{.z=2.5}", &status, .{}), |
| 1408 | fromSlice(Union, gpa, ".{.z=2.5}", &diag, .{}), |
| 1409 | 1409 | ); |
| 1410 | 1410 | try std.testing.expectFmt( |
| 1411 | 1411 | \\1:4: error: unexpected field 'z' |
| ... | ... | @@ -1413,78 +1413,78 @@ test "std.zon unions" { |
| 1413 | 1413 | \\ |
| 1414 | 1414 | , |
| 1415 | 1415 | "{}", |
| 1416 | | .{status}, |
| 1416 | .{diag}, |
| 1417 | 1417 | ); |
| 1418 | 1418 | } |
| 1419 | 1419 | |
| 1420 | 1420 | // Explicit void field |
| 1421 | 1421 | { |
| 1422 | 1422 | const Union = union(enum) { x: void }; |
| 1423 | | var status: Status = .{}; |
| 1424 | | defer status.deinit(gpa); |
| 1423 | var diag: Diagnostics = .{}; |
| 1424 | defer diag.deinit(gpa); |
| 1425 | 1425 | try std.testing.expectError( |
| 1426 | 1426 | error.ParseZon, |
| 1427 | | fromSlice(Union, gpa, ".{.x=1}", &status, .{}), |
| 1427 | fromSlice(Union, gpa, ".{.x=1}", &diag, .{}), |
| 1428 | 1428 | ); |
| 1429 | | try std.testing.expectFmt("1:6: error: expected type 'void'\n", "{}", .{status}); |
| 1429 | try std.testing.expectFmt("1:6: error: expected type 'void'\n", "{}", .{diag}); |
| 1430 | 1430 | } |
| 1431 | 1431 | |
| 1432 | 1432 | // Extra field |
| 1433 | 1433 | { |
| 1434 | 1434 | const Union = union { x: f32, y: bool }; |
| 1435 | | var status: Status = .{}; |
| 1436 | | defer status.deinit(gpa); |
| 1435 | var diag: Diagnostics = .{}; |
| 1436 | defer diag.deinit(gpa); |
| 1437 | 1437 | try std.testing.expectError( |
| 1438 | 1438 | error.ParseZon, |
| 1439 | | fromSlice(Union, gpa, ".{.x = 1.5, .y = true}", &status, .{}), |
| 1439 | fromSlice(Union, gpa, ".{.x = 1.5, .y = true}", &diag, .{}), |
| 1440 | 1440 | ); |
| 1441 | | try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{status}); |
| 1441 | try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{diag}); |
| 1442 | 1442 | } |
| 1443 | 1443 | |
| 1444 | 1444 | // No fields |
| 1445 | 1445 | { |
| 1446 | 1446 | const Union = union { x: f32, y: bool }; |
| 1447 | | var status: Status = .{}; |
| 1448 | | defer status.deinit(gpa); |
| 1447 | var diag: Diagnostics = .{}; |
| 1448 | defer diag.deinit(gpa); |
| 1449 | 1449 | try std.testing.expectError( |
| 1450 | 1450 | error.ParseZon, |
| 1451 | | fromSlice(Union, gpa, ".{}", &status, .{}), |
| 1451 | fromSlice(Union, gpa, ".{}", &diag, .{}), |
| 1452 | 1452 | ); |
| 1453 | | try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{status}); |
| 1453 | try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{diag}); |
| 1454 | 1454 | } |
| 1455 | 1455 | |
| 1456 | 1456 | // Enum literals cannot coerce into untagged unions |
| 1457 | 1457 | { |
| 1458 | 1458 | const Union = union { x: void }; |
| 1459 | | var status: Status = .{}; |
| 1460 | | defer status.deinit(gpa); |
| 1461 | | try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".x", &status, .{})); |
| 1462 | | try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{status}); |
| 1459 | var diag: Diagnostics = .{}; |
| 1460 | defer diag.deinit(gpa); |
| 1461 | try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".x", &diag, .{})); |
| 1462 | try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{diag}); |
| 1463 | 1463 | } |
| 1464 | 1464 | |
| 1465 | 1465 | // Unknown field for enum literal coercion |
| 1466 | 1466 | { |
| 1467 | 1467 | const Union = union(enum) { x: void }; |
| 1468 | | var status: Status = .{}; |
| 1469 | | defer status.deinit(gpa); |
| 1470 | | try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".y", &status, .{})); |
| 1468 | var diag: Diagnostics = .{}; |
| 1469 | defer diag.deinit(gpa); |
| 1470 | try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".y", &diag, .{})); |
| 1471 | 1471 | try std.testing.expectFmt( |
| 1472 | 1472 | \\1:2: error: unexpected field 'y' |
| 1473 | 1473 | \\1:2: note: supported: 'x' |
| 1474 | 1474 | \\ |
| 1475 | 1475 | , |
| 1476 | 1476 | "{}", |
| 1477 | | .{status}, |
| 1477 | .{diag}, |
| 1478 | 1478 | ); |
| 1479 | 1479 | } |
| 1480 | 1480 | |
| 1481 | 1481 | // Non void field for enum literal coercion |
| 1482 | 1482 | { |
| 1483 | 1483 | const Union = union(enum) { x: f32 }; |
| 1484 | | var status: Status = .{}; |
| 1485 | | defer status.deinit(gpa); |
| 1486 | | try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".x", &status, .{})); |
| 1487 | | try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{status}); |
| 1484 | var diag: Diagnostics = .{}; |
| 1485 | defer diag.deinit(gpa); |
| 1486 | try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".x", &diag, .{})); |
| 1487 | try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{diag}); |
| 1488 | 1488 | } |
| 1489 | 1489 | } |
| 1490 | 1490 | |
| ... | ... | @@ -1529,11 +1529,11 @@ test "std.zon structs" { |
| 1529 | 1529 | // Unknown field |
| 1530 | 1530 | { |
| 1531 | 1531 | const Vec2 = struct { x: f32, y: f32 }; |
| 1532 | | var status: Status = .{}; |
| 1533 | | defer status.deinit(gpa); |
| 1532 | var diag: Diagnostics = .{}; |
| 1533 | defer diag.deinit(gpa); |
| 1534 | 1534 | try std.testing.expectError( |
| 1535 | 1535 | error.ParseZon, |
| 1536 | | fromSlice(Vec2, gpa, ".{.x=1.5, .z=2.5}", &status, .{}), |
| 1536 | fromSlice(Vec2, gpa, ".{.x=1.5, .z=2.5}", &diag, .{}), |
| 1537 | 1537 | ); |
| 1538 | 1538 | try std.testing.expectFmt( |
| 1539 | 1539 | \\1:12: error: unexpected field 'z' |
| ... | ... | @@ -1541,24 +1541,24 @@ test "std.zon structs" { |
| 1541 | 1541 | \\ |
| 1542 | 1542 | , |
| 1543 | 1543 | "{}", |
| 1544 | | .{status}, |
| 1544 | .{diag}, |
| 1545 | 1545 | ); |
| 1546 | 1546 | } |
| 1547 | 1547 | |
| 1548 | 1548 | // Duplicate field |
| 1549 | 1549 | { |
| 1550 | 1550 | const Vec2 = struct { x: f32, y: f32 }; |
| 1551 | | var status: Status = .{}; |
| 1552 | | defer status.deinit(gpa); |
| 1551 | var diag: Diagnostics = .{}; |
| 1552 | defer diag.deinit(gpa); |
| 1553 | 1553 | try std.testing.expectError( |
| 1554 | 1554 | error.ParseZon, |
| 1555 | | fromSlice(Vec2, gpa, ".{.x=1.5, .x=2.5, .x=3.5}", &status, .{}), |
| 1555 | fromSlice(Vec2, gpa, ".{.x=1.5, .x=2.5, .x=3.5}", &diag, .{}), |
| 1556 | 1556 | ); |
| 1557 | 1557 | try std.testing.expectFmt( |
| 1558 | 1558 | \\1:4: error: duplicate struct field name |
| 1559 | 1559 | \\1:12: note: duplicate name here |
| 1560 | 1560 | \\ |
| 1561 | | , "{}", .{status}); |
| 1561 | , "{}", .{diag}); |
| 1562 | 1562 | } |
| 1563 | 1563 | |
| 1564 | 1564 | // Ignore unknown fields |
| ... | ... | @@ -1573,29 +1573,29 @@ test "std.zon structs" { |
| 1573 | 1573 | // Unknown field when struct has no fields (regression test) |
| 1574 | 1574 | { |
| 1575 | 1575 | const Vec2 = struct {}; |
| 1576 | | var status: Status = .{}; |
| 1577 | | defer status.deinit(gpa); |
| 1576 | var diag: Diagnostics = .{}; |
| 1577 | defer diag.deinit(gpa); |
| 1578 | 1578 | try std.testing.expectError( |
| 1579 | 1579 | error.ParseZon, |
| 1580 | | fromSlice(Vec2, gpa, ".{.x=1.5, .z=2.5}", &status, .{}), |
| 1580 | fromSlice(Vec2, gpa, ".{.x=1.5, .z=2.5}", &diag, .{}), |
| 1581 | 1581 | ); |
| 1582 | 1582 | try std.testing.expectFmt( |
| 1583 | 1583 | \\1:4: error: unexpected field 'x' |
| 1584 | 1584 | \\1:4: note: none expected |
| 1585 | 1585 | \\ |
| 1586 | | , "{}", .{status}); |
| 1586 | , "{}", .{diag}); |
| 1587 | 1587 | } |
| 1588 | 1588 | |
| 1589 | 1589 | // Missing field |
| 1590 | 1590 | { |
| 1591 | 1591 | const Vec2 = struct { x: f32, y: f32 }; |
| 1592 | | var status: Status = .{}; |
| 1593 | | defer status.deinit(gpa); |
| 1592 | var diag: Diagnostics = .{}; |
| 1593 | defer diag.deinit(gpa); |
| 1594 | 1594 | try std.testing.expectError( |
| 1595 | 1595 | error.ParseZon, |
| 1596 | | fromSlice(Vec2, gpa, ".{.x=1.5}", &status, .{}), |
| 1596 | fromSlice(Vec2, gpa, ".{.x=1.5}", &diag, .{}), |
| 1597 | 1597 | ); |
| 1598 | | try std.testing.expectFmt("1:2: error: missing required field y\n", "{}", .{status}); |
| 1598 | try std.testing.expectFmt("1:2: error: missing required field y\n", "{}", .{diag}); |
| 1599 | 1599 | } |
| 1600 | 1600 | |
| 1601 | 1601 | // Default field |
| ... | ... | @@ -1615,14 +1615,14 @@ test "std.zon structs" { |
| 1615 | 1615 | // Comptime field assignment |
| 1616 | 1616 | { |
| 1617 | 1617 | const Vec2 = struct { x: f32, comptime y: f32 = 1.5 }; |
| 1618 | | var status: Status = .{}; |
| 1619 | | defer status.deinit(gpa); |
| 1620 | | const parsed = fromSlice(Vec2, gpa, ".{.x = 1.2, .y = 1.5}", &status, .{}); |
| 1618 | var diag: Diagnostics = .{}; |
| 1619 | defer diag.deinit(gpa); |
| 1620 | const parsed = fromSlice(Vec2, gpa, ".{.x = 1.2, .y = 1.5}", &diag, .{}); |
| 1621 | 1621 | try std.testing.expectError(error.ParseZon, parsed); |
| 1622 | 1622 | try std.testing.expectFmt( |
| 1623 | 1623 | \\1:18: error: cannot initialize comptime field |
| 1624 | 1624 | \\ |
| 1625 | | , "{}", .{status}); |
| 1625 | , "{}", .{diag}); |
| 1626 | 1626 | } |
| 1627 | 1627 | |
| 1628 | 1628 | // Enum field (regression test, we were previously getting the field name in an |
| ... | ... | @@ -1644,52 +1644,52 @@ test "std.zon structs" { |
| 1644 | 1644 | { |
| 1645 | 1645 | // Structs |
| 1646 | 1646 | { |
| 1647 | | var status: Status = .{}; |
| 1648 | | defer status.deinit(gpa); |
| 1649 | | const parsed = fromSlice(struct {}, gpa, "Empty{}", &status, .{}); |
| 1647 | var diag: Diagnostics = .{}; |
| 1648 | defer diag.deinit(gpa); |
| 1649 | const parsed = fromSlice(struct {}, gpa, "Empty{}", &diag, .{}); |
| 1650 | 1650 | try std.testing.expectError(error.ParseZon, parsed); |
| 1651 | 1651 | try std.testing.expectFmt( |
| 1652 | 1652 | \\1:1: error: types are not available in ZON |
| 1653 | 1653 | \\1:1: note: replace the type with '.' |
| 1654 | 1654 | \\ |
| 1655 | | , "{}", .{status}); |
| 1655 | , "{}", .{diag}); |
| 1656 | 1656 | } |
| 1657 | 1657 | |
| 1658 | 1658 | // Arrays |
| 1659 | 1659 | { |
| 1660 | | var status: Status = .{}; |
| 1661 | | defer status.deinit(gpa); |
| 1662 | | const parsed = fromSlice([3]u8, gpa, "[3]u8{1, 2, 3}", &status, .{}); |
| 1660 | var diag: Diagnostics = .{}; |
| 1661 | defer diag.deinit(gpa); |
| 1662 | const parsed = fromSlice([3]u8, gpa, "[3]u8{1, 2, 3}", &diag, .{}); |
| 1663 | 1663 | try std.testing.expectError(error.ParseZon, parsed); |
| 1664 | 1664 | try std.testing.expectFmt( |
| 1665 | 1665 | \\1:1: error: types are not available in ZON |
| 1666 | 1666 | \\1:1: note: replace the type with '.' |
| 1667 | 1667 | \\ |
| 1668 | | , "{}", .{status}); |
| 1668 | , "{}", .{diag}); |
| 1669 | 1669 | } |
| 1670 | 1670 | |
| 1671 | 1671 | // Slices |
| 1672 | 1672 | { |
| 1673 | | var status: Status = .{}; |
| 1674 | | defer status.deinit(gpa); |
| 1675 | | const parsed = fromSlice([]u8, gpa, "[]u8{1, 2, 3}", &status, .{}); |
| 1673 | var diag: Diagnostics = .{}; |
| 1674 | defer diag.deinit(gpa); |
| 1675 | const parsed = fromSlice([]u8, gpa, "[]u8{1, 2, 3}", &diag, .{}); |
| 1676 | 1676 | try std.testing.expectError(error.ParseZon, parsed); |
| 1677 | 1677 | try std.testing.expectFmt( |
| 1678 | 1678 | \\1:1: error: types are not available in ZON |
| 1679 | 1679 | \\1:1: note: replace the type with '.' |
| 1680 | 1680 | \\ |
| 1681 | | , "{}", .{status}); |
| 1681 | , "{}", .{diag}); |
| 1682 | 1682 | } |
| 1683 | 1683 | |
| 1684 | 1684 | // Tuples |
| 1685 | 1685 | { |
| 1686 | | var status: Status = .{}; |
| 1687 | | defer status.deinit(gpa); |
| 1686 | var diag: Diagnostics = .{}; |
| 1687 | defer diag.deinit(gpa); |
| 1688 | 1688 | const parsed = fromSlice( |
| 1689 | 1689 | struct { u8, u8, u8 }, |
| 1690 | 1690 | gpa, |
| 1691 | 1691 | "Tuple{1, 2, 3}", |
| 1692 | | &status, |
| 1692 | &diag, |
| 1693 | 1693 | .{}, |
| 1694 | 1694 | ); |
| 1695 | 1695 | try std.testing.expectError(error.ParseZon, parsed); |
| ... | ... | @@ -1697,20 +1697,20 @@ test "std.zon structs" { |
| 1697 | 1697 | \\1:1: error: types are not available in ZON |
| 1698 | 1698 | \\1:1: note: replace the type with '.' |
| 1699 | 1699 | \\ |
| 1700 | | , "{}", .{status}); |
| 1700 | , "{}", .{diag}); |
| 1701 | 1701 | } |
| 1702 | 1702 | |
| 1703 | 1703 | // Nested |
| 1704 | 1704 | { |
| 1705 | | var status: Status = .{}; |
| 1706 | | defer status.deinit(gpa); |
| 1707 | | const parsed = fromSlice(struct {}, gpa, ".{ .x = Tuple{1, 2, 3} }", &status, .{}); |
| 1705 | var diag: Diagnostics = .{}; |
| 1706 | defer diag.deinit(gpa); |
| 1707 | const parsed = fromSlice(struct {}, gpa, ".{ .x = Tuple{1, 2, 3} }", &diag, .{}); |
| 1708 | 1708 | try std.testing.expectError(error.ParseZon, parsed); |
| 1709 | 1709 | try std.testing.expectFmt( |
| 1710 | 1710 | \\1:9: error: types are not available in ZON |
| 1711 | 1711 | \\1:9: note: replace the type with '.' |
| 1712 | 1712 | \\ |
| 1713 | | , "{}", .{status}); |
| 1713 | , "{}", .{diag}); |
| 1714 | 1714 | } |
| 1715 | 1715 | } |
| 1716 | 1716 | } |
| ... | ... | @@ -1749,53 +1749,53 @@ test "std.zon tuples" { |
| 1749 | 1749 | // Extra field |
| 1750 | 1750 | { |
| 1751 | 1751 | const Tuple = struct { f32, bool }; |
| 1752 | | var status: Status = .{}; |
| 1753 | | defer status.deinit(gpa); |
| 1752 | var diag: Diagnostics = .{}; |
| 1753 | defer diag.deinit(gpa); |
| 1754 | 1754 | try std.testing.expectError( |
| 1755 | 1755 | error.ParseZon, |
| 1756 | | fromSlice(Tuple, gpa, ".{0.5, true, 123}", &status, .{}), |
| 1756 | fromSlice(Tuple, gpa, ".{0.5, true, 123}", &diag, .{}), |
| 1757 | 1757 | ); |
| 1758 | | try std.testing.expectFmt("1:14: error: index 2 outside of tuple length 2\n", "{}", .{status}); |
| 1758 | try std.testing.expectFmt("1:14: error: index 2 outside of tuple length 2\n", "{}", .{diag}); |
| 1759 | 1759 | } |
| 1760 | 1760 | |
| 1761 | 1761 | // Extra field |
| 1762 | 1762 | { |
| 1763 | 1763 | const Tuple = struct { f32, bool }; |
| 1764 | | var status: Status = .{}; |
| 1765 | | defer status.deinit(gpa); |
| 1764 | var diag: Diagnostics = .{}; |
| 1765 | defer diag.deinit(gpa); |
| 1766 | 1766 | try std.testing.expectError( |
| 1767 | 1767 | error.ParseZon, |
| 1768 | | fromSlice(Tuple, gpa, ".{0.5}", &status, .{}), |
| 1768 | fromSlice(Tuple, gpa, ".{0.5}", &diag, .{}), |
| 1769 | 1769 | ); |
| 1770 | 1770 | try std.testing.expectFmt( |
| 1771 | 1771 | "1:2: error: missing tuple field with index 1\n", |
| 1772 | 1772 | "{}", |
| 1773 | | .{status}, |
| 1773 | .{diag}, |
| 1774 | 1774 | ); |
| 1775 | 1775 | } |
| 1776 | 1776 | |
| 1777 | 1777 | // Tuple with unexpected field names |
| 1778 | 1778 | { |
| 1779 | 1779 | const Tuple = struct { f32 }; |
| 1780 | | var status: Status = .{}; |
| 1781 | | defer status.deinit(gpa); |
| 1780 | var diag: Diagnostics = .{}; |
| 1781 | defer diag.deinit(gpa); |
| 1782 | 1782 | try std.testing.expectError( |
| 1783 | 1783 | error.ParseZon, |
| 1784 | | fromSlice(Tuple, gpa, ".{.foo = 10.0}", &status, .{}), |
| 1784 | fromSlice(Tuple, gpa, ".{.foo = 10.0}", &diag, .{}), |
| 1785 | 1785 | ); |
| 1786 | | try std.testing.expectFmt("1:2: error: expected tuple\n", "{}", .{status}); |
| 1786 | try std.testing.expectFmt("1:2: error: expected tuple\n", "{}", .{diag}); |
| 1787 | 1787 | } |
| 1788 | 1788 | |
| 1789 | 1789 | // Struct with missing field names |
| 1790 | 1790 | { |
| 1791 | 1791 | const Struct = struct { foo: f32 }; |
| 1792 | | var status: Status = .{}; |
| 1793 | | defer status.deinit(gpa); |
| 1792 | var diag: Diagnostics = .{}; |
| 1793 | defer diag.deinit(gpa); |
| 1794 | 1794 | try std.testing.expectError( |
| 1795 | 1795 | error.ParseZon, |
| 1796 | | fromSlice(Struct, gpa, ".{10.0}", &status, .{}), |
| 1796 | fromSlice(Struct, gpa, ".{10.0}", &diag, .{}), |
| 1797 | 1797 | ); |
| 1798 | | try std.testing.expectFmt("1:2: error: expected struct\n", "{}", .{status}); |
| 1798 | try std.testing.expectFmt("1:2: error: expected struct\n", "{}", .{diag}); |
| 1799 | 1799 | } |
| 1800 | 1800 | |
| 1801 | 1801 | // Comptime field |
| ... | ... | @@ -1808,14 +1808,14 @@ test "std.zon tuples" { |
| 1808 | 1808 | // Comptime field assignment |
| 1809 | 1809 | { |
| 1810 | 1810 | const Vec2 = struct { f32, comptime f32 = 1.5 }; |
| 1811 | | var status: Status = .{}; |
| 1812 | | defer status.deinit(gpa); |
| 1813 | | const parsed = fromSlice(Vec2, gpa, ".{ 1.2, 1.5}", &status, .{}); |
| 1811 | var diag: Diagnostics = .{}; |
| 1812 | defer diag.deinit(gpa); |
| 1813 | const parsed = fromSlice(Vec2, gpa, ".{ 1.2, 1.5}", &diag, .{}); |
| 1814 | 1814 | try std.testing.expectError(error.ParseZon, parsed); |
| 1815 | 1815 | try std.testing.expectFmt( |
| 1816 | 1816 | \\1:9: error: cannot initialize comptime field |
| 1817 | 1817 | \\ |
| 1818 | | , "{}", .{status}); |
| 1818 | , "{}", .{diag}); |
| 1819 | 1819 | } |
| 1820 | 1820 | } |
| 1821 | 1821 | |
| ... | ... | @@ -1919,61 +1919,61 @@ test "std.zon arrays and slices" { |
| 1919 | 1919 | |
| 1920 | 1920 | // Expect 0 find 3 |
| 1921 | 1921 | { |
| 1922 | | var status: Status = .{}; |
| 1923 | | defer status.deinit(gpa); |
| 1922 | var diag: Diagnostics = .{}; |
| 1923 | defer diag.deinit(gpa); |
| 1924 | 1924 | try std.testing.expectError( |
| 1925 | 1925 | error.ParseZon, |
| 1926 | | fromSlice([0]u8, gpa, ".{'a', 'b', 'c'}", &status, .{}), |
| 1926 | fromSlice([0]u8, gpa, ".{'a', 'b', 'c'}", &diag, .{}), |
| 1927 | 1927 | ); |
| 1928 | 1928 | try std.testing.expectFmt( |
| 1929 | 1929 | "1:3: error: index 0 outside of array of length 0\n", |
| 1930 | 1930 | "{}", |
| 1931 | | .{status}, |
| 1931 | .{diag}, |
| 1932 | 1932 | ); |
| 1933 | 1933 | } |
| 1934 | 1934 | |
| 1935 | 1935 | // Expect 1 find 2 |
| 1936 | 1936 | { |
| 1937 | | var status: Status = .{}; |
| 1938 | | defer status.deinit(gpa); |
| 1937 | var diag: Diagnostics = .{}; |
| 1938 | defer diag.deinit(gpa); |
| 1939 | 1939 | try std.testing.expectError( |
| 1940 | 1940 | error.ParseZon, |
| 1941 | | fromSlice([1]u8, gpa, ".{'a', 'b'}", &status, .{}), |
| 1941 | fromSlice([1]u8, gpa, ".{'a', 'b'}", &diag, .{}), |
| 1942 | 1942 | ); |
| 1943 | 1943 | try std.testing.expectFmt( |
| 1944 | 1944 | "1:8: error: index 1 outside of array of length 1\n", |
| 1945 | 1945 | "{}", |
| 1946 | | .{status}, |
| 1946 | .{diag}, |
| 1947 | 1947 | ); |
| 1948 | 1948 | } |
| 1949 | 1949 | |
| 1950 | 1950 | // Expect 2 find 1 |
| 1951 | 1951 | { |
| 1952 | | var status: Status = .{}; |
| 1953 | | defer status.deinit(gpa); |
| 1952 | var diag: Diagnostics = .{}; |
| 1953 | defer diag.deinit(gpa); |
| 1954 | 1954 | try std.testing.expectError( |
| 1955 | 1955 | error.ParseZon, |
| 1956 | | fromSlice([2]u8, gpa, ".{'a'}", &status, .{}), |
| 1956 | fromSlice([2]u8, gpa, ".{'a'}", &diag, .{}), |
| 1957 | 1957 | ); |
| 1958 | 1958 | try std.testing.expectFmt( |
| 1959 | 1959 | "1:2: error: expected 2 array elements; found 1\n", |
| 1960 | 1960 | "{}", |
| 1961 | | .{status}, |
| 1961 | .{diag}, |
| 1962 | 1962 | ); |
| 1963 | 1963 | } |
| 1964 | 1964 | |
| 1965 | 1965 | // Expect 3 find 0 |
| 1966 | 1966 | { |
| 1967 | | var status: Status = .{}; |
| 1968 | | defer status.deinit(gpa); |
| 1967 | var diag: Diagnostics = .{}; |
| 1968 | defer diag.deinit(gpa); |
| 1969 | 1969 | try std.testing.expectError( |
| 1970 | 1970 | error.ParseZon, |
| 1971 | | fromSlice([3]u8, gpa, ".{}", &status, .{}), |
| 1971 | fromSlice([3]u8, gpa, ".{}", &diag, .{}), |
| 1972 | 1972 | ); |
| 1973 | 1973 | try std.testing.expectFmt( |
| 1974 | 1974 | "1:2: error: expected 3 array elements; found 0\n", |
| 1975 | 1975 | "{}", |
| 1976 | | .{status}, |
| 1976 | .{diag}, |
| 1977 | 1977 | ); |
| 1978 | 1978 | } |
| 1979 | 1979 | |
| ... | ... | @@ -1981,24 +1981,24 @@ test "std.zon arrays and slices" { |
| 1981 | 1981 | { |
| 1982 | 1982 | // Array |
| 1983 | 1983 | { |
| 1984 | | var status: Status = .{}; |
| 1985 | | defer status.deinit(gpa); |
| 1984 | var diag: Diagnostics = .{}; |
| 1985 | defer diag.deinit(gpa); |
| 1986 | 1986 | try std.testing.expectError( |
| 1987 | 1987 | error.ParseZon, |
| 1988 | | fromSlice([3]bool, gpa, ".{'a', 'b', 'c'}", &status, .{}), |
| 1988 | fromSlice([3]bool, gpa, ".{'a', 'b', 'c'}", &diag, .{}), |
| 1989 | 1989 | ); |
| 1990 | | try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{}", .{status}); |
| 1990 | try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{}", .{diag}); |
| 1991 | 1991 | } |
| 1992 | 1992 | |
| 1993 | 1993 | // Slice |
| 1994 | 1994 | { |
| 1995 | | var status: Status = .{}; |
| 1996 | | defer status.deinit(gpa); |
| 1995 | var diag: Diagnostics = .{}; |
| 1996 | defer diag.deinit(gpa); |
| 1997 | 1997 | try std.testing.expectError( |
| 1998 | 1998 | error.ParseZon, |
| 1999 | | fromSlice([]bool, gpa, ".{'a', 'b', 'c'}", &status, .{}), |
| 1999 | fromSlice([]bool, gpa, ".{'a', 'b', 'c'}", &diag, .{}), |
| 2000 | 2000 | ); |
| 2001 | | try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{}", .{status}); |
| 2001 | try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{}", .{diag}); |
| 2002 | 2002 | } |
| 2003 | 2003 | } |
| 2004 | 2004 | |
| ... | ... | @@ -2006,39 +2006,39 @@ test "std.zon arrays and slices" { |
| 2006 | 2006 | { |
| 2007 | 2007 | // Array |
| 2008 | 2008 | { |
| 2009 | | var status: Status = .{}; |
| 2010 | | defer status.deinit(gpa); |
| 2009 | var diag: Diagnostics = .{}; |
| 2010 | defer diag.deinit(gpa); |
| 2011 | 2011 | try std.testing.expectError( |
| 2012 | 2012 | error.ParseZon, |
| 2013 | | fromSlice([3]u8, gpa, "'a'", &status, .{}), |
| 2013 | fromSlice([3]u8, gpa, "'a'", &diag, .{}), |
| 2014 | 2014 | ); |
| 2015 | | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status}); |
| 2015 | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag}); |
| 2016 | 2016 | } |
| 2017 | 2017 | |
| 2018 | 2018 | // Slice |
| 2019 | 2019 | { |
| 2020 | | var status: Status = .{}; |
| 2021 | | defer status.deinit(gpa); |
| 2020 | var diag: Diagnostics = .{}; |
| 2021 | defer diag.deinit(gpa); |
| 2022 | 2022 | try std.testing.expectError( |
| 2023 | 2023 | error.ParseZon, |
| 2024 | | fromSlice([]u8, gpa, "'a'", &status, .{}), |
| 2024 | fromSlice([]u8, gpa, "'a'", &diag, .{}), |
| 2025 | 2025 | ); |
| 2026 | | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status}); |
| 2026 | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag}); |
| 2027 | 2027 | } |
| 2028 | 2028 | } |
| 2029 | 2029 | |
| 2030 | 2030 | // Address of is not allowed (indirection for slices in ZON is implicit) |
| 2031 | 2031 | { |
| 2032 | | var status: Status = .{}; |
| 2033 | | defer status.deinit(gpa); |
| 2032 | var diag: Diagnostics = .{}; |
| 2033 | defer diag.deinit(gpa); |
| 2034 | 2034 | try std.testing.expectError( |
| 2035 | 2035 | error.ParseZon, |
| 2036 | | fromSlice([]u8, gpa, " &.{'a', 'b', 'c'}", &status, .{}), |
| 2036 | fromSlice([]u8, gpa, " &.{'a', 'b', 'c'}", &diag, .{}), |
| 2037 | 2037 | ); |
| 2038 | 2038 | try std.testing.expectFmt( |
| 2039 | 2039 | "1:3: error: pointers are not available in ZON\n", |
| 2040 | 2040 | "{}", |
| 2041 | | .{status}, |
| 2041 | .{diag}, |
| 2042 | 2042 | ); |
| 2043 | 2043 | } |
| 2044 | 2044 | } |
| ... | ... | @@ -2070,23 +2070,23 @@ test "std.zon string literal" { |
| 2070 | 2070 | // Passing string literal to a mutable slice |
| 2071 | 2071 | { |
| 2072 | 2072 | { |
| 2073 | | var status: Status = .{}; |
| 2074 | | defer status.deinit(gpa); |
| 2073 | var diag: Diagnostics = .{}; |
| 2074 | defer diag.deinit(gpa); |
| 2075 | 2075 | try std.testing.expectError( |
| 2076 | 2076 | error.ParseZon, |
| 2077 | | fromSlice([]u8, gpa, "\"abcd\"", &status, .{}), |
| 2077 | fromSlice([]u8, gpa, "\"abcd\"", &diag, .{}), |
| 2078 | 2078 | ); |
| 2079 | | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status}); |
| 2079 | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag}); |
| 2080 | 2080 | } |
| 2081 | 2081 | |
| 2082 | 2082 | { |
| 2083 | | var status: Status = .{}; |
| 2084 | | defer status.deinit(gpa); |
| 2083 | var diag: Diagnostics = .{}; |
| 2084 | defer diag.deinit(gpa); |
| 2085 | 2085 | try std.testing.expectError( |
| 2086 | 2086 | error.ParseZon, |
| 2087 | | fromSlice([]u8, gpa, "\\\\abcd", &status, .{}), |
| 2087 | fromSlice([]u8, gpa, "\\\\abcd", &diag, .{}), |
| 2088 | 2088 | ); |
| 2089 | | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status}); |
| 2089 | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag}); |
| 2090 | 2090 | } |
| 2091 | 2091 | } |
| 2092 | 2092 | |
| ... | ... | @@ -2097,23 +2097,23 @@ test "std.zon string literal" { |
| 2097 | 2097 | defer ast.deinit(gpa); |
| 2098 | 2098 | var zoir = try ZonGen.generate(gpa, ast, .{ .parse_str_lits = false }); |
| 2099 | 2099 | defer zoir.deinit(gpa); |
| 2100 | | var status: Status = .{}; |
| 2101 | | defer status.deinit(gpa); |
| 2100 | var diag: Diagnostics = .{}; |
| 2101 | defer diag.deinit(gpa); |
| 2102 | 2102 | try std.testing.expectError( |
| 2103 | 2103 | error.ParseZon, |
| 2104 | | fromSlice([4:0]u8, gpa, "\"abcd\"", &status, .{}), |
| 2104 | fromSlice([4:0]u8, gpa, "\"abcd\"", &diag, .{}), |
| 2105 | 2105 | ); |
| 2106 | | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status}); |
| 2106 | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag}); |
| 2107 | 2107 | } |
| 2108 | 2108 | |
| 2109 | 2109 | { |
| 2110 | | var status: Status = .{}; |
| 2111 | | defer status.deinit(gpa); |
| 2110 | var diag: Diagnostics = .{}; |
| 2111 | defer diag.deinit(gpa); |
| 2112 | 2112 | try std.testing.expectError( |
| 2113 | 2113 | error.ParseZon, |
| 2114 | | fromSlice([4:0]u8, gpa, "\\\\abcd", &status, .{}), |
| 2114 | fromSlice([4:0]u8, gpa, "\\\\abcd", &diag, .{}), |
| 2115 | 2115 | ); |
| 2116 | | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status}); |
| 2116 | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag}); |
| 2117 | 2117 | } |
| 2118 | 2118 | } |
| 2119 | 2119 | |
| ... | ... | @@ -2149,102 +2149,102 @@ test "std.zon string literal" { |
| 2149 | 2149 | // Other value terminated slices |
| 2150 | 2150 | { |
| 2151 | 2151 | { |
| 2152 | | var status: Status = .{}; |
| 2153 | | defer status.deinit(gpa); |
| 2152 | var diag: Diagnostics = .{}; |
| 2153 | defer diag.deinit(gpa); |
| 2154 | 2154 | try std.testing.expectError( |
| 2155 | 2155 | error.ParseZon, |
| 2156 | | fromSlice([:1]const u8, gpa, "\"foo\"", &status, .{}), |
| 2156 | fromSlice([:1]const u8, gpa, "\"foo\"", &diag, .{}), |
| 2157 | 2157 | ); |
| 2158 | | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status}); |
| 2158 | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag}); |
| 2159 | 2159 | } |
| 2160 | 2160 | |
| 2161 | 2161 | { |
| 2162 | | var status: Status = .{}; |
| 2163 | | defer status.deinit(gpa); |
| 2162 | var diag: Diagnostics = .{}; |
| 2163 | defer diag.deinit(gpa); |
| 2164 | 2164 | try std.testing.expectError( |
| 2165 | 2165 | error.ParseZon, |
| 2166 | | fromSlice([:1]const u8, gpa, "\\\\foo", &status, .{}), |
| 2166 | fromSlice([:1]const u8, gpa, "\\\\foo", &diag, .{}), |
| 2167 | 2167 | ); |
| 2168 | | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status}); |
| 2168 | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag}); |
| 2169 | 2169 | } |
| 2170 | 2170 | } |
| 2171 | 2171 | |
| 2172 | 2172 | // Expecting string literal, getting something else |
| 2173 | 2173 | { |
| 2174 | | var status: Status = .{}; |
| 2175 | | defer status.deinit(gpa); |
| 2174 | var diag: Diagnostics = .{}; |
| 2175 | defer diag.deinit(gpa); |
| 2176 | 2176 | try std.testing.expectError( |
| 2177 | 2177 | error.ParseZon, |
| 2178 | | fromSlice([]const u8, gpa, "true", &status, .{}), |
| 2178 | fromSlice([]const u8, gpa, "true", &diag, .{}), |
| 2179 | 2179 | ); |
| 2180 | | try std.testing.expectFmt("1:1: error: expected string\n", "{}", .{status}); |
| 2180 | try std.testing.expectFmt("1:1: error: expected string\n", "{}", .{diag}); |
| 2181 | 2181 | } |
| 2182 | 2182 | |
| 2183 | 2183 | // Expecting string literal, getting an incompatible tuple |
| 2184 | 2184 | { |
| 2185 | | var status: Status = .{}; |
| 2186 | | defer status.deinit(gpa); |
| 2185 | var diag: Diagnostics = .{}; |
| 2186 | defer diag.deinit(gpa); |
| 2187 | 2187 | try std.testing.expectError( |
| 2188 | 2188 | error.ParseZon, |
| 2189 | | fromSlice([]const u8, gpa, ".{false}", &status, .{}), |
| 2189 | fromSlice([]const u8, gpa, ".{false}", &diag, .{}), |
| 2190 | 2190 | ); |
| 2191 | | try std.testing.expectFmt("1:3: error: expected type 'u8'\n", "{}", .{status}); |
| 2191 | try std.testing.expectFmt("1:3: error: expected type 'u8'\n", "{}", .{diag}); |
| 2192 | 2192 | } |
| 2193 | 2193 | |
| 2194 | 2194 | // Invalid string literal |
| 2195 | 2195 | { |
| 2196 | | var status: Status = .{}; |
| 2197 | | defer status.deinit(gpa); |
| 2196 | var diag: Diagnostics = .{}; |
| 2197 | defer diag.deinit(gpa); |
| 2198 | 2198 | try std.testing.expectError( |
| 2199 | 2199 | error.ParseZon, |
| 2200 | | fromSlice([]const i8, gpa, "\"\\a\"", &status, .{}), |
| 2200 | fromSlice([]const i8, gpa, "\"\\a\"", &diag, .{}), |
| 2201 | 2201 | ); |
| 2202 | | try std.testing.expectFmt("1:3: error: invalid escape character: 'a'\n", "{}", .{status}); |
| 2202 | try std.testing.expectFmt("1:3: error: invalid escape character: 'a'\n", "{}", .{diag}); |
| 2203 | 2203 | } |
| 2204 | 2204 | |
| 2205 | 2205 | // Slice wrong child type |
| 2206 | 2206 | { |
| 2207 | 2207 | { |
| 2208 | | var status: Status = .{}; |
| 2209 | | defer status.deinit(gpa); |
| 2208 | var diag: Diagnostics = .{}; |
| 2209 | defer diag.deinit(gpa); |
| 2210 | 2210 | try std.testing.expectError( |
| 2211 | 2211 | error.ParseZon, |
| 2212 | | fromSlice([]const i8, gpa, "\"a\"", &status, .{}), |
| 2212 | fromSlice([]const i8, gpa, "\"a\"", &diag, .{}), |
| 2213 | 2213 | ); |
| 2214 | | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status}); |
| 2214 | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag}); |
| 2215 | 2215 | } |
| 2216 | 2216 | |
| 2217 | 2217 | { |
| 2218 | | var status: Status = .{}; |
| 2219 | | defer status.deinit(gpa); |
| 2218 | var diag: Diagnostics = .{}; |
| 2219 | defer diag.deinit(gpa); |
| 2220 | 2220 | try std.testing.expectError( |
| 2221 | 2221 | error.ParseZon, |
| 2222 | | fromSlice([]const i8, gpa, "\\\\a", &status, .{}), |
| 2222 | fromSlice([]const i8, gpa, "\\\\a", &diag, .{}), |
| 2223 | 2223 | ); |
| 2224 | | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status}); |
| 2224 | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag}); |
| 2225 | 2225 | } |
| 2226 | 2226 | } |
| 2227 | 2227 | |
| 2228 | 2228 | // Bad alignment |
| 2229 | 2229 | { |
| 2230 | 2230 | { |
| 2231 | | var status: Status = .{}; |
| 2232 | | defer status.deinit(gpa); |
| 2231 | var diag: Diagnostics = .{}; |
| 2232 | defer diag.deinit(gpa); |
| 2233 | 2233 | try std.testing.expectError( |
| 2234 | 2234 | error.ParseZon, |
| 2235 | | fromSlice([]align(2) const u8, gpa, "\"abc\"", &status, .{}), |
| 2235 | fromSlice([]align(2) const u8, gpa, "\"abc\"", &diag, .{}), |
| 2236 | 2236 | ); |
| 2237 | | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status}); |
| 2237 | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag}); |
| 2238 | 2238 | } |
| 2239 | 2239 | |
| 2240 | 2240 | { |
| 2241 | | var status: Status = .{}; |
| 2242 | | defer status.deinit(gpa); |
| 2241 | var diag: Diagnostics = .{}; |
| 2242 | defer diag.deinit(gpa); |
| 2243 | 2243 | try std.testing.expectError( |
| 2244 | 2244 | error.ParseZon, |
| 2245 | | fromSlice([]align(2) const u8, gpa, "\\\\abc", &status, .{}), |
| 2245 | fromSlice([]align(2) const u8, gpa, "\\\\abc", &diag, .{}), |
| 2246 | 2246 | ); |
| 2247 | | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status}); |
| 2247 | try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag}); |
| 2248 | 2248 | } |
| 2249 | 2249 | } |
| 2250 | 2250 | |
| ... | ... | @@ -2307,11 +2307,11 @@ test "std.zon enum literals" { |
| 2307 | 2307 | |
| 2308 | 2308 | // Bad tag |
| 2309 | 2309 | { |
| 2310 | | var status: Status = .{}; |
| 2311 | | defer status.deinit(gpa); |
| 2310 | var diag: Diagnostics = .{}; |
| 2311 | defer diag.deinit(gpa); |
| 2312 | 2312 | try std.testing.expectError( |
| 2313 | 2313 | error.ParseZon, |
| 2314 | | fromSlice(Enum, gpa, ".qux", &status, .{}), |
| 2314 | fromSlice(Enum, gpa, ".qux", &diag, .{}), |
| 2315 | 2315 | ); |
| 2316 | 2316 | try std.testing.expectFmt( |
| 2317 | 2317 | \\1:2: error: unexpected enum literal 'qux' |
| ... | ... | @@ -2319,17 +2319,17 @@ test "std.zon enum literals" { |
| 2319 | 2319 | \\ |
| 2320 | 2320 | , |
| 2321 | 2321 | "{}", |
| 2322 | | .{status}, |
| 2322 | .{diag}, |
| 2323 | 2323 | ); |
| 2324 | 2324 | } |
| 2325 | 2325 | |
| 2326 | 2326 | // Bad tag that's too long for parser |
| 2327 | 2327 | { |
| 2328 | | var status: Status = .{}; |
| 2329 | | defer status.deinit(gpa); |
| 2328 | var diag: Diagnostics = .{}; |
| 2329 | defer diag.deinit(gpa); |
| 2330 | 2330 | try std.testing.expectError( |
| 2331 | 2331 | error.ParseZon, |
| 2332 | | fromSlice(Enum, gpa, ".@\"foobarbaz\"", &status, .{}), |
| 2332 | fromSlice(Enum, gpa, ".@\"foobarbaz\"", &diag, .{}), |
| 2333 | 2333 | ); |
| 2334 | 2334 | try std.testing.expectFmt( |
| 2335 | 2335 | \\1:2: error: unexpected enum literal 'foobarbaz' |
| ... | ... | @@ -2337,33 +2337,33 @@ test "std.zon enum literals" { |
| 2337 | 2337 | \\ |
| 2338 | 2338 | , |
| 2339 | 2339 | "{}", |
| 2340 | | .{status}, |
| 2340 | .{diag}, |
| 2341 | 2341 | ); |
| 2342 | 2342 | } |
| 2343 | 2343 | |
| 2344 | 2344 | // Bad type |
| 2345 | 2345 | { |
| 2346 | | var status: Status = .{}; |
| 2347 | | defer status.deinit(gpa); |
| 2346 | var diag: Diagnostics = .{}; |
| 2347 | defer diag.deinit(gpa); |
| 2348 | 2348 | try std.testing.expectError( |
| 2349 | 2349 | error.ParseZon, |
| 2350 | | fromSlice(Enum, gpa, "true", &status, .{}), |
| 2350 | fromSlice(Enum, gpa, "true", &diag, .{}), |
| 2351 | 2351 | ); |
| 2352 | | try std.testing.expectFmt("1:1: error: expected enum literal\n", "{}", .{status}); |
| 2352 | try std.testing.expectFmt("1:1: error: expected enum literal\n", "{}", .{diag}); |
| 2353 | 2353 | } |
| 2354 | 2354 | |
| 2355 | 2355 | // Test embedded nulls in an identifier |
| 2356 | 2356 | { |
| 2357 | | var status: Status = .{}; |
| 2358 | | defer status.deinit(gpa); |
| 2357 | var diag: Diagnostics = .{}; |
| 2358 | defer diag.deinit(gpa); |
| 2359 | 2359 | try std.testing.expectError( |
| 2360 | 2360 | error.ParseZon, |
| 2361 | | fromSlice(Enum, gpa, ".@\"\\x00\"", &status, .{}), |
| 2361 | fromSlice(Enum, gpa, ".@\"\\x00\"", &diag, .{}), |
| 2362 | 2362 | ); |
| 2363 | 2363 | try std.testing.expectFmt( |
| 2364 | 2364 | "1:2: error: identifier cannot contain null bytes\n", |
| 2365 | 2365 | "{}", |
| 2366 | | .{status}, |
| 2366 | .{diag}, |
| 2367 | 2367 | ); |
| 2368 | 2368 | } |
| 2369 | 2369 | } |
| ... | ... | @@ -2377,24 +2377,24 @@ test "std.zon parse bool" { |
| 2377 | 2377 | |
| 2378 | 2378 | // Errors |
| 2379 | 2379 | { |
| 2380 | | var status: Status = .{}; |
| 2381 | | defer status.deinit(gpa); |
| 2380 | var diag: Diagnostics = .{}; |
| 2381 | defer diag.deinit(gpa); |
| 2382 | 2382 | try std.testing.expectError( |
| 2383 | 2383 | error.ParseZon, |
| 2384 | | fromSlice(bool, gpa, " foo", &status, .{}), |
| 2384 | fromSlice(bool, gpa, " foo", &diag, .{}), |
| 2385 | 2385 | ); |
| 2386 | 2386 | try std.testing.expectFmt( |
| 2387 | 2387 | \\1:2: error: invalid expression |
| 2388 | 2388 | \\1:2: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan' |
| 2389 | 2389 | \\1:2: note: precede identifier with '.' for an enum literal |
| 2390 | 2390 | \\ |
| 2391 | | , "{}", .{status}); |
| 2391 | , "{}", .{diag}); |
| 2392 | 2392 | } |
| 2393 | 2393 | { |
| 2394 | | var status: Status = .{}; |
| 2395 | | defer status.deinit(gpa); |
| 2396 | | try std.testing.expectError(error.ParseZon, fromSlice(bool, gpa, "123", &status, .{})); |
| 2397 | | try std.testing.expectFmt("1:1: error: expected type 'bool'\n", "{}", .{status}); |
| 2394 | var diag: Diagnostics = .{}; |
| 2395 | defer diag.deinit(gpa); |
| 2396 | try std.testing.expectError(error.ParseZon, fromSlice(bool, gpa, "123", &diag, .{})); |
| 2397 | try std.testing.expectFmt("1:1: error: expected type 'bool'\n", "{}", .{diag}); |
| 2398 | 2398 | } |
| 2399 | 2399 | } |
| 2400 | 2400 | |
| ... | ... | @@ -2456,35 +2456,35 @@ test "std.zon parse int" { |
| 2456 | 2456 | try fromSlice(i66, gpa, "-36893488147419103232", null, .{}), |
| 2457 | 2457 | ); |
| 2458 | 2458 | { |
| 2459 | | var status: Status = .{}; |
| 2460 | | defer status.deinit(gpa); |
| 2459 | var diag: Diagnostics = .{}; |
| 2460 | defer diag.deinit(gpa); |
| 2461 | 2461 | try std.testing.expectError(error.ParseZon, fromSlice( |
| 2462 | 2462 | i66, |
| 2463 | 2463 | gpa, |
| 2464 | 2464 | "36893488147419103232", |
| 2465 | | &status, |
| 2465 | &diag, |
| 2466 | 2466 | .{}, |
| 2467 | 2467 | )); |
| 2468 | 2468 | try std.testing.expectFmt( |
| 2469 | 2469 | "1:1: error: type 'i66' cannot represent value\n", |
| 2470 | 2470 | "{}", |
| 2471 | | .{status}, |
| 2471 | .{diag}, |
| 2472 | 2472 | ); |
| 2473 | 2473 | } |
| 2474 | 2474 | { |
| 2475 | | var status: Status = .{}; |
| 2476 | | defer status.deinit(gpa); |
| 2475 | var diag: Diagnostics = .{}; |
| 2476 | defer diag.deinit(gpa); |
| 2477 | 2477 | try std.testing.expectError(error.ParseZon, fromSlice( |
| 2478 | 2478 | i66, |
| 2479 | 2479 | gpa, |
| 2480 | 2480 | "-36893488147419103233", |
| 2481 | | &status, |
| 2481 | &diag, |
| 2482 | 2482 | .{}, |
| 2483 | 2483 | )); |
| 2484 | 2484 | try std.testing.expectFmt( |
| 2485 | 2485 | "1:1: error: type 'i66' cannot represent value\n", |
| 2486 | 2486 | "{}", |
| 2487 | | .{status}, |
| 2487 | .{diag}, |
| 2488 | 2488 | ); |
| 2489 | 2489 | } |
| 2490 | 2490 | |
| ... | ... | @@ -2567,108 +2567,108 @@ test "std.zon parse int" { |
| 2567 | 2567 | |
| 2568 | 2568 | // Number with invalid character in the middle |
| 2569 | 2569 | { |
| 2570 | | var status: Status = .{}; |
| 2571 | | defer status.deinit(gpa); |
| 2572 | | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "32a32", &status, .{})); |
| 2570 | var diag: Diagnostics = .{}; |
| 2571 | defer diag.deinit(gpa); |
| 2572 | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "32a32", &diag, .{})); |
| 2573 | 2573 | try std.testing.expectFmt( |
| 2574 | 2574 | "1:3: error: invalid digit 'a' for decimal base\n", |
| 2575 | 2575 | "{}", |
| 2576 | | .{status}, |
| 2576 | .{diag}, |
| 2577 | 2577 | ); |
| 2578 | 2578 | } |
| 2579 | 2579 | |
| 2580 | 2580 | // Failing to parse as int |
| 2581 | 2581 | { |
| 2582 | | var status: Status = .{}; |
| 2583 | | defer status.deinit(gpa); |
| 2584 | | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "true", &status, .{})); |
| 2585 | | try std.testing.expectFmt("1:1: error: expected type 'u8'\n", "{}", .{status}); |
| 2582 | var diag: Diagnostics = .{}; |
| 2583 | defer diag.deinit(gpa); |
| 2584 | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "true", &diag, .{})); |
| 2585 | try std.testing.expectFmt("1:1: error: expected type 'u8'\n", "{}", .{diag}); |
| 2586 | 2586 | } |
| 2587 | 2587 | |
| 2588 | 2588 | // Failing because an int is out of range |
| 2589 | 2589 | { |
| 2590 | | var status: Status = .{}; |
| 2591 | | defer status.deinit(gpa); |
| 2592 | | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "256", &status, .{})); |
| 2590 | var diag: Diagnostics = .{}; |
| 2591 | defer diag.deinit(gpa); |
| 2592 | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "256", &diag, .{})); |
| 2593 | 2593 | try std.testing.expectFmt( |
| 2594 | 2594 | "1:1: error: type 'u8' cannot represent value\n", |
| 2595 | 2595 | "{}", |
| 2596 | | .{status}, |
| 2596 | .{diag}, |
| 2597 | 2597 | ); |
| 2598 | 2598 | } |
| 2599 | 2599 | |
| 2600 | 2600 | // Failing because a negative int is out of range |
| 2601 | 2601 | { |
| 2602 | | var status: Status = .{}; |
| 2603 | | defer status.deinit(gpa); |
| 2604 | | try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-129", &status, .{})); |
| 2602 | var diag: Diagnostics = .{}; |
| 2603 | defer diag.deinit(gpa); |
| 2604 | try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-129", &diag, .{})); |
| 2605 | 2605 | try std.testing.expectFmt( |
| 2606 | 2606 | "1:1: error: type 'i8' cannot represent value\n", |
| 2607 | 2607 | "{}", |
| 2608 | | .{status}, |
| 2608 | .{diag}, |
| 2609 | 2609 | ); |
| 2610 | 2610 | } |
| 2611 | 2611 | |
| 2612 | 2612 | // Failing because an unsigned int is negative |
| 2613 | 2613 | { |
| 2614 | | var status: Status = .{}; |
| 2615 | | defer status.deinit(gpa); |
| 2616 | | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "-1", &status, .{})); |
| 2614 | var diag: Diagnostics = .{}; |
| 2615 | defer diag.deinit(gpa); |
| 2616 | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "-1", &diag, .{})); |
| 2617 | 2617 | try std.testing.expectFmt( |
| 2618 | 2618 | "1:1: error: type 'u8' cannot represent value\n", |
| 2619 | 2619 | "{}", |
| 2620 | | .{status}, |
| 2620 | .{diag}, |
| 2621 | 2621 | ); |
| 2622 | 2622 | } |
| 2623 | 2623 | |
| 2624 | 2624 | // Failing because a float is non-whole |
| 2625 | 2625 | { |
| 2626 | | var status: Status = .{}; |
| 2627 | | defer status.deinit(gpa); |
| 2628 | | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "1.5", &status, .{})); |
| 2626 | var diag: Diagnostics = .{}; |
| 2627 | defer diag.deinit(gpa); |
| 2628 | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "1.5", &diag, .{})); |
| 2629 | 2629 | try std.testing.expectFmt( |
| 2630 | 2630 | "1:1: error: type 'u8' cannot represent value\n", |
| 2631 | 2631 | "{}", |
| 2632 | | .{status}, |
| 2632 | .{diag}, |
| 2633 | 2633 | ); |
| 2634 | 2634 | } |
| 2635 | 2635 | |
| 2636 | 2636 | // Failing because a float is negative |
| 2637 | 2637 | { |
| 2638 | | var status: Status = .{}; |
| 2639 | | defer status.deinit(gpa); |
| 2640 | | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "-1.0", &status, .{})); |
| 2638 | var diag: Diagnostics = .{}; |
| 2639 | defer diag.deinit(gpa); |
| 2640 | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "-1.0", &diag, .{})); |
| 2641 | 2641 | try std.testing.expectFmt( |
| 2642 | 2642 | "1:1: error: type 'u8' cannot represent value\n", |
| 2643 | 2643 | "{}", |
| 2644 | | .{status}, |
| 2644 | .{diag}, |
| 2645 | 2645 | ); |
| 2646 | 2646 | } |
| 2647 | 2647 | |
| 2648 | 2648 | // Negative integer zero |
| 2649 | 2649 | { |
| 2650 | | var status: Status = .{}; |
| 2651 | | defer status.deinit(gpa); |
| 2652 | | try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-0", &status, .{})); |
| 2650 | var diag: Diagnostics = .{}; |
| 2651 | defer diag.deinit(gpa); |
| 2652 | try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-0", &diag, .{})); |
| 2653 | 2653 | try std.testing.expectFmt( |
| 2654 | 2654 | \\1:2: error: integer literal '-0' is ambiguous |
| 2655 | 2655 | \\1:2: note: use '0' for an integer zero |
| 2656 | 2656 | \\1:2: note: use '-0.0' for a floating-point signed zero |
| 2657 | 2657 | \\ |
| 2658 | | , "{}", .{status}); |
| 2658 | , "{}", .{diag}); |
| 2659 | 2659 | } |
| 2660 | 2660 | |
| 2661 | 2661 | // Negative integer zero casted to float |
| 2662 | 2662 | { |
| 2663 | | var status: Status = .{}; |
| 2664 | | defer status.deinit(gpa); |
| 2665 | | try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-0", &status, .{})); |
| 2663 | var diag: Diagnostics = .{}; |
| 2664 | defer diag.deinit(gpa); |
| 2665 | try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-0", &diag, .{})); |
| 2666 | 2666 | try std.testing.expectFmt( |
| 2667 | 2667 | \\1:2: error: integer literal '-0' is ambiguous |
| 2668 | 2668 | \\1:2: note: use '0' for an integer zero |
| 2669 | 2669 | \\1:2: note: use '-0.0' for a floating-point signed zero |
| 2670 | 2670 | \\ |
| 2671 | | , "{}", .{status}); |
| 2671 | , "{}", .{diag}); |
| 2672 | 2672 | } |
| 2673 | 2673 | |
| 2674 | 2674 | // Negative float 0 is allowed |
| ... | ... | @@ -2679,48 +2679,48 @@ test "std.zon parse int" { |
| 2679 | 2679 | |
| 2680 | 2680 | // Double negation is not allowed |
| 2681 | 2681 | { |
| 2682 | | var status: Status = .{}; |
| 2683 | | defer status.deinit(gpa); |
| 2684 | | try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "--2", &status, .{})); |
| 2682 | var diag: Diagnostics = .{}; |
| 2683 | defer diag.deinit(gpa); |
| 2684 | try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "--2", &diag, .{})); |
| 2685 | 2685 | try std.testing.expectFmt( |
| 2686 | 2686 | "1:1: error: expected number or 'inf' after '-'\n", |
| 2687 | 2687 | "{}", |
| 2688 | | .{status}, |
| 2688 | .{diag}, |
| 2689 | 2689 | ); |
| 2690 | 2690 | } |
| 2691 | 2691 | |
| 2692 | 2692 | { |
| 2693 | | var status: Status = .{}; |
| 2694 | | defer status.deinit(gpa); |
| 2693 | var diag: Diagnostics = .{}; |
| 2694 | defer diag.deinit(gpa); |
| 2695 | 2695 | try std.testing.expectError( |
| 2696 | 2696 | error.ParseZon, |
| 2697 | | fromSlice(f32, gpa, "--2.0", &status, .{}), |
| 2697 | fromSlice(f32, gpa, "--2.0", &diag, .{}), |
| 2698 | 2698 | ); |
| 2699 | 2699 | try std.testing.expectFmt( |
| 2700 | 2700 | "1:1: error: expected number or 'inf' after '-'\n", |
| 2701 | 2701 | "{}", |
| 2702 | | .{status}, |
| 2702 | .{diag}, |
| 2703 | 2703 | ); |
| 2704 | 2704 | } |
| 2705 | 2705 | |
| 2706 | 2706 | // Invalid int literal |
| 2707 | 2707 | { |
| 2708 | | var status: Status = .{}; |
| 2709 | | defer status.deinit(gpa); |
| 2710 | | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "0xg", &status, .{})); |
| 2711 | | try std.testing.expectFmt("1:3: error: invalid digit 'g' for hex base\n", "{}", .{status}); |
| 2708 | var diag: Diagnostics = .{}; |
| 2709 | defer diag.deinit(gpa); |
| 2710 | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "0xg", &diag, .{})); |
| 2711 | try std.testing.expectFmt("1:3: error: invalid digit 'g' for hex base\n", "{}", .{diag}); |
| 2712 | 2712 | } |
| 2713 | 2713 | |
| 2714 | 2714 | // Notes on invalid int literal |
| 2715 | 2715 | { |
| 2716 | | var status: Status = .{}; |
| 2717 | | defer status.deinit(gpa); |
| 2718 | | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "0123", &status, .{})); |
| 2716 | var diag: Diagnostics = .{}; |
| 2717 | defer diag.deinit(gpa); |
| 2718 | try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "0123", &diag, .{})); |
| 2719 | 2719 | try std.testing.expectFmt( |
| 2720 | 2720 | \\1:1: error: number '0123' has leading zero |
| 2721 | 2721 | \\1:1: note: use '0o' prefix for octal literals |
| 2722 | 2722 | \\ |
| 2723 | | , "{}", .{status}); |
| 2723 | , "{}", .{diag}); |
| 2724 | 2724 | } |
| 2725 | 2725 | } |
| 2726 | 2726 | |
| ... | ... | @@ -2728,23 +2728,23 @@ test "std.zon negative char" { |
| 2728 | 2728 | const gpa = std.testing.allocator; |
| 2729 | 2729 | |
| 2730 | 2730 | { |
| 2731 | | var status: Status = .{}; |
| 2732 | | defer status.deinit(gpa); |
| 2733 | | try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-'a'", &status, .{})); |
| 2731 | var diag: Diagnostics = .{}; |
| 2732 | defer diag.deinit(gpa); |
| 2733 | try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-'a'", &diag, .{})); |
| 2734 | 2734 | try std.testing.expectFmt( |
| 2735 | 2735 | "1:1: error: expected number or 'inf' after '-'\n", |
| 2736 | 2736 | "{}", |
| 2737 | | .{status}, |
| 2737 | .{diag}, |
| 2738 | 2738 | ); |
| 2739 | 2739 | } |
| 2740 | 2740 | { |
| 2741 | | var status: Status = .{}; |
| 2742 | | defer status.deinit(gpa); |
| 2743 | | try std.testing.expectError(error.ParseZon, fromSlice(i16, gpa, "-'a'", &status, .{})); |
| 2741 | var diag: Diagnostics = .{}; |
| 2742 | defer diag.deinit(gpa); |
| 2743 | try std.testing.expectError(error.ParseZon, fromSlice(i16, gpa, "-'a'", &diag, .{})); |
| 2744 | 2744 | try std.testing.expectFmt( |
| 2745 | 2745 | "1:1: error: expected number or 'inf' after '-'\n", |
| 2746 | 2746 | "{}", |
| 2747 | | .{status}, |
| 2747 | .{diag}, |
| 2748 | 2748 | ); |
| 2749 | 2749 | } |
| 2750 | 2750 | } |
| ... | ... | @@ -2825,81 +2825,81 @@ test "std.zon parse float" { |
| 2825 | 2825 | |
| 2826 | 2826 | // Negative nan not allowed |
| 2827 | 2827 | { |
| 2828 | | var status: Status = .{}; |
| 2829 | | defer status.deinit(gpa); |
| 2830 | | try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-nan", &status, .{})); |
| 2828 | var diag: Diagnostics = .{}; |
| 2829 | defer diag.deinit(gpa); |
| 2830 | try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-nan", &diag, .{})); |
| 2831 | 2831 | try std.testing.expectFmt( |
| 2832 | 2832 | "1:1: error: expected number or 'inf' after '-'\n", |
| 2833 | 2833 | "{}", |
| 2834 | | .{status}, |
| 2834 | .{diag}, |
| 2835 | 2835 | ); |
| 2836 | 2836 | } |
| 2837 | 2837 | |
| 2838 | 2838 | // nan as int not allowed |
| 2839 | 2839 | { |
| 2840 | | var status: Status = .{}; |
| 2841 | | defer status.deinit(gpa); |
| 2842 | | try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "nan", &status, .{})); |
| 2843 | | try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{status}); |
| 2840 | var diag: Diagnostics = .{}; |
| 2841 | defer diag.deinit(gpa); |
| 2842 | try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "nan", &diag, .{})); |
| 2843 | try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{diag}); |
| 2844 | 2844 | } |
| 2845 | 2845 | |
| 2846 | 2846 | // nan as int not allowed |
| 2847 | 2847 | { |
| 2848 | | var status: Status = .{}; |
| 2849 | | defer status.deinit(gpa); |
| 2850 | | try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "nan", &status, .{})); |
| 2851 | | try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{status}); |
| 2848 | var diag: Diagnostics = .{}; |
| 2849 | defer diag.deinit(gpa); |
| 2850 | try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "nan", &diag, .{})); |
| 2851 | try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{diag}); |
| 2852 | 2852 | } |
| 2853 | 2853 | |
| 2854 | 2854 | // inf as int not allowed |
| 2855 | 2855 | { |
| 2856 | | var status: Status = .{}; |
| 2857 | | defer status.deinit(gpa); |
| 2858 | | try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "inf", &status, .{})); |
| 2859 | | try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{status}); |
| 2856 | var diag: Diagnostics = .{}; |
| 2857 | defer diag.deinit(gpa); |
| 2858 | try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "inf", &diag, .{})); |
| 2859 | try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{diag}); |
| 2860 | 2860 | } |
| 2861 | 2861 | |
| 2862 | 2862 | // -inf as int not allowed |
| 2863 | 2863 | { |
| 2864 | | var status: Status = .{}; |
| 2865 | | defer status.deinit(gpa); |
| 2866 | | try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-inf", &status, .{})); |
| 2867 | | try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{status}); |
| 2864 | var diag: Diagnostics = .{}; |
| 2865 | defer diag.deinit(gpa); |
| 2866 | try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-inf", &diag, .{})); |
| 2867 | try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{diag}); |
| 2868 | 2868 | } |
| 2869 | 2869 | |
| 2870 | 2870 | // Bad identifier as float |
| 2871 | 2871 | { |
| 2872 | | var status: Status = .{}; |
| 2873 | | defer status.deinit(gpa); |
| 2874 | | try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "foo", &status, .{})); |
| 2872 | var diag: Diagnostics = .{}; |
| 2873 | defer diag.deinit(gpa); |
| 2874 | try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "foo", &diag, .{})); |
| 2875 | 2875 | try std.testing.expectFmt( |
| 2876 | 2876 | \\1:1: error: invalid expression |
| 2877 | 2877 | \\1:1: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan' |
| 2878 | 2878 | \\1:1: note: precede identifier with '.' for an enum literal |
| 2879 | 2879 | \\ |
| 2880 | | , "{}", .{status}); |
| 2880 | , "{}", .{diag}); |
| 2881 | 2881 | } |
| 2882 | 2882 | |
| 2883 | 2883 | { |
| 2884 | | var status: Status = .{}; |
| 2885 | | defer status.deinit(gpa); |
| 2886 | | try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-foo", &status, .{})); |
| 2884 | var diag: Diagnostics = .{}; |
| 2885 | defer diag.deinit(gpa); |
| 2886 | try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-foo", &diag, .{})); |
| 2887 | 2887 | try std.testing.expectFmt( |
| 2888 | 2888 | "1:1: error: expected number or 'inf' after '-'\n", |
| 2889 | 2889 | "{}", |
| 2890 | | .{status}, |
| 2890 | .{diag}, |
| 2891 | 2891 | ); |
| 2892 | 2892 | } |
| 2893 | 2893 | |
| 2894 | 2894 | // Non float as float |
| 2895 | 2895 | { |
| 2896 | | var status: Status = .{}; |
| 2897 | | defer status.deinit(gpa); |
| 2896 | var diag: Diagnostics = .{}; |
| 2897 | defer diag.deinit(gpa); |
| 2898 | 2898 | try std.testing.expectError( |
| 2899 | 2899 | error.ParseZon, |
| 2900 | | fromSlice(f32, gpa, "\"foo\"", &status, .{}), |
| 2900 | fromSlice(f32, gpa, "\"foo\"", &diag, .{}), |
| 2901 | 2901 | ); |
| 2902 | | try std.testing.expectFmt("1:1: error: expected type 'f32'\n", "{}", .{status}); |
| 2902 | try std.testing.expectFmt("1:1: error: expected type 'f32'\n", "{}", .{diag}); |
| 2903 | 2903 | } |
| 2904 | 2904 | } |
| 2905 | 2905 | |
| ... | ... | @@ -3136,69 +3136,69 @@ test "std.zon vector" { |
| 3136 | 3136 | |
| 3137 | 3137 | // Too few fields |
| 3138 | 3138 | { |
| 3139 | | var status: Status = .{}; |
| 3140 | | defer status.deinit(gpa); |
| 3139 | var diag: Diagnostics = .{}; |
| 3140 | defer diag.deinit(gpa); |
| 3141 | 3141 | try std.testing.expectError( |
| 3142 | 3142 | error.ParseZon, |
| 3143 | | fromSlice(@Vector(2, f32), gpa, ".{0.5}", &status, .{}), |
| 3143 | fromSlice(@Vector(2, f32), gpa, ".{0.5}", &diag, .{}), |
| 3144 | 3144 | ); |
| 3145 | 3145 | try std.testing.expectFmt( |
| 3146 | 3146 | "1:2: error: expected 2 vector elements; found 1\n", |
| 3147 | 3147 | "{}", |
| 3148 | | .{status}, |
| 3148 | .{diag}, |
| 3149 | 3149 | ); |
| 3150 | 3150 | } |
| 3151 | 3151 | |
| 3152 | 3152 | // Too many fields |
| 3153 | 3153 | { |
| 3154 | | var status: Status = .{}; |
| 3155 | | defer status.deinit(gpa); |
| 3154 | var diag: Diagnostics = .{}; |
| 3155 | defer diag.deinit(gpa); |
| 3156 | 3156 | try std.testing.expectError( |
| 3157 | 3157 | error.ParseZon, |
| 3158 | | fromSlice(@Vector(2, f32), gpa, ".{0.5, 1.5, 2.5}", &status, .{}), |
| 3158 | fromSlice(@Vector(2, f32), gpa, ".{0.5, 1.5, 2.5}", &diag, .{}), |
| 3159 | 3159 | ); |
| 3160 | 3160 | try std.testing.expectFmt( |
| 3161 | 3161 | "1:2: error: expected 2 vector elements; found 3\n", |
| 3162 | 3162 | "{}", |
| 3163 | | .{status}, |
| 3163 | .{diag}, |
| 3164 | 3164 | ); |
| 3165 | 3165 | } |
| 3166 | 3166 | |
| 3167 | 3167 | // Wrong type fields |
| 3168 | 3168 | { |
| 3169 | | var status: Status = .{}; |
| 3170 | | defer status.deinit(gpa); |
| 3169 | var diag: Diagnostics = .{}; |
| 3170 | defer diag.deinit(gpa); |
| 3171 | 3171 | try std.testing.expectError( |
| 3172 | 3172 | error.ParseZon, |
| 3173 | | fromSlice(@Vector(3, f32), gpa, ".{0.5, true, 2.5}", &status, .{}), |
| 3173 | fromSlice(@Vector(3, f32), gpa, ".{0.5, true, 2.5}", &diag, .{}), |
| 3174 | 3174 | ); |
| 3175 | 3175 | try std.testing.expectFmt( |
| 3176 | 3176 | "1:8: error: expected type 'f32'\n", |
| 3177 | 3177 | "{}", |
| 3178 | | .{status}, |
| 3178 | .{diag}, |
| 3179 | 3179 | ); |
| 3180 | 3180 | } |
| 3181 | 3181 | |
| 3182 | 3182 | // Wrong type |
| 3183 | 3183 | { |
| 3184 | | var status: Status = .{}; |
| 3185 | | defer status.deinit(gpa); |
| 3184 | var diag: Diagnostics = .{}; |
| 3185 | defer diag.deinit(gpa); |
| 3186 | 3186 | try std.testing.expectError( |
| 3187 | 3187 | error.ParseZon, |
| 3188 | | fromSlice(@Vector(3, u8), gpa, "true", &status, .{}), |
| 3188 | fromSlice(@Vector(3, u8), gpa, "true", &diag, .{}), |
| 3189 | 3189 | ); |
| 3190 | | try std.testing.expectFmt("1:1: error: expected type '@Vector(3, u8)'\n", "{}", .{status}); |
| 3190 | try std.testing.expectFmt("1:1: error: expected type '@Vector(3, u8)'\n", "{}", .{diag}); |
| 3191 | 3191 | } |
| 3192 | 3192 | |
| 3193 | 3193 | // Elements should get freed on error |
| 3194 | 3194 | { |
| 3195 | | var status: Status = .{}; |
| 3196 | | defer status.deinit(gpa); |
| 3195 | var diag: Diagnostics = .{}; |
| 3196 | defer diag.deinit(gpa); |
| 3197 | 3197 | try std.testing.expectError( |
| 3198 | 3198 | error.ParseZon, |
| 3199 | | fromSlice(@Vector(3, *u8), gpa, ".{1, true, 3}", &status, .{}), |
| 3199 | fromSlice(@Vector(3, *u8), gpa, ".{1, true, 3}", &diag, .{}), |
| 3200 | 3200 | ); |
| 3201 | | try std.testing.expectFmt("1:6: error: expected type 'u8'\n", "{}", .{status}); |
| 3201 | try std.testing.expectFmt("1:6: error: expected type 'u8'\n", "{}", .{diag}); |
| 3202 | 3202 | } |
| 3203 | 3203 | } |
| 3204 | 3204 | |
| ... | ... | @@ -3316,133 +3316,133 @@ test "std.zon add pointers" { |
| 3316 | 3316 | |
| 3317 | 3317 | // Test that optional types are flattened correctly in errors |
| 3318 | 3318 | { |
| 3319 | | var status: Status = .{}; |
| 3320 | | defer status.deinit(gpa); |
| 3319 | var diag: Diagnostics = .{}; |
| 3320 | defer diag.deinit(gpa); |
| 3321 | 3321 | try std.testing.expectError( |
| 3322 | 3322 | error.ParseZon, |
| 3323 | | fromSlice(*const ?*const u8, gpa, "true", &status, .{}), |
| 3323 | fromSlice(*const ?*const u8, gpa, "true", &diag, .{}), |
| 3324 | 3324 | ); |
| 3325 | | try std.testing.expectFmt("1:1: error: expected type '?u8'\n", "{}", .{status}); |
| 3325 | try std.testing.expectFmt("1:1: error: expected type '?u8'\n", "{}", .{diag}); |
| 3326 | 3326 | } |
| 3327 | 3327 | |
| 3328 | 3328 | { |
| 3329 | | var status: Status = .{}; |
| 3330 | | defer status.deinit(gpa); |
| 3329 | var diag: Diagnostics = .{}; |
| 3330 | defer diag.deinit(gpa); |
| 3331 | 3331 | try std.testing.expectError( |
| 3332 | 3332 | error.ParseZon, |
| 3333 | | fromSlice(*const ?*const f32, gpa, "true", &status, .{}), |
| 3333 | fromSlice(*const ?*const f32, gpa, "true", &diag, .{}), |
| 3334 | 3334 | ); |
| 3335 | | try std.testing.expectFmt("1:1: error: expected type '?f32'\n", "{}", .{status}); |
| 3335 | try std.testing.expectFmt("1:1: error: expected type '?f32'\n", "{}", .{diag}); |
| 3336 | 3336 | } |
| 3337 | 3337 | |
| 3338 | 3338 | { |
| 3339 | | var status: Status = .{}; |
| 3340 | | defer status.deinit(gpa); |
| 3339 | var diag: Diagnostics = .{}; |
| 3340 | defer diag.deinit(gpa); |
| 3341 | 3341 | try std.testing.expectError( |
| 3342 | 3342 | error.ParseZon, |
| 3343 | | fromSlice(*const ?*const @Vector(3, u8), gpa, "true", &status, .{}), |
| 3343 | fromSlice(*const ?*const @Vector(3, u8), gpa, "true", &diag, .{}), |
| 3344 | 3344 | ); |
| 3345 | | try std.testing.expectFmt("1:1: error: expected type '?@Vector(3, u8)'\n", "{}", .{status}); |
| 3345 | try std.testing.expectFmt("1:1: error: expected type '?@Vector(3, u8)'\n", "{}", .{diag}); |
| 3346 | 3346 | } |
| 3347 | 3347 | |
| 3348 | 3348 | { |
| 3349 | | var status: Status = .{}; |
| 3350 | | defer status.deinit(gpa); |
| 3349 | var diag: Diagnostics = .{}; |
| 3350 | defer diag.deinit(gpa); |
| 3351 | 3351 | try std.testing.expectError( |
| 3352 | 3352 | error.ParseZon, |
| 3353 | | fromSlice(*const ?*const bool, gpa, "10", &status, .{}), |
| 3353 | fromSlice(*const ?*const bool, gpa, "10", &diag, .{}), |
| 3354 | 3354 | ); |
| 3355 | | try std.testing.expectFmt("1:1: error: expected type '?bool'\n", "{}", .{status}); |
| 3355 | try std.testing.expectFmt("1:1: error: expected type '?bool'\n", "{}", .{diag}); |
| 3356 | 3356 | } |
| 3357 | 3357 | |
| 3358 | 3358 | { |
| 3359 | | var status: Status = .{}; |
| 3360 | | defer status.deinit(gpa); |
| 3359 | var diag: Diagnostics = .{}; |
| 3360 | defer diag.deinit(gpa); |
| 3361 | 3361 | try std.testing.expectError( |
| 3362 | 3362 | error.ParseZon, |
| 3363 | | fromSlice(*const ?*const struct { a: i32 }, gpa, "true", &status, .{}), |
| 3363 | fromSlice(*const ?*const struct { a: i32 }, gpa, "true", &diag, .{}), |
| 3364 | 3364 | ); |
| 3365 | | try std.testing.expectFmt("1:1: error: expected optional struct\n", "{}", .{status}); |
| 3365 | try std.testing.expectFmt("1:1: error: expected optional struct\n", "{}", .{diag}); |
| 3366 | 3366 | } |
| 3367 | 3367 | |
| 3368 | 3368 | { |
| 3369 | | var status: Status = .{}; |
| 3370 | | defer status.deinit(gpa); |
| 3369 | var diag: Diagnostics = .{}; |
| 3370 | defer diag.deinit(gpa); |
| 3371 | 3371 | try std.testing.expectError( |
| 3372 | 3372 | error.ParseZon, |
| 3373 | | fromSlice(*const ?*const struct { i32 }, gpa, "true", &status, .{}), |
| 3373 | fromSlice(*const ?*const struct { i32 }, gpa, "true", &diag, .{}), |
| 3374 | 3374 | ); |
| 3375 | | try std.testing.expectFmt("1:1: error: expected optional tuple\n", "{}", .{status}); |
| 3375 | try std.testing.expectFmt("1:1: error: expected optional tuple\n", "{}", .{diag}); |
| 3376 | 3376 | } |
| 3377 | 3377 | |
| 3378 | 3378 | { |
| 3379 | | var status: Status = .{}; |
| 3380 | | defer status.deinit(gpa); |
| 3379 | var diag: Diagnostics = .{}; |
| 3380 | defer diag.deinit(gpa); |
| 3381 | 3381 | try std.testing.expectError( |
| 3382 | 3382 | error.ParseZon, |
| 3383 | | fromSlice(*const ?*const union { x: void }, gpa, "true", &status, .{}), |
| 3383 | fromSlice(*const ?*const union { x: void }, gpa, "true", &diag, .{}), |
| 3384 | 3384 | ); |
| 3385 | | try std.testing.expectFmt("1:1: error: expected optional union\n", "{}", .{status}); |
| 3385 | try std.testing.expectFmt("1:1: error: expected optional union\n", "{}", .{diag}); |
| 3386 | 3386 | } |
| 3387 | 3387 | |
| 3388 | 3388 | { |
| 3389 | | var status: Status = .{}; |
| 3390 | | defer status.deinit(gpa); |
| 3389 | var diag: Diagnostics = .{}; |
| 3390 | defer diag.deinit(gpa); |
| 3391 | 3391 | try std.testing.expectError( |
| 3392 | 3392 | error.ParseZon, |
| 3393 | | fromSlice(*const ?*const [3]u8, gpa, "true", &status, .{}), |
| 3393 | fromSlice(*const ?*const [3]u8, gpa, "true", &diag, .{}), |
| 3394 | 3394 | ); |
| 3395 | | try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{status}); |
| 3395 | try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{diag}); |
| 3396 | 3396 | } |
| 3397 | 3397 | |
| 3398 | 3398 | { |
| 3399 | | var status: Status = .{}; |
| 3400 | | defer status.deinit(gpa); |
| 3399 | var diag: Diagnostics = .{}; |
| 3400 | defer diag.deinit(gpa); |
| 3401 | 3401 | try std.testing.expectError( |
| 3402 | 3402 | error.ParseZon, |
| 3403 | | fromSlice(?[3]u8, gpa, "true", &status, .{}), |
| 3403 | fromSlice(?[3]u8, gpa, "true", &diag, .{}), |
| 3404 | 3404 | ); |
| 3405 | | try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{status}); |
| 3405 | try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{diag}); |
| 3406 | 3406 | } |
| 3407 | 3407 | |
| 3408 | 3408 | { |
| 3409 | | var status: Status = .{}; |
| 3410 | | defer status.deinit(gpa); |
| 3409 | var diag: Diagnostics = .{}; |
| 3410 | defer diag.deinit(gpa); |
| 3411 | 3411 | try std.testing.expectError( |
| 3412 | 3412 | error.ParseZon, |
| 3413 | | fromSlice(*const ?*const []u8, gpa, "true", &status, .{}), |
| 3413 | fromSlice(*const ?*const []u8, gpa, "true", &diag, .{}), |
| 3414 | 3414 | ); |
| 3415 | | try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{status}); |
| 3415 | try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{diag}); |
| 3416 | 3416 | } |
| 3417 | 3417 | |
| 3418 | 3418 | { |
| 3419 | | var status: Status = .{}; |
| 3420 | | defer status.deinit(gpa); |
| 3419 | var diag: Diagnostics = .{}; |
| 3420 | defer diag.deinit(gpa); |
| 3421 | 3421 | try std.testing.expectError( |
| 3422 | 3422 | error.ParseZon, |
| 3423 | | fromSlice(?[]u8, gpa, "true", &status, .{}), |
| 3423 | fromSlice(?[]u8, gpa, "true", &diag, .{}), |
| 3424 | 3424 | ); |
| 3425 | | try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{status}); |
| 3425 | try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{diag}); |
| 3426 | 3426 | } |
| 3427 | 3427 | |
| 3428 | 3428 | { |
| 3429 | | var status: Status = .{}; |
| 3430 | | defer status.deinit(gpa); |
| 3429 | var diag: Diagnostics = .{}; |
| 3430 | defer diag.deinit(gpa); |
| 3431 | 3431 | try std.testing.expectError( |
| 3432 | 3432 | error.ParseZon, |
| 3433 | | fromSlice(*const ?*const []const u8, gpa, "true", &status, .{}), |
| 3433 | fromSlice(*const ?*const []const u8, gpa, "true", &diag, .{}), |
| 3434 | 3434 | ); |
| 3435 | | try std.testing.expectFmt("1:1: error: expected optional string\n", "{}", .{status}); |
| 3435 | try std.testing.expectFmt("1:1: error: expected optional string\n", "{}", .{diag}); |
| 3436 | 3436 | } |
| 3437 | 3437 | |
| 3438 | 3438 | { |
| 3439 | | var status: Status = .{}; |
| 3440 | | defer status.deinit(gpa); |
| 3439 | var diag: Diagnostics = .{}; |
| 3440 | defer diag.deinit(gpa); |
| 3441 | 3441 | try std.testing.expectError( |
| 3442 | 3442 | error.ParseZon, |
| 3443 | | fromSlice(*const ?*const enum { foo }, gpa, "true", &status, .{}), |
| 3443 | fromSlice(*const ?*const enum { foo }, gpa, "true", &diag, .{}), |
| 3444 | 3444 | ); |
| 3445 | | try std.testing.expectFmt("1:1: error: expected optional enum literal\n", "{}", .{status}); |
| 3445 | try std.testing.expectFmt("1:1: error: expected optional enum literal\n", "{}", .{diag}); |
| 3446 | 3446 | } |
| 3447 | 3447 | } |
| 3448 | 3448 | |
| ... | ... | @@ -3455,17 +3455,17 @@ test "std.zon stop on node" { |
| 3455 | 3455 | y: f32, |
| 3456 | 3456 | }; |
| 3457 | 3457 | |
| 3458 | | var status: Status = .{}; |
| 3459 | | defer status.deinit(gpa); |
| 3460 | | const result = try fromSlice(Vec2, gpa, ".{ .x = 1.5, .y = 2.5 }", &status, .{}); |
| 3458 | var diag: Diagnostics = .{}; |
| 3459 | defer diag.deinit(gpa); |
| 3460 | const result = try fromSlice(Vec2, gpa, ".{ .x = 1.5, .y = 2.5 }", &diag, .{}); |
| 3461 | 3461 | try std.testing.expectEqual(result.y, 2.5); |
| 3462 | | try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.5 }, result.x.get(status.zoir.?)); |
| 3462 | try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.5 }, result.x.get(diag.zoir.?)); |
| 3463 | 3463 | } |
| 3464 | 3464 | |
| 3465 | 3465 | { |
| 3466 | | var status: Status = .{}; |
| 3467 | | defer status.deinit(gpa); |
| 3468 | | const result = try fromSlice(Zoir.Node.Index, gpa, "1.23", &status, .{}); |
| 3469 | | try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.23 }, result.get(status.zoir.?)); |
| 3466 | var diag: Diagnostics = .{}; |
| 3467 | defer diag.deinit(gpa); |
| 3468 | const result = try fromSlice(Zoir.Node.Index, gpa, "1.23", &diag, .{}); |
| 3469 | try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.23 }, result.get(diag.zoir.?)); |
| 3470 | 3470 | } |
| 3471 | 3471 | } |