| ... | @@ -436,6 +436,7 @@ fn fromZoirInner( | ... | @@ -436,6 +436,7 @@ fn fromZoirInner( |
| 436 | .arena = options.arena, | 436 | .arena = options.arena, |
| 437 | .ast = options.ast, | 437 | .ast = options.ast, |
| 438 | .zoir = options.zoir, | 438 | .zoir = options.zoir, |
| | 439 | .node = options.node, |
| 439 | .errors = &errors, | 440 | .errors = &errors, |
| 440 | .ignore_unknown_fields = options.ignore_unknown_fields, | 441 | .ignore_unknown_fields = options.ignore_unknown_fields, |
| 441 | }); | 442 | }); |
| ... | @@ -4854,6 +4855,47 @@ test "std.zon variants" { | ... | @@ -4854,6 +4855,47 @@ test "std.zon variants" { |
| 4854 | } | 4855 | } |
| 4855 | } | 4856 | } |
| 4856 | | 4857 | |
| | 4858 | test "std.zon parse specific node with zoir" { |
| | 4859 | const gpa = std.testing.allocator; |
| | 4860 | var arena_allocator: ArenaAllocator = .init(gpa); |
| | 4861 | defer arena_allocator.deinit(); |
| | 4862 | const arena = arena_allocator.allocator(); |
| | 4863 | var diagnostics: Diagnostics = undefined; |
| | 4864 | |
| | 4865 | var ast = try std.zig.Ast.parse(gpa, ".{ .x = 1.5, .y = 2.5 }", .{ .mode = .zon }); |
| | 4866 | defer ast.deinit(gpa); |
| | 4867 | |
| | 4868 | var zoir = try ZonGen.generate(gpa, ast, .{ .parse_str_lits = false }); |
| | 4869 | defer zoir.deinit(gpa); |
| | 4870 | |
| | 4871 | const root_node: std.zig.Zoir.Node = std.zig.Zoir.Node.Index.get(.root, &zoir); |
| | 4872 | |
| | 4873 | try std.testing.expect(root_node == .struct_literal); |
| | 4874 | try std.testing.expectEqual(2, root_node.struct_literal.vals.len); |
| | 4875 | |
| | 4876 | const x_node = root_node.struct_literal.vals.at(0); |
| | 4877 | const x_result = try fromZoirNoAlloc(f32, .{ |
| | 4878 | .arena = arena, |
| | 4879 | .ast = &ast, |
| | 4880 | .zoir = &zoir, |
| | 4881 | .node = x_node, |
| | 4882 | .diagnostics = &diagnostics, |
| | 4883 | }); |
| | 4884 | |
| | 4885 | try std.testing.expectApproxEqAbs(x_result, 1.5, 0.1); |
| | 4886 | |
| | 4887 | const y_node = root_node.struct_literal.vals.at(1); |
| | 4888 | const y_result = try fromZoirNoAlloc(f32, .{ |
| | 4889 | .arena = arena, |
| | 4890 | .ast = &ast, |
| | 4891 | .zoir = &zoir, |
| | 4892 | .node = y_node, |
| | 4893 | .diagnostics = &diagnostics, |
| | 4894 | }); |
| | 4895 | |
| | 4896 | try std.testing.expectApproxEqAbs(y_result, 2.5, 0.1); |
| | 4897 | } |
| | 4898 | |
| 4857 | test { | 4899 | test { |
| 4858 | _ = Diagnostics; | 4900 | _ = Diagnostics; |
| 4859 | } | 4901 | } |