serialiser
This commit is contained in:
parent
113f49f6a4
commit
e1f1084a39
14 changed files with 698 additions and 51 deletions
43
tests/serialise/int.zig
Normal file
43
tests/serialise/int.zig
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
const std = @import("std");
|
||||
|
||||
const msgpack = @import("msgpack");
|
||||
|
||||
const Object = msgpack.Object;
|
||||
const serialise = msgpack.serialise;
|
||||
|
||||
fn test_int(expected: []const u8, i: i64) !void {
|
||||
const alloc = std.testing.allocator;
|
||||
|
||||
const bytes = try serialise(alloc, .{ .integer = i });
|
||||
defer alloc.free(bytes);
|
||||
|
||||
try std.testing.expectEqualSlices(u8, expected, bytes);
|
||||
}
|
||||
|
||||
test "neg fixint" {
|
||||
try test_int(&[_]u8{0xFF}, -1);
|
||||
}
|
||||
|
||||
test "int i8" {
|
||||
try test_int(&[_]u8{ 0xd0, 0x80 }, std.math.minInt(i8));
|
||||
|
||||
try test_int(&[_]u8{ 0xd0, 0x7F }, std.math.maxInt(i8));
|
||||
}
|
||||
|
||||
test "int i16" {
|
||||
try test_int(&[_]u8{ 0xd1, 0x80, 0x00 }, std.math.minInt(i16));
|
||||
|
||||
try test_int(&[_]u8{ 0xd1, 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{ 0xd2, 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{ 0xd3, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, std.math.maxInt(i64));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue