~sircmpwn/hare-message

06505fc6c725cc11c79b3e4495768de4072b49cc — Drew DeVault 5 months ago 2aefb0c
Add round-trip test
1 files changed, 22 insertions(+), 0 deletions(-)

M message/header.ha
M message/header.ha => message/header.ha +22 -0
@@ 433,6 433,28 @@ export fn write_header(sink: io::handle, head: *header) (size | io::error) = {
	assert(result == expect);
};

@test fn roundtrip() void = {
	const input =
		"To: Drew DeVault <sir@cmpwn.com>\r\n"
		"From: Harriet <harriet@harelang.org>\r\n"
		"Content-Type: text/plain\r\n"
		"DKIM-Signature: a=rsa-sha256;\r\n"
		" bh=uI/rVH7mLBSWkJVvQYKz3TbpdI2BLZWTIMKcuo0KHOI=; c=simple/simple;\r\n"
		" d=example.org; h=Subject:To:From; s=default; t=1577562184; v=1; b=;\r\n"
		"\r\n";

	const in = bufio::fixed(strings::toutf8(input), io::mode::READ);
	const head = read_header(&in)!;
	defer header_finish(&head);

	const sink = strio::dynamic();
	defer io::close(&sink)!;

	write_header(&sink, &head)!;

	assert(strio::string(&sink) == input);
};

// Initializes a new header field, duplicating the provided parameters.
fn new_header_field(key: str, val: str, raw: []u8) header_field = {
	return header_field {