added deserialiser tests, fixed some bugs in deserialised
This commit is contained in:
parent
f454526c5a
commit
0275d67669
8 changed files with 267 additions and 93 deletions
38
tests/deserialise/int.zig
Normal file
38
tests/deserialise/int.zig
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub const msgpack = @import("msgpack");
|
||||
|
||||
const deserialise = msgpack.deserialise.deserialise;
|
||||
|
||||
fn test_int(bytes: []const u8, expected: i64) !void {
|
||||
const alloc = std.testing.allocator;
|
||||
|
||||
const obj = try deserialise(alloc, bytes);
|
||||
defer obj.deinit(alloc);
|
||||
|
||||
try std.testing.expectEqual(expected, obj.integer);
|
||||
}
|
||||
|
||||
test "int i8" {
|
||||
try test_int(&[_]u8{ 0xd0, 0x80 }, std.math.minInt(i8));
|
||||
|
||||
try test_int(&[_]u8{0x7f}, std.math.maxInt(i8));
|
||||
}
|
||||
|
||||
test "int i16" {
|
||||
try test_int(&[_]u8{ 0xd1, 0x80, 0x00 }, std.math.minInt(i16));
|
||||
|
||||
try test_int(&[_]u8{ 0xcd, 0x7f, 0xff }, std.math.maxInt(i16));
|
||||
}
|
||||
|
||||
test "int i32" {
|
||||
try test_int(&[_]u8{ 0xd2, 0x80, 0x00, 0x00, 0x00 }, std.math.minInt(i32));
|
||||
|
||||
try test_int(&[_]u8{ 0xce, 0x7f, 0xff, 0xff, 0xff }, std.math.maxInt(i32));
|
||||
}
|
||||
|
||||
test "int i64" {
|
||||
try test_int(&[_]u8{ 0xd3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, std.math.minInt(i64));
|
||||
|
||||
try test_int(&[_]u8{ 0xcf, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, std.math.maxInt(i64));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue