fmt: Make default_max_depth configurable

This commit is contained in:
ominitay
2022-07-31 22:58:04 +01:00
committed by Veikka Tuominen
parent 2ccff51154
commit 3c8d968194
2 changed files with 11 additions and 5 deletions

View File

@@ -1,11 +1,12 @@
const std = @import("std.zig");
const builtin = @import("builtin");
const io = std.io;
const math = std.math;
const assert = std.debug.assert;
const mem = std.mem;
const unicode = std.unicode;
const meta = std.meta;
const builtin = @import("builtin");
const errol = @import("fmt/errol.zig");
const lossyCast = std.math.lossyCast;
const expectFmt = std.testing.expectFmt;
@@ -190,7 +191,7 @@ pub fn format(
.precision = precision,
},
writer,
default_max_depth,
std.options.fmt_max_depth,
);
}
@@ -2140,15 +2141,15 @@ test "buffer" {
{
var buf1: [32]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buf1);
try formatType(1234, "", FormatOptions{}, fbs.writer(), default_max_depth);
try formatType(1234, "", FormatOptions{}, fbs.writer(), std.options.fmt_max_depth);
try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1234"));
fbs.reset();
try formatType('a', "c", FormatOptions{}, fbs.writer(), default_max_depth);
try formatType('a', "c", FormatOptions{}, fbs.writer(), std.options.fmt_max_depth);
try std.testing.expect(mem.eql(u8, fbs.getWritten(), "a"));
fbs.reset();
try formatType(0b1100, "b", FormatOptions{}, fbs.writer(), default_max_depth);
try formatType(0b1100, "b", FormatOptions{}, fbs.writer(), std.options.fmt_max_depth);
try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1100"));
}
}

View File

@@ -153,6 +153,11 @@ pub const options = struct {
else
log.defaultLog;
pub const fmt_max_depth = if (@hasDecl(options_override, "fmt_max_depth"))
options_override.fmt_max_depth
else
fmt.default_max_depth;
pub const cryptoRandomSeed: fn (buffer: []u8) void = if (@hasDecl(options_override, "cryptoRandomSeed"))
options_override.cryptoRandomSeed
else