oct 0.25.0

Octonary transcodings.
Documentation
// Copyright 2024-2025 Gabriel Bjørnager Jensen.
//
// This Source Code Form is subject to the terms of
// the Mozilla Public License, v. 2.0. If a copy of
// the MPL was not distributed with this file, you
// can obtain one at:
// <https://mozilla.org/MPL/2.0/>.

#![cfg(test)]

#[cfg(feature = "alloc")]
macro_rules! test {
	{$($Ty:ty { $($lhs:expr => $rhs:expr),+$(,)? }$(,)?)*} => {{
		$($({
			let mut buf = alloc::vec::Vec::new();

			<$Ty as ::oct::io::Serialise>::serialise(&$lhs, &mut buf).unwrap();

			let lhs = &buf;
			let rhs = $rhs;

			::core::assert_eq!(lhs, rhs);
		})*)*
	}};
}

#[cfg(feature = "alloc")]
#[test]
fn test_serialise() {
	test! {
		u8 {
			0x00 => &[0x00],
			0xFF => &[0xFF],
			0x7F => &[0x7F],
		}

		u16 {
			0x0F_7E => &[0x7E, 0x0F],
		}

		u32 {
			0x00_2F_87_E7 => &[0xE7, 0x87, 0x2F, 0x00],
		}

		u64 {
			0xF3_37_CF_8B_DB_03_2B_39 => &[0x39, 0x2B, 0x03, 0xDB, 0x8B, 0xCF, 0x37, 0xF3],
		}

		u128 {
			0x45_A0_15_6A_36_77_17_8A_83_2E_3C_2C_84_10_58_1A => &[
				0x1A, 0x58, 0x10, 0x84, 0x2C, 0x3C, 0x2E, 0x83,
				0x8A, 0x17, 0x77, 0x36, 0x6A, 0x15, 0xA0, 0x45,
			],
		}

		usize {
			0x1A4 => &[0xA4, 0x01],
		}

		[char; 0x5] {
			['\u{03B4}', '\u{0190}', '\u{03BB}', '\u{03A4}', '\u{03B1}'] => &[
				0xB4, 0x03, 0x00, 0x00, 0x90, 0x01, 0x00, 0x00,
				0xBB, 0x03, 0x00, 0x00, 0xA4, 0x03, 0x00, 0x00,
				0xB1, 0x03, 0x00, 0x00,
			],
		}

		str {
			"A" => &[0x01, 0x00, 0x41],
		}

		str {
			"l\u{00F8}gma\u{00F0}ur" => &[
				0x0A, 0x00, 0x6C, 0xC3, 0xB8, 0x67, 0x6D, 0x61,
				0xC3, 0xB0, 0x75, 0x72,
			],
		}

		Result<u16, char> {
			Ok(0x4545) => &[0x00, 0x45, 0x45],

			Err(char::REPLACEMENT_CHARACTER) => &[0x01, 0xFD, 0xFF, 0x00, 0x00],
		}

		Option<()> {
			None => &[0x00],

			Some(()) => &[0x01],
		}
	}
}