authorgravatar for johnny5jg5@gmail.comthejohnny5 <johnny5jg5@gmail.com> 2025-01-01 12:02:32-05:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-01-26 18:53:11+01:00
log5b3eaff80d5d5254676877436df08829dbc7186b
treea1e2e2c52906d5c3a7ce28f83311242d2e8297ad
parent24965af2950941969681a1eb5e1be27390083ba8

std: check max depth for vector type in formatType


1 files changed, 12 insertions(+), 0 deletions(-)

lib/std/fmt.zig+12
...@@ -679,6 +679,9 @@ pub fn formatType(...@@ -679,6 +679,9 @@ pub fn formatType(
679 try writer.writeAll(" }");679 try writer.writeAll(" }");
680 },680 },
681 .vector => |info| {681 .vector => |info| {
682 if (max_depth == 0) {
683 return writer.writeAll("{ ... }");
684 }
682 try writer.writeAll("{ ");685 try writer.writeAll("{ ");
683 var i: usize = 0;686 var i: usize = 0;
684 while (i < info.len) : (i += 1) {687 while (i < info.len) : (i += 1) {
...@@ -2577,6 +2580,15 @@ test "formatType max_depth" {...@@ -2577,6 +2580,15 @@ test "formatType max_depth" {
2577 fbs.reset();2580 fbs.reset();
2578 try formatType(inst, "", FormatOptions{}, fbs.writer(), 3);2581 try formatType(inst, "", FormatOptions{}, fbs.writer(), 3);
2579 try std.testing.expectEqualStrings("fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ ... }, .tu = fmt.test.formatType max_depth.TU{ ... }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }, .tu = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ ... } }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }, .tu = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ ... } } }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }", fbs.getWritten());2582 try std.testing.expectEqualStrings("fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ ... }, .tu = fmt.test.formatType max_depth.TU{ ... }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }, .tu = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ ... } }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }, .tu = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ ... } } }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }", fbs.getWritten());
2583
2584 const vec: @Vector(4, i32) = .{ 1, 2, 3, 4 };
2585 fbs.reset();
2586 try formatType(vec, "", FormatOptions{}, fbs.writer(), 0);
2587 try std.testing.expectEqualStrings("{ ... }", fbs.getWritten());
2588
2589 fbs.reset();
2590 try formatType(vec, "", FormatOptions{}, fbs.writer(), 1);
2591 try std.testing.expectEqualStrings("{ 1, 2, 3, 4 }", fbs.getWritten());
2580}2592}
25812593
2582test "positional" {2594test "positional" {