authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-07 23:25:02-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-07 23:25:02-04:00
log8abcd94eceef08402f86c774c0f484cb51c6905a
tree7a14224995e21d9db00731c778a6ccc9ef8e7413
parent5774b48ceb7cdca7fbf3dd19fff4a0e42228473f

std.fmt.format prints bool values


1 files changed, 5 insertions(+), 3 deletions(-)

std/fmt.zig+5-3
...@@ -183,6 +183,8 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons...@@ -183,6 +183,8 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons
183 return output(context, casted_value);183 return output(context, casted_value);
184 } else if (T == void) {184 } else if (T == void) {
185 return output(context, "void");185 return output(context, "void");
186 } else if (T == bool) {
187 return output(context, if (value) "true" else "false");
186 } else {188 } else {
187 @compileError("Unable to format type '" ++ @typeName(T) ++ "'");189 @compileError("Unable to format type '" ++ @typeName(T) ++ "'");
188 }190 }
...@@ -363,7 +365,7 @@ fn countSize(size: &usize, bytes: []const u8) -> bool {...@@ -363,7 +365,7 @@ fn countSize(size: &usize, bytes: []const u8) -> bool {
363 return true;365 return true;
364}366}
365367
366test "testBufPrintInt" {368test "buf print int" {
367 var buffer: [max_int_digits]u8 = undefined;369 var buffer: [max_int_digits]u8 = undefined;
368 const buf = buffer[0...];370 const buf = buffer[0...];
369 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, 0), "-101111000110000101001110"));371 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, 0), "-101111000110000101001110"));
...@@ -385,7 +387,7 @@ fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: u...@@ -385,7 +387,7 @@ fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: u
385 return buf[0...formatIntBuf(buf, value, base, uppercase, width)];387 return buf[0...formatIntBuf(buf, value, base, uppercase, width)];
386}388}
387389
388test "testParseU64DigitTooBig" {390test "parse u64 digit too big" {
389 _ = parseUnsigned(u64, "123a", 10) %% |err| {391 _ = parseUnsigned(u64, "123a", 10) %% |err| {
390 if (err == error.InvalidChar) return;392 if (err == error.InvalidChar) return;
391 unreachable;393 unreachable;
...@@ -393,7 +395,7 @@ test "testParseU64DigitTooBig" {...@@ -393,7 +395,7 @@ test "testParseU64DigitTooBig" {
393 unreachable;395 unreachable;
394}396}
395397
396test "testParseUnsignedComptime" {398test "parse unsigned comptime" {
397 comptime {399 comptime {
398 assert(%%parseUnsigned(usize, "2", 10) == 2);400 assert(%%parseUnsigned(usize, "2", 10) == 2);
399 }401 }