authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-03-10 23:50:04+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-03-10 23:50:04+01:00
log2f1052a313cb09f87f04cef56805c33be62eb169
tree53b8b7843c9af6af01ed2424d307c49cdfd0fa59
parent4ab13a359dfb14c93869e7f88320ec2aa438da9c

std: Fix broken tests


2 files changed, 15 insertions(+), 3 deletions(-)

lib/std/io.zig+8-2
...@@ -350,12 +350,18 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {...@@ -350,12 +350,18 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
350 switch (endian) {350 switch (endian) {
351 .Big => {351 .Big => {
352 out_buffer = @as(Buf, self.bit_buffer >> shift);352 out_buffer = @as(Buf, self.bit_buffer >> shift);
353 self.bit_buffer <<= n;353 if (n >= u7_bit_count)
354 self.bit_buffer = 0
355 else
356 self.bit_buffer <<= n;
354 },357 },
355 .Little => {358 .Little => {
356 const value = (self.bit_buffer << shift) >> shift;359 const value = (self.bit_buffer << shift) >> shift;
357 out_buffer = @as(Buf, value);360 out_buffer = @as(Buf, value);
358 self.bit_buffer >>= n;361 if (n >= u7_bit_count)
362 self.bit_buffer = 0
363 else
364 self.bit_buffer >>= n;
359 },365 },
360 }366 }
361 self.bit_count -= n;367 self.bit_count -= n;
lib/std/mem.zig+7-1
...@@ -921,6 +921,9 @@ pub fn writeInt(comptime T: type, buffer: *[@divExact(T.bit_count, 8)]u8, value:...@@ -921,6 +921,9 @@ pub fn writeInt(comptime T: type, buffer: *[@divExact(T.bit_count, 8)]u8, value:
921pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {921pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {
922 assert(buffer.len >= @divExact(T.bit_count, 8));922 assert(buffer.len >= @divExact(T.bit_count, 8));
923923
924 if (T.bit_count == 0)
925 return set(u8, buffer, 0);
926
924 // TODO I want to call writeIntLittle here but comptime eval facilities aren't good enough927 // TODO I want to call writeIntLittle here but comptime eval facilities aren't good enough
925 const uint = std.meta.IntType(false, T.bit_count);928 const uint = std.meta.IntType(false, T.bit_count);
926 var bits = @truncate(uint, value);929 var bits = @truncate(uint, value);
...@@ -938,6 +941,9 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {...@@ -938,6 +941,9 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {
938pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {941pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
939 assert(buffer.len >= @divExact(T.bit_count, 8));942 assert(buffer.len >= @divExact(T.bit_count, 8));
940943
944 if (T.bit_count == 0)
945 return set(u8, buffer, 0);
946
941 // TODO I want to call writeIntBig here but comptime eval facilities aren't good enough947 // TODO I want to call writeIntBig here but comptime eval facilities aren't good enough
942 const uint = std.meta.IntType(false, T.bit_count);948 const uint = std.meta.IntType(false, T.bit_count);
943 var bits = @truncate(uint, value);949 var bits = @truncate(uint, value);
...@@ -1807,7 +1813,7 @@ test "sliceAsBytes" {...@@ -1807,7 +1813,7 @@ test "sliceAsBytes" {
1807}1813}
18081814
1809test "sliceAsBytes with sentinel slice" {1815test "sliceAsBytes with sentinel slice" {
1810 const empty_string:[:0]const u8 = "";1816 const empty_string: [:0]const u8 = "";
1811 const bytes = sliceAsBytes(empty_string);1817 const bytes = sliceAsBytes(empty_string);
1812 testing.expect(bytes.len == 0);1818 testing.expect(bytes.len == 0);
1813}1819}