multitype 0.21.1

Arithmetic type traits.
Documentation
// Copyright 2025-2026 Gabriel Bjørnager Jensen.
//
// SPDX: MIT OR Apache-2.0

#![cfg(test)]

use multitype::{Signed, Unsigned};

#[cfg(feature = "std")]
use std::panic::catch_unwind;

#[test]
fn test_cast_unsigned() {
	fn test<T: Signed<Unsigned: Default>>() {
		let _: T = T::Unsigned::default().cast_signed();
	}

	test::<i8>();
	test::<i16>();
	test::<i32>();
	test::<i64>();
	test::<i128>();
	test::<isize>();
}

#[cfg(feature = "std")]
#[test]
fn test_strict_abs() {
	catch_unwind(|| Signed::strict_abs(i8::MIN + 1)).unwrap();
	catch_unwind(|| Signed::strict_abs(i16::MIN + 1)).unwrap();
	catch_unwind(|| Signed::strict_abs(i32::MIN + 1)).unwrap();
	catch_unwind(|| Signed::strict_abs(i64::MIN + 1)).unwrap();
	catch_unwind(|| Signed::strict_abs(i128::MIN + 1)).unwrap();
	catch_unwind(|| Signed::strict_abs(isize::MIN + 1)).unwrap();

	catch_unwind(|| Signed::strict_abs(i8::MIN)).unwrap_err();
	catch_unwind(|| Signed::strict_abs(i16::MIN)).unwrap_err();
	catch_unwind(|| Signed::strict_abs(i32::MIN)).unwrap_err();
	catch_unwind(|| Signed::strict_abs(i64::MIN)).unwrap_err();
	catch_unwind(|| Signed::strict_abs(i128::MIN)).unwrap_err();
	catch_unwind(|| Signed::strict_abs(isize::MIN)).unwrap_err();
}