serialiser
This commit is contained in:
parent
113f49f6a4
commit
e1f1084a39
14 changed files with 698 additions and 51 deletions
|
|
@ -2,7 +2,7 @@ const std = @import("std");
|
|||
|
||||
const msgpack = @import("msgpack");
|
||||
|
||||
const deserialise = msgpack.deserialise.deserialise;
|
||||
const deserialise = msgpack.deserialise;
|
||||
|
||||
fn test_string(bytes: []const u8, expected: []const u8) !void {
|
||||
const alloc = std.testing.allocator;
|
||||
|
|
@ -10,26 +10,26 @@ fn test_string(bytes: []const u8, expected: []const u8) !void {
|
|||
const obj = try deserialise(alloc, bytes);
|
||||
defer obj.deinit(alloc);
|
||||
|
||||
try std.testing.expectEqualStrings(expected, obj.raw.string);
|
||||
try std.testing.expectEqualStrings(expected, obj.string);
|
||||
}
|
||||
|
||||
test "string 1" {
|
||||
test "fixstr 1" {
|
||||
const bytes = [_]u8{ 0b101_00000 | 0x03, 'A', 'B', 'C' };
|
||||
|
||||
try test_string(&bytes, "ABC");
|
||||
}
|
||||
|
||||
test "string 2" {
|
||||
test "str8 1" {
|
||||
const bytes = [_]u8{ 0xd9, 0x03, 'A', 'B', 'C' };
|
||||
|
||||
try test_string(&bytes, "ABC");
|
||||
}
|
||||
test "string 3" {
|
||||
test "empty string" {
|
||||
const bytes = [_]u8{ 0xd9, 0x00 };
|
||||
|
||||
try test_string(&bytes, "");
|
||||
}
|
||||
test "string 4" {
|
||||
test "str8 2" {
|
||||
var bytes: [2 + 255]u8 = undefined;
|
||||
|
||||
bytes[0] = 0xd9;
|
||||
|
|
@ -41,7 +41,7 @@ test "string 4" {
|
|||
|
||||
try test_string(&bytes, "A" ** 255);
|
||||
}
|
||||
test "string 5" {
|
||||
test "str16 1" {
|
||||
var bytes: [3 + 256]u8 = undefined;
|
||||
|
||||
bytes[0] = 0xda;
|
||||
|
|
@ -54,7 +54,7 @@ test "string 5" {
|
|||
|
||||
try test_string(&bytes, "A" ** 256);
|
||||
}
|
||||
test "string 6" {
|
||||
test "str16 2" {
|
||||
var bytes: [3 + 65535]u8 = undefined;
|
||||
|
||||
bytes[0] = 0xda;
|
||||
|
|
@ -67,7 +67,7 @@ test "string 6" {
|
|||
|
||||
try test_string(&bytes, "A" ** 65535);
|
||||
}
|
||||
test "string 7" {
|
||||
test "str32 1" {
|
||||
var bytes: [5 + 65536]u8 = undefined;
|
||||
|
||||
bytes[0] = 0xdb;
|
||||
|
|
@ -82,3 +82,6 @@ test "string 7" {
|
|||
|
||||
try test_string(&bytes, "A" ** 65536);
|
||||
}
|
||||
test "fixstr 2" {
|
||||
try test_string(&[_]u8{ 0xaa, 0x6c, 0x65, 0x20, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65 }, "le message");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue