added uinteger tag to Object
This commit is contained in:
parent
0275d67669
commit
113f49f6a4
5 changed files with 66 additions and 40 deletions
|
|
@ -13,26 +13,30 @@ fn test_int(bytes: []const u8, expected: i64) !void {
|
|||
try std.testing.expectEqual(expected, obj.integer);
|
||||
}
|
||||
|
||||
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{0x7f}, std.math.maxInt(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{ 0xcd, 0x7f, 0xff }, std.math.maxInt(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{ 0xce, 0x7f, 0xff, 0xff, 0xff }, std.math.maxInt(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{ 0xcf, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, std.math.maxInt(i64));
|
||||
try test_int(&[_]u8{ 0xd3, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, std.math.maxInt(i64));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ const std = @import("std");
|
|||
pub const binary = @import("binary.zig");
|
||||
pub const string = @import("string.zig");
|
||||
pub const int = @import("int.zig");
|
||||
pub const uint = @import("uint.zig");
|
||||
|
||||
pub const msgpack = @import("msgpack");
|
||||
|
||||
|
|
|
|||
46
tests/deserialise/uint.zig
Normal file
46
tests/deserialise/uint.zig
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub const msgpack = @import("msgpack");
|
||||
|
||||
const deserialise = msgpack.deserialise.deserialise;
|
||||
|
||||
fn test_uint(bytes: []const u8, expected: u64) !void {
|
||||
const alloc = std.testing.allocator;
|
||||
|
||||
const obj = try deserialise(alloc, bytes);
|
||||
defer obj.deinit(alloc);
|
||||
|
||||
try std.testing.expectEqual(expected, obj.uinteger);
|
||||
}
|
||||
|
||||
test "pos fixint" {
|
||||
try test_uint(&[_]u8{0x00}, std.math.minInt(u8));
|
||||
|
||||
try test_uint(&[_]u8{0x07}, 0x07);
|
||||
|
||||
try test_uint(&[_]u8{0x7F}, 0x7F);
|
||||
}
|
||||
|
||||
test "int u8" {
|
||||
try test_uint(&[_]u8{ 0xcc, 0x00 }, std.math.minInt(u8));
|
||||
|
||||
try test_uint(&[_]u8{ 0xcc, 0xff }, std.math.maxInt(u8));
|
||||
}
|
||||
|
||||
test "int u16" {
|
||||
try test_uint(&[_]u8{ 0xcd, 0x00, 0x00 }, std.math.minInt(u16));
|
||||
|
||||
try test_uint(&[_]u8{ 0xcd, 0xff, 0xff }, std.math.maxInt(u16));
|
||||
}
|
||||
|
||||
test "int u32" {
|
||||
try test_uint(&[_]u8{ 0xce, 0x00, 0x00, 0x00, 0x00 }, std.math.minInt(u32));
|
||||
|
||||
try test_uint(&[_]u8{ 0xce, 0xff, 0xff, 0xff, 0xff }, std.math.maxInt(u32));
|
||||
}
|
||||
|
||||
test "int u64" {
|
||||
try test_uint(&[_]u8{ 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, std.math.minInt(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