aboutsummaryrefslogtreecommitdiff
path: root/tests/distributed_slice.rs
diff options
context:
space:
mode:
authorAndrew Walbran <qwandor@google.com>2023-06-01 21:35:03 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-06-01 21:35:03 +0000
commit1c22bc6df0d6bc5b59369a7ef807a233ffc0d93c (patch)
treec152abda73624cb4a77225f0682f01b33a76be30 /tests/distributed_slice.rs
parenteef466dd058ab69a4edff26d5ba602918dc8b071 (diff)
parent6128694f14608a39f371cb04332203dd55021272 (diff)
downloadlinkme-1c22bc6df0d6bc5b59369a7ef807a233ffc0d93c.tar.gz
Initial import am: 2970041c34 am: 59f583acb4 am: a1d0e5dd7b am: e423295327 am: c89a473751 am: 6128694f14
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/linkme/+/2607228 Change-Id: I68fab7b22e524e64414ad7695e83e668c744c07f Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'tests/distributed_slice.rs')
-rw-r--r--tests/distributed_slice.rs72
1 files changed, 72 insertions, 0 deletions
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<i32>] = [..];
+
+ #[distributed_slice(MUTABLE)]
+ static ELEMENT: Lazy<i32> = 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());
+}