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
84
tests/deserialise/string.zig
Normal file
84
tests/deserialise/string.zig
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
const std = @import("std");
|
||||
|
||||
const msgpack = @import("msgpack");
|
||||
|
||||
const deserialise = msgpack.deserialise.deserialise;
|
||||
|
||||
fn test_string(bytes: []const u8, expected: []const u8) !void {
|
||||
const alloc = std.testing.allocator;
|
||||
|
||||
const obj = try deserialise(alloc, bytes);
|
||||
defer obj.deinit(alloc);
|
||||
|
||||
try std.testing.expectEqualStrings(expected, obj.raw.string);
|
||||
}
|
||||
|
||||
test "string 1" {
|
||||
const bytes = [_]u8{ 0b101_00000 | 0x03, 'A', 'B', 'C' };
|
||||
|
||||
try test_string(&bytes, "ABC");
|
||||
}
|
||||
|
||||
test "string 2" {
|
||||
const bytes = [_]u8{ 0xd9, 0x03, 'A', 'B', 'C' };
|
||||
|
||||
try test_string(&bytes, "ABC");
|
||||
}
|
||||
test "string 3" {
|
||||
const bytes = [_]u8{ 0xd9, 0x00 };
|
||||
|
||||
try test_string(&bytes, "");
|
||||
}
|
||||
test "string 4" {
|
||||
var bytes: [2 + 255]u8 = undefined;
|
||||
|
||||
bytes[0] = 0xd9;
|
||||
bytes[1] = 0xff;
|
||||
|
||||
for (bytes[2..]) |*c| {
|
||||
c.* = 'A';
|
||||
}
|
||||
|
||||
try test_string(&bytes, "A" ** 255);
|
||||
}
|
||||
test "string 5" {
|
||||
var bytes: [3 + 256]u8 = undefined;
|
||||
|
||||
bytes[0] = 0xda;
|
||||
bytes[1] = 0x01;
|
||||
bytes[2] = 0x00;
|
||||
|
||||
for (bytes[3..]) |*c| {
|
||||
c.* = 'A';
|
||||
}
|
||||
|
||||
try test_string(&bytes, "A" ** 256);
|
||||
}
|
||||
test "string 6" {
|
||||
var bytes: [3 + 65535]u8 = undefined;
|
||||
|
||||
bytes[0] = 0xda;
|
||||
bytes[1] = 0xff;
|
||||
bytes[2] = 0xff;
|
||||
|
||||
for (bytes[3..]) |*c| {
|
||||
c.* = 'A';
|
||||
}
|
||||
|
||||
try test_string(&bytes, "A" ** 65535);
|
||||
}
|
||||
test "string 7" {
|
||||
var bytes: [5 + 65536]u8 = undefined;
|
||||
|
||||
bytes[0] = 0xdb;
|
||||
bytes[1] = 0x00;
|
||||
bytes[2] = 0x01;
|
||||
bytes[3] = 0x00;
|
||||
bytes[4] = 0x00;
|
||||
|
||||
for (bytes[5..]) |*c| {
|
||||
c.* = 'A';
|
||||
}
|
||||
|
||||
try test_string(&bytes, "A" ** 65536);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue