serialiser
This commit is contained in:
parent
113f49f6a4
commit
e1f1084a39
14 changed files with 698 additions and 51 deletions
39
tests/serialise/uint.zig
Normal file
39
tests/serialise/uint.zig
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
const std = @import("std");
|
||||
|
||||
const msgpack = @import("msgpack");
|
||||
|
||||
const Object = msgpack.Object;
|
||||
const serialise = msgpack.serialise;
|
||||
|
||||
fn test_uint(expected: []const u8, u: u64) !void {
|
||||
const alloc = std.testing.allocator;
|
||||
|
||||
const bytes = try serialise(alloc, .{ .uinteger = u });
|
||||
defer alloc.free(bytes);
|
||||
|
||||
try std.testing.expectEqualSlices(u8, expected, bytes);
|
||||
}
|
||||
|
||||
test "pos fixint" {
|
||||
try test_uint(&[_]u8{0x00}, 0);
|
||||
|
||||
try test_uint(&[_]u8{0x07}, 0x07);
|
||||
|
||||
try test_uint(&[_]u8{0x7F}, 0x7F);
|
||||
}
|
||||
|
||||
test "int u8" {
|
||||
try test_uint(&[_]u8{ 0xcc, 0xff }, std.math.maxInt(u8));
|
||||
}
|
||||
|
||||
test "int u16" {
|
||||
try test_uint(&[_]u8{ 0xcd, 0xff, 0xff }, std.math.maxInt(u16));
|
||||
}
|
||||
|
||||
test "int u32" {
|
||||
try test_uint(&[_]u8{ 0xce, 0xff, 0xff, 0xff, 0xff }, std.math.maxInt(u32));
|
||||
}
|
||||
|
||||
test "int u64" {
|
||||
try test_uint(&[_]u8{ 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, std.math.maxInt(u64));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue