From 2970041c341ecaa3e8d9996f422a50a8f5bb76be Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Tue, 9 May 2023 15:45:36 +0000 Subject: Initial import Bug: 285067342 Test: m liblinkme Change-Id: I555af1b175a96118ca099f469d7675abf63e8594 --- tests/distributed_slice.rs | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/distributed_slice.rs (limited to 'tests/distributed_slice.rs') diff --git a/tests/distributed_slice.rs b/tests/distributed_slice.rs new file mode 100644 index 0000000..f8ab487 --- /dev/null +++ b/tests/distributed_slice.rs @@ -0,0 +1,72 @@ +#![cfg_attr(feature = "used_linker", feature(used_with_arg))] + +use linkme::distributed_slice; +use once_cell::sync::Lazy; + +#[distributed_slice] +static SHENANIGANS: [i32] = [..]; + +#[distributed_slice(SHENANIGANS)] +static N: i32 = 9; + +#[distributed_slice(SHENANIGANS)] +static NN: i32 = 99; + +#[distributed_slice(SHENANIGANS)] +static NNN: i32 = 999; + +#[test] +fn test() { + assert_eq!(SHENANIGANS.len(), 3); + + let mut sum = 0; + for n in SHENANIGANS { + sum += n; + } + + assert_eq!(sum, 9 + 99 + 999); +} + +#[test] +fn test_empty() { + #[distributed_slice] + static EMPTY: [i32] = [..]; + + assert!(EMPTY.is_empty()); +} + +#[test] +fn test_non_copy() { + struct NonCopy(i32); + + #[distributed_slice] + static NONCOPY: [NonCopy] = [..]; + + #[distributed_slice(NONCOPY)] + static ELEMENT: NonCopy = NonCopy(9); + + assert!(!NONCOPY.is_empty()); +} + +#[test] +fn test_interior_mutable() { + #[distributed_slice] + static MUTABLE: [Lazy] = [..]; + + #[distributed_slice(MUTABLE)] + static ELEMENT: Lazy = Lazy::new(|| -1); + + assert!(MUTABLE.len() == 1); + assert!(*MUTABLE[0] == -1); +} + +#[test] +fn test_elided_lifetime() { + #[distributed_slice] + pub static MYSLICE: [&str] = [..]; + + #[distributed_slice(MYSLICE)] + static ELEMENT: &str = "..."; + + assert!(!MYSLICE.is_empty()); +} -- cgit v1.2.3