[lib] Fix doc tests
Signed-off-by: Ben Aaron Goldberg <ben@benaaron.dev>
This commit is contained in:
parent
4cef709f52
commit
a853d8796a
11
src/lib.rs
11
src/lib.rs
|
@ -8,6 +8,7 @@
|
|||
//! ## Basic Usage
|
||||
//!
|
||||
//! ```
|
||||
//! # use pronouns_today::user_preferences::ParseError;
|
||||
//! use pronouns_today::InstanceSettings;
|
||||
//!
|
||||
//! let instance_settings = InstanceSettings::default(); // Or load from a config file
|
||||
|
@ -15,9 +16,10 @@
|
|||
//! // When you receive a request
|
||||
//! let user_name = Some("Emi");
|
||||
//! let user_prefstr = Some("acaqqbykawbag");
|
||||
//! let pronouns = instance_settings.select_pronouns(user_name, user_prefstr);
|
||||
//! let pronouns = instance_settings.select_pronouns(user_name, user_prefstr)?;
|
||||
//!
|
||||
//! println!("Your pronouns are: {}", pronouns);
|
||||
//! # Ok::<(), ParseError>(())
|
||||
//! ```
|
||||
//!
|
||||
//! ## Advanced Usage
|
||||
|
@ -74,12 +76,15 @@ impl InstanceSettings {
|
|||
/// This is shorthand for
|
||||
///
|
||||
/// ```
|
||||
/// # use crate::pronouns_today::user_preferences::Preference;
|
||||
/// # use pronouns_today::user_preferences::ParseError;
|
||||
/// # use pronouns_today::InstanceSettings;
|
||||
/// # let settings = InstanceSettings::default();
|
||||
/// # let name = String::from("Sashanoraa");
|
||||
/// # let prefstring = String::from("todo");
|
||||
/// let pronouns = InstanceSettings::parse_prefstring(Some(&prefstring))?.select_pronouns(&settings, Some(&name));
|
||||
/// # let prefstring = String::from("acaqebicadbqaaa");
|
||||
/// let pronouns = InstanceSettings::parse_prefstring(Some(&prefstring))?.select_pronoun(&settings, Some(&name));
|
||||
/// # assert_eq!(pronouns, settings.select_pronouns(Some(&name), Some(&prefstring)));
|
||||
/// # Ok::<(), ParseError>(())
|
||||
/// ```
|
||||
pub fn select_pronouns(&self, name: Option<&str>, pref_string: Option<&str>) -> Result<&Pronoun, ParseError> {
|
||||
Self::parse_prefstring(pref_string)?.select_pronoun(&self, name)
|
||||
|
|
|
@ -100,10 +100,14 @@ pub trait Preference {
|
|||
/// Is shorthand for
|
||||
///
|
||||
/// ```
|
||||
/// # use pronouns_today::InstanceSettings;
|
||||
/// # use pronouns_today::user_preferences::ParseError;
|
||||
/// # use pronouns_today::{InstanceSettings, UserPreferences};
|
||||
/// # use crate::pronouns_today::user_preferences::Preference;
|
||||
/// # let settings = InstanceSettings::default();
|
||||
/// # let seed = &[];
|
||||
/// self.into_weighted_table(settings)?.select_today(seed)
|
||||
/// # let prefs = UserPreferences::default();
|
||||
/// prefs.create_weighted_table(&settings)?.select_today(seed);
|
||||
/// # Ok::<(), ParseError>(())
|
||||
/// ```
|
||||
fn select_pronoun<'a>(&self, settings: &'a InstanceSettings, name: Option<&str>) -> Result<&'a Pronoun, ParseError> {
|
||||
let seed = match name {
|
||||
|
|
|
@ -306,7 +306,7 @@ mod tests {
|
|||
fn check_table(actual: WeightedTable<&Pronoun>, expected: Vec<(&str, u8)>) {
|
||||
let actual_simplified = actual.weights()
|
||||
.into_iter()
|
||||
.filter(|(pronoun, weight)| **weight > 0)
|
||||
.filter(|(_, weight)| **weight > 0)
|
||||
.map(|(pronoun, weight)| (pronoun.subject_pronoun.as_str(), *weight))
|
||||
.collect::<HashMap<&str, u8>>();
|
||||
let expected_owned = expected.into_iter()
|
||||
|
@ -362,6 +362,7 @@ mod tests {
|
|||
("they", 3),
|
||||
("it", 3),
|
||||
];
|
||||
check_table(table, expected_table);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue