diff --git a/src/core.rs b/src/core.rs index c0947774..4d53e1d0 100644 --- a/src/core.rs +++ b/src/core.rs @@ -155,14 +155,16 @@ impl MailboxConnection { /// /// # Examples /// - /// #[cfg(feature = "entropy")] /// ```no_run + /// # #[cfg(feature = "entropy")] + /// # { /// # fn main() -> eyre::Result<()> { async_std::task::block_on(async { /// use magic_wormhole::{transfer::APP_CONFIG, MailboxConnection}; /// let config = APP_CONFIG; /// let mailbox_connection = /// MailboxConnection::create_with_password(config, "secret".parse()?).await?; /// # Ok(()) })} + /// # } /// ``` /// /// TODO: Replace this with create_with_validated_password @@ -260,13 +262,17 @@ impl MailboxConnection { /// /// ``` /// # fn main() -> eyre::Result<()> { use magic_wormhole::WormholeError; - /// async_std::task::block_on(async { + /// # #[cfg(feature = "entropy")] + /// return async_std::task::block_on(async { /// use magic_wormhole::{transfer::APP_CONFIG, MailboxConnection, Mood}; /// let config = APP_CONFIG; /// let mailbox_connection = MailboxConnection::create_with_password(config, "secret-code-password".parse()?) /// .await?; /// mailbox_connection.shutdown(Mood::Happy).await?; - /// # Ok(())})} + /// # Ok(())}); + /// # #[cfg(not(feature = "entropy"))] + /// # return Ok(()); + /// # } /// ``` pub async fn shutdown(self, mood: Mood) -> Result<(), WormholeError> { self.server diff --git a/src/core/wordlist.rs b/src/core/wordlist.rs index 652a5748..bdb3a0c1 100644 --- a/src/core/wordlist.rs +++ b/src/core/wordlist.rs @@ -79,7 +79,7 @@ impl Wordlist { fn normal_complete(&self, partial: &str, words: &[String]) -> Vec { words .iter() - .filter(|word| word.starts_with(partial)) + .filter(|word| !partial.is_empty() && word.starts_with(partial)) .cloned() .collect() } @@ -277,7 +277,6 @@ mod test { #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] - #[cfg(feature = "fuzzy-complete")] fn test_completion_normal() { let wl = Wordlist::default_wordlist(2); let list = wl.get_wordlist("22-"); @@ -286,10 +285,8 @@ mod test { wl.normal_complete("braz", list).first().unwrap(), "brazilian" ); - assert_ne!( - wl.fuzzy_complete("choking", list).first().unwrap(), - "choking" - ) + assert_eq!(wl.normal_complete("cara", list).first().unwrap(), "caravan"); + assert!(wl.normal_complete("cravan", list).is_empty()); } #[test] @@ -298,11 +295,11 @@ mod test { let list = Wordlist::default_wordlist(2); assert_eq!( - list.get_completions("22-cmpont").first().unwrap(), + list.get_completions("22-compo").first().unwrap(), "22-component" ); assert_eq!( - list.get_completions("22-component-chkup").first().unwrap(), + list.get_completions("22-component-check").first().unwrap(), "22-component-checkup" ); assert_ne!(list.get_completions("22-troj"), ["trojan"]);