authorgravatar for tgschultz@gmail.comtgschultz <tgschultz@gmail.com> 2018-05-30 12:18:24-05:00
committergravatar for tgschultz@gmail.comtgschultz <tgschultz@gmail.com> 2018-05-30 12:18:24-05:00
logfb001f5e903ddf3774a673af0923841a57197a17
tree9725f81eb15557db5a3e18c8704a0d51fad2c996
parent8938c16f38866a7149c32463dea44f884b265643

Fixed character handling


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

std/fmt/index.zig+7-5
......@@ -227,7 +227,7 @@ pub fn formatIntValue(value: var, comptime fmt: []const u8, context: var, compti
227227 'c' => {
228228 if(@typeOf(value) == u8) {
229229 if(fmt.len > 1) @compileError("Unknown format character: " ++ []u8{fmt[1]});
230 return formatAsciiChar(fmt[0], context, Errors, output);
230 return formatAsciiChar(value, context, Errors, output);
231231 }
232232 },
233233 'd' => {
......@@ -810,6 +810,10 @@ test "fmt.format" {
810810 const value: u3 = 0b101;
811811 try testFmt("u3: 5\n", "u3: {}\n", value);
812812 }
813 {
814 const value: u8 = 'a';
815 try testFmt("u8: a\n", "u8: {c}\n", value);
816 }
813817 try testFmt("file size: 63MiB\n", "file size: {Bi}\n", usize(63 * 1024 * 1024));
814818 try testFmt("file size: 66.06MB\n", "file size: {B2}\n", usize(63 * 1024 * 1024));
815819 {
......@@ -1054,10 +1058,8 @@ test "fmt.format" {
10541058
10551059 var buf1: [32]u8 = undefined;
10561060 var value = Vec2{.x = 10.2, .y = 2.22,};
1057 const point_result = try bufPrint(buf1[0..], "point: {}\n", &value);
1058 assert(mem.eql(u8, point_result, "point: (10.200,2.220)\n"));
1059 const dim_result = try bufPrint(buf1[0..], "dim: {d}\n", &value);
1060 assert(mem.eql(u8, dim_result, "dim: 10.200x2.220\n"));
1061 try testFmt("point: (10.200,2.220)\n", "point: {}\n", &value);
1062 try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", &value);
10611063 }
10621064}
10631065