diff options
| author | Zeyla Hellyer <[email protected]> | 2017-11-01 10:27:18 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-11-01 10:36:06 -0700 |
| commit | 7d360baf45142127476d2d37898f65e942c626e2 (patch) | |
| tree | 7b256b286fcc5330520f67bbb19432a8dd6156aa /src/framework | |
| parent | Fix audit logs a bit (diff) | |
| download | serenity-7d360baf45142127476d2d37898f65e942c626e2.tar.xz serenity-7d360baf45142127476d2d37898f65e942c626e2.zip | |
Fix framework Args tests
The tests were left untouched after a breaking change, resulting in them
failing.
Diffstat (limited to 'src/framework')
| -rw-r--r-- | src/framework/standard/args.rs | 142 |
1 files changed, 71 insertions, 71 deletions
diff --git a/src/framework/standard/args.rs b/src/framework/standard/args.rs index 6186cd4..fab27a5 100644 --- a/src/framework/standard/args.rs +++ b/src/framework/standard/args.rs @@ -83,14 +83,14 @@ impl Args { } /// Removes the first element, parses it to a specific type if necessary, returns. - /// + /// /// # Examples - /// + /// /// ```rust /// use serenity::framework::standard::Args; - /// - /// let mut args = Args::new("42 69", " "); - /// + /// + /// let mut args = Args::new("42 69", vec![" ".to_owned()]); + /// /// assert_eq!(args.single::<i32>().unwrap(), 42); /// assert_eq!(args, ["69"]); /// ``` @@ -112,18 +112,18 @@ impl Args { /// /// [`single`]: #method.single /// [`FromStrZc`]: trait.FromStrZc.html - pub fn single_zc<'a, T: FromStrZc<'a> + 'a>(&'a mut self) -> Result<T, T::Err> + pub fn single_zc<'a, T: FromStrZc<'a> + 'a>(&'a mut self) -> Result<T, T::Err> where T::Err: StdError { - + // This is a hack as to mitigate some nasty lifetime errors. // // (Culprit `Vec::remove`s return type) fn get_and_remove(b: &mut Vec<String>) -> Option<&str> { struct GetThenRemove<'a>(&'a mut Vec<String>); - + impl<'a> Drop for GetThenRemove<'a> { fn drop(&mut self) { - if !self.0.is_empty() { + if !self.0.is_empty() { self.0.remove(0); } } @@ -139,16 +139,16 @@ impl Args { /// Like [`single`], but doesn't remove the element. /// /// # Examples - /// + /// /// ```rust /// use serenity::framework::standard::Args; - /// - /// let args = Args::new("42 69", " "); - /// + /// + /// let args = Args::new("42 69", vec![" ".to_owned()]); + /// /// assert_eq!(args.single_n::<i32>().unwrap(), 42); /// assert_eq!(args, ["42", "69"]); /// ``` - /// + /// /// [`single`]: #method.single pub fn single_n<T: FromStr>(&self) -> Result<T, T::Err> where T::Err: StdError { @@ -163,14 +163,14 @@ impl Args { } /// Skips if there's a first element, but also returns it. - /// + /// /// # Examples - /// + /// /// ```rust /// use serenity::framework::standard::Args; - /// - /// let mut args = Args::new("42 69", " "); - /// + /// + /// let mut args = Args::new("42 69", vec![" ".to_owned()]); + /// /// assert_eq!(args.skip().unwrap(), "42"); /// assert_eq!(args, ["69"]); /// ``` @@ -181,13 +181,13 @@ impl Args { /// # Examples /// ```rust /// use serenity::framework::standard::Args; - /// - /// let mut args = Args::new("42 69 88 99", " "); - /// + /// + /// let mut args = Args::new("42 69 88 99", vec![" ".to_owned()]); + /// /// assert_eq!(*args.skip_for(3).unwrap(), ["42".to_string(), "69".to_string(), "88".to_string()]); /// assert_eq!(args, ["99"]); /// ``` - /// + /// /// [`skip`]: #method.skip pub fn skip_for(&mut self, i: u32) -> Option<Vec<String>> { let mut vec = Vec::with_capacity(i as usize); @@ -200,18 +200,18 @@ impl Args { } /// Like [`single`], but takes quotes into account. - /// + /// /// # Examples - /// + /// /// ```rust /// use serenity::framework::standard::Args; - /// - /// let mut args = Args::new(r#""42"#, " "); - /// + /// + /// let mut args = Args::new(r#""42"#, vec![" ".to_owned()]); + /// /// assert_eq!(args.single_quoted::<i32>().unwrap(), 42); /// assert!(args.is_empty()); /// ``` - /// + /// /// [`single`]: #method.single pub fn single_quoted<T: FromStr>(&mut self) -> Result<T, T::Err> where T::Err: StdError { @@ -246,30 +246,30 @@ impl Args { } /// Empty outs the internal vector while parsing (if necessary) and returning them - /// + /// /// # Examples - /// + /// /// ```rust /// use serenity::framework::standard::Args; - /// - /// let mut args = Args::new("42 69", " "); - /// + /// + /// let mut args = Args::new("42 69", vec![" ".to_owned()]); + /// /// assert_eq!(*args.list::<i32>().unwrap(), [42, 69]); - /// ``` + /// ``` pub fn list<T: FromStr>(mut self) -> Result<Vec<T>, T::Err> where T::Err: StdError { Iter::<T>::new(&mut self).collect() } /// Provides an iterator of items: (`T: FromStr`) `Result<T, T::Err>`. - /// + /// /// # Examples - /// + /// /// ```rust /// use serenity::framework::standard::Args; - /// - /// let mut args = Args::new("3 4", " "); - /// + /// + /// let mut args = Args::new("3 4", vec![" ".to_owned()]); + /// /// assert_eq!(*args.iter::<i32>().map(|num| num.unwrap().pow(2)).collect::<Vec<_>>(), [9, 16]); /// assert!(args.is_empty()); /// ``` @@ -278,27 +278,27 @@ impl Args { } /// This method is just `internal_vector.join(delimiter)` - /// + /// /// # Examples - /// + /// /// ```rust /// use serenity::framework::standard::Args; - /// - /// let mut args = Args::new("42 69", " "); - /// + /// + /// let mut args = Args::new("42 69", vec![" ".to_owned()]); + /// /// assert_eq!(args.full(), "42 69"); /// ``` pub fn full(&self) -> String { self.delimiter_split.join(&self.delimiter) } /// Returns the first argument that can be converted and removes it from the list. - /// + /// /// # Examples - /// + /// /// ```rust /// use serenity::framework::standard::Args; - /// - /// let mut args = Args::new("c47 69", " "); - /// + /// + /// let mut args = Args::new("c47 69", vec![" ".to_owned()]); + /// /// assert_eq!(args.find::<i32>().unwrap(), 69); /// assert_eq!(args, ["c47"]); /// ``` @@ -327,14 +327,14 @@ impl Args { } /// Returns the first argument that can be converted and does not remove it from the list. - /// + /// /// # Examples - /// + /// /// ```rust /// use serenity::framework::standard::Args; - /// - /// let args = Args::new("c47 69", " "); - /// + /// + /// let args = Args::new("c47 69", vec![" ".to_owned()]); + /// /// assert_eq!(args.find_n::<i32>().unwrap(), 69); /// assert_eq!(args, ["c47", "69"]); /// ``` @@ -353,29 +353,29 @@ impl Args { } /// A version of `FromStr` that allows for "zero-copy" parsing. -/// +/// /// # Examples -/// +/// /// ```rust,ignore /// use serenity::framework::standard::{Args, FromStrZc}; /// use std::fmt; -/// +/// /// struct NameDiscrim<'a>(&'a str, Option<&'a str>); -/// +/// /// #[derive(Debug)] /// struct Error(&'static str); -/// +/// /// impl std::error::Error for Error { /// fn description(&self) -> &str { self.0 } /// } -/// +/// /// impl fmt::Display for Error { /// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0) } /// } -/// +/// /// impl<'a> FromStrZc<'a> for NameDiscrim<'a> { /// type Err = Error; -/// +/// /// fn from_str(s: &'a str) -> Result<NameDiscrim<'a>, Error> { /// let mut it = s.split("#"); /// let name = it.next().ok_or(Error("name must be specified"))?; @@ -383,16 +383,16 @@ impl Args { /// Ok(NameDiscrim(name, discrim)) /// } /// } -/// -/// let mut args = Args::new("abc#1234", " "); +/// +/// let mut args = Args::new("abc#1234", vec![" ".to_owned()]); /// let NameDiscrim(name, discrim) = args.single_zc::<NameDiscrim>().unwrap(); -/// +/// /// assert_eq!(name, "abc"); /// assert_eq!(discrim, Some("1234")); -/// ``` +/// ``` pub trait FromStrZc<'a>: Sized { type Err; - + fn from_str(s: &'a str) -> ::std::result::Result<Self, Self::Err>; } @@ -413,14 +413,14 @@ impl ::std::ops::Deref for Args { impl<'a> PartialEq<[&'a str]> for Args { fn eq(&self, other: &[&str]) -> bool { let mut b = true; - + for (s, o) in self.delimiter_split.iter().zip(other.iter()) { if s != o { b = false; break; } } - + b } } @@ -432,7 +432,7 @@ macro_rules! impl_slices { self.delimiter_split.is_empty() } } - + $( impl<'a> PartialEq<[&'a str; $num]> for Args { fn eq(&self, other: &[&str; $num]) -> bool { |