From 87726882dd5c7e64aefa9599f944afdda0585ede Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Fri, 16 Jul 2021 14:21:31 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20add=20test=20cases=20for=20new=20`e?= =?UTF-8?q?ntity=5Fimpl!`=20form?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cranelift/entity/src/lib.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cranelift/entity/src/lib.rs b/cranelift/entity/src/lib.rs index 2665a1ce25..8cddb830dd 100644 --- a/cranelift/entity/src/lib.rs +++ b/cranelift/entity/src/lib.rs @@ -280,4 +280,35 @@ mod tests { assert_eq!(alloc::format!("{}", e), "prefix-0"); } } + + /// Test cases for an `EntityRef` implementation for a type we can only construct through + /// other means, such as calls to `core::convert::From`. + mod other_entity { + mod inner { + #[derive(Clone, Copy, PartialEq, Eq)] + pub struct InnerEntity(u32); + + impl From for InnerEntity { + fn from(x: u32) -> Self { + Self(x) + } + } + + impl From for u32 { + fn from(x: InnerEntity) -> Self { + x.0 + } + } + } + + use {crate::EntityRef, self::inner::InnerEntity}; + entity_impl!(InnerEntity, "inner-", i, InnerEntity::from(i), u32::from(i)); + entity_test!(InnerEntity); + + #[test] + fn display_prefix_works() { + let e = InnerEntity::new(0); + assert_eq!(alloc::format!("{}", e), "inner-0"); + } + } }