summary refs log tree commit diff stats
path: root/src/extra_tests.rs
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2022-04-26 23:02:43 -0300
committerSoniEx2 <endermoneymod@gmail.com>2022-04-26 23:02:43 -0300
commitee7b71e9e1380592f47b78673bf127f1c18bbcb9 (patch)
treef9ce89d67da4aa1e7aa1e5dc94838bb160fc5626 /src/extra_tests.rs
parentcd895073b6f44239ba65147783e0d305b1d49a64 (diff)
Tweak extra tests
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);
+//!     })
+//! }
+//! ```