From ee7b71e9e1380592f47b78673bf127f1c18bbcb9 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Tue, 26 Apr 2022 23:02:43 -0300 Subject: Tweak extra tests --- src/extra_tests.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/extra_tests.rs') 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); +//! }) +//! } +//! ``` -- cgit 1.4.1