summary refs log tree commit diff stats
path: root/src/extra_tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/extra_tests.rs')
-rw-r--r--src/extra_tests.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/extra_tests.rs b/src/extra_tests.rs
index b64cc22..a81e312 100644
--- a/src/extra_tests.rs
+++ b/src/extra_tests.rs
@@ -30,3 +30,36 @@
 //!     })
 //! }
 //! ```
+//!
+//! ```compile_fail
+//! use hexchat_unsafe_plugin::list::Contexts;
+//! use hexchat_unsafe_plugin::PluginHandle;
+//!
+//! fn unsound(ph: &mut PluginHandle<'_>) {
+//!     ph.ensure_valid_context(|mut ph| {
+//!         let mut list = ph.list(&Contexts);
+//!         let context = list.next().unwrap();
+//!         std::mem::forget(list);
+//!         let ctx = context.context();
+//!         ph.set_context(&ctx);
+//!     })
+//! }
+//! ```
+//!
+//! ```no_run
+//! use hexchat_unsafe_plugin::list::Contexts;
+//! use hexchat_unsafe_plugin::PluginHandle;
+//!
+//! fn fine(ph: &mut PluginHandle<'_>) {
+//!     ph.ensure_valid_context(|mut ph| {
+//!         let mut list = ph.list(&Contexts);
+//!         let context = list.next().unwrap();
+//!         write!(ph, "{}", context.name().unwrap());
+//!         let ctx = context.context();
+//!         let name = context.name().unwrap();
+//!         drop(list);
+//!         ph.set_context(&ctx);
+//!         write!(ph, "{}", name);
+//!     })
+//! }
+//! ```