| ... | ... | @@ -34,8 +34,7 @@ test "write a file, read it, then delete it" { |
| 34 | 34 | // make sure openWriteNoClobber doesn't harm the file |
| 35 | 35 | if (os.File.openWriteNoClobber(tmp_file_name, os.File.default_mode)) |file| { |
| 36 | 36 | unreachable; |
| 37 | | } |
| 38 | | else |err| { |
| 37 | } else |err| { |
| 39 | 38 | std.debug.assert(err == os.File.OpenError.PathAlreadyExists); |
| 40 | 39 | } |
| 41 | 40 | } |
| ... | ... | @@ -180,7 +179,7 @@ test "BitInStream" { |
| 180 | 179 | expect(out_bits == 16); |
| 181 | 180 | |
| 182 | 181 | _ = try bit_stream_be.readBits(u0, 0, &out_bits); |
| 183 | | |
| 182 | |
| 184 | 183 | expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits)); |
| 185 | 184 | expect(out_bits == 0); |
| 186 | 185 | expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1)); |
| ... | ... | @@ -212,7 +211,7 @@ test "BitInStream" { |
| 212 | 211 | expect(out_bits == 16); |
| 213 | 212 | |
| 214 | 213 | _ = try bit_stream_le.readBits(u0, 0, &out_bits); |
| 215 | | |
| 214 | |
| 216 | 215 | expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits)); |
| 217 | 216 | expect(out_bits == 0); |
| 218 | 217 | expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1)); |
| ... | ... | @@ -281,7 +280,7 @@ test "BitStreams with File Stream" { |
| 281 | 280 | var file_out_stream = &file_out.stream; |
| 282 | 281 | const OutError = os.File.WriteError; |
| 283 | 282 | var bit_stream = io.BitOutStream(builtin.endian, OutError).init(file_out_stream); |
| 284 | | |
| 283 | |
| 285 | 284 | try bit_stream.writeBits(u2(1), 1); |
| 286 | 285 | try bit_stream.writeBits(u5(2), 2); |
| 287 | 286 | try bit_stream.writeBits(u128(3), 3); |
| ... | ... | @@ -298,7 +297,7 @@ test "BitStreams with File Stream" { |
| 298 | 297 | var file_in_stream = &file_in.stream; |
| 299 | 298 | const InError = os.File.ReadError; |
| 300 | 299 | var bit_stream = io.BitInStream(builtin.endian, InError).init(file_in_stream); |
| 301 | | |
| 300 | |
| 302 | 301 | var out_bits: usize = undefined; |
| 303 | 302 | |
| 304 | 303 | expect(1 == try bit_stream.readBits(u2, 1, &out_bits)); |
| ... | ... | @@ -313,7 +312,7 @@ test "BitStreams with File Stream" { |
| 313 | 312 | expect(out_bits == 5); |
| 314 | 313 | expect(1 == try bit_stream.readBits(u1, 1, &out_bits)); |
| 315 | 314 | expect(out_bits == 1); |
| 316 | | |
| 315 | |
| 317 | 316 | expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1)); |
| 318 | 317 | } |
| 319 | 318 | try os.deleteFile(tmp_file_name); |
| ... | ... | @@ -322,14 +321,14 @@ test "BitStreams with File Stream" { |
| 322 | 321 | fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime is_packed: bool) !void { |
| 323 | 322 | //@NOTE: if this test is taking too long, reduce the maximum tested bitsize |
| 324 | 323 | const max_test_bitsize = 128; |
| 325 | | |
| 324 | |
| 326 | 325 | const total_bytes = comptime blk: { |
| 327 | 326 | var bytes = 0; |
| 328 | 327 | comptime var i = 0; |
| 329 | 328 | while (i <= max_test_bitsize) : (i += 1) bytes += (i / 8) + @boolToInt(i % 8 > 0); |
| 330 | 329 | break :blk bytes * 2; |
| 331 | 330 | }; |
| 332 | | |
| 331 | |
| 333 | 332 | var data_mem: [total_bytes]u8 = undefined; |
| 334 | 333 | var out = io.SliceOutStream.init(data_mem[0..]); |
| 335 | 334 | const OutError = io.SliceOutStream.Error; |
| ... | ... | @@ -382,16 +381,19 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime is_pa |
| 382 | 381 | test "Serializer/Deserializer Int" { |
| 383 | 382 | try testIntSerializerDeserializer(builtin.Endian.Big, false); |
| 384 | 383 | try testIntSerializerDeserializer(builtin.Endian.Little, false); |
| 385 | | try testIntSerializerDeserializer(builtin.Endian.Big, true); |
| 386 | | try testIntSerializerDeserializer(builtin.Endian.Little, true); |
| 384 | // TODO these tests are disabled due to tripping an LLVM assertion |
| 385 | // https://github.com/ziglang/zig/issues/2019 |
| 386 | //try testIntSerializerDeserializer(builtin.Endian.Big, true); |
| 387 | //try testIntSerializerDeserializer(builtin.Endian.Little, true); |
| 387 | 388 | } |
| 388 | 389 | |
| 389 | | fn testIntSerializerDeserializerInfNaN(comptime endian: builtin.Endian, |
| 390 | | comptime is_packed: bool) !void |
| 391 | | { |
| 392 | | const mem_size = (16*2 + 32*2 + 64*2 + 128*2) / comptime meta.bitCount(u8); |
| 390 | fn testIntSerializerDeserializerInfNaN( |
| 391 | comptime endian: builtin.Endian, |
| 392 | comptime is_packed: bool, |
| 393 | ) !void { |
| 394 | const mem_size = (16 * 2 + 32 * 2 + 64 * 2 + 128 * 2) / comptime meta.bitCount(u8); |
| 393 | 395 | var data_mem: [mem_size]u8 = undefined; |
| 394 | | |
| 396 | |
| 395 | 397 | var out = io.SliceOutStream.init(data_mem[0..]); |
| 396 | 398 | const OutError = io.SliceOutStream.Error; |
| 397 | 399 | var out_stream = &out.stream; |
| ... | ... | @@ -472,8 +474,6 @@ fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime is_packe |
| 472 | 474 | f_u2: u2, |
| 473 | 475 | }; |
| 474 | 476 | |
| 475 | | |
| 476 | | |
| 477 | 477 | //to test custom serialization |
| 478 | 478 | const Custom = struct { |
| 479 | 479 | f_f16: f16, |