Clean up status_builder a bit, and add some tests

master
Paul Woolcock 6 years ago
parent 6cee086d79
commit 009798d17f
  1. 40
      src/status_builder.rs

@ -1,5 +1,5 @@
/// A builder pattern struct for constructing a status. /// A builder pattern struct for constructing a status.
#[derive(Debug, Default, Clone, Serialize)] #[derive(Debug, Default, Clone, Serialize, PartialEq)]
pub struct StatusBuilder { pub struct StatusBuilder {
/// The text of the status. /// The text of the status.
pub status: String, pub status: String,
@ -21,19 +21,16 @@ pub struct StatusBuilder {
} }
/// The visibility of a status. /// The visibility of a status.
#[derive(Clone, Copy, Debug, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum Visibility { pub enum Visibility {
/// A Direct message to a user /// A Direct message to a user
#[serde(rename = "direct")]
Direct, Direct,
/// Only available to followers /// Only available to followers
#[serde(rename = "private")]
Private, Private,
/// Not shown in public timelines /// Not shown in public timelines
#[serde(rename = "unlisted")]
Unlisted, Unlisted,
/// Posted to public timelines /// Posted to public timelines
#[serde(rename = "public")]
Public, Public,
} }
@ -42,11 +39,11 @@ impl StatusBuilder {
/// ``` /// ```
/// use elefren::prelude::*; /// use elefren::prelude::*;
/// ///
/// let status = StatusBuilder::new("Hello World!".into()); /// let status = StatusBuilder::new("Hello World!");
/// ``` /// ```
pub fn new(status: String) -> Self { pub fn new<I: Into<String>>(status: I) -> Self {
StatusBuilder { StatusBuilder {
status, status: status.into(),
..Self::default() ..Self::default()
} }
} }
@ -57,3 +54,28 @@ impl Default for Visibility {
Visibility::Public Visibility::Public
} }
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new() {
let s = StatusBuilder::new("a status");
let expected = StatusBuilder {
status: "a status".to_string(),
in_reply_to_id: None,
media_ids: None,
sensitive: None,
spoiler_text: None,
visibility: None,
};
assert_eq!(s, expected);
}
#[test]
fn test_default_visibility() {
let v = Visibility::default();
assert_eq!(v, Visibility::Public);
}
}

Loading…
Cancel
Save