| ... | @@ -435,6 +435,7 @@ fn fromZoirInner( | ... | @@ -435,6 +435,7 @@ fn fromZoirInner( |
| 435 | .arena = options.arena, | 435 | .arena = options.arena, |
| 436 | .ast = options.ast, | 436 | .ast = options.ast, |
| 437 | .zoir = options.zoir, | 437 | .zoir = options.zoir, |
| | 438 | .node = options.node, |
| 438 | .errors = &errors, | 439 | .errors = &errors, |
| 439 | .ignore_unknown_fields = options.ignore_unknown_fields, | 440 | .ignore_unknown_fields = options.ignore_unknown_fields, |
| 440 | }); | 441 | }); |
| ... | @@ -4951,6 +4952,47 @@ test "std.zon variants" { | ... | @@ -4951,6 +4952,47 @@ test "std.zon variants" { |
| 4951 | } | 4952 | } |
| 4952 | } | 4953 | } |
| 4953 | | 4954 | |
| | 4955 | test "std.zon parse specific node with zoir" { |
| | 4956 | const gpa = std.testing.allocator; |
| | 4957 | var arena_allocator: ArenaAllocator = .init(gpa); |
| | 4958 | defer arena_allocator.deinit(); |
| | 4959 | const arena = arena_allocator.allocator(); |
| | 4960 | var diagnostics: Diagnostics = undefined; |
| | 4961 | |
| | 4962 | var ast = try std.zig.Ast.parse(gpa, ".{ .x = 1.5, .y = 2.5 }", .{ .mode = .zon }); |
| | 4963 | defer ast.deinit(gpa); |
| | 4964 | |
| | 4965 | var zoir = try ZonGen.generate(gpa, ast, .{ .parse_str_lits = false }); |
| | 4966 | defer zoir.deinit(gpa); |
| | 4967 | |
| | 4968 | const root_node: std.zig.Zoir.Node = std.zig.Zoir.Node.Index.get(.root, &zoir); |
| | 4969 | |
| | 4970 | try std.testing.expect(root_node == .struct_literal); |
| | 4971 | try std.testing.expectEqual(2, root_node.struct_literal.vals.len); |
| | 4972 | |
| | 4973 | const x_node = root_node.struct_literal.vals.at(0); |
| | 4974 | const x_result = try fromZoirNoAlloc(f32, .{ |
| | 4975 | .arena = arena, |
| | 4976 | .ast = &ast, |
| | 4977 | .zoir = &zoir, |
| | 4978 | .node = x_node, |
| | 4979 | .diagnostics = &diagnostics, |
| | 4980 | }); |
| | 4981 | |
| | 4982 | try std.testing.expectApproxEqAbs(x_result, 1.5, 0.1); |
| | 4983 | |
| | 4984 | const y_node = root_node.struct_literal.vals.at(1); |
| | 4985 | const y_result = try fromZoirNoAlloc(f32, .{ |
| | 4986 | .arena = arena, |
| | 4987 | .ast = &ast, |
| | 4988 | .zoir = &zoir, |
| | 4989 | .node = y_node, |
| | 4990 | .diagnostics = &diagnostics, |
| | 4991 | }); |
| | 4992 | |
| | 4993 | try std.testing.expectApproxEqAbs(y_result, 2.5, 0.1); |
| | 4994 | } |
| | 4995 | |
| 4954 | test { | 4996 | test { |
| 4955 | _ = Diagnostics; | 4997 | _ = Diagnostics; |
| 4956 | } | 4998 | } |