Clean up status_builder a bit, and add some tests
This commit is contained in:
+31
-9
@@ -1,5 +1,5 @@
|
||||
/// A builder pattern struct for constructing a status.
|
||||
#[derive(Debug, Default, Clone, Serialize)]
|
||||
#[derive(Debug, Default, Clone, Serialize, PartialEq)]
|
||||
pub struct StatusBuilder {
|
||||
/// The text of the status.
|
||||
pub status: String,
|
||||
@@ -21,19 +21,16 @@ pub struct StatusBuilder {
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
/// A Direct message to a user
|
||||
#[serde(rename = "direct")]
|
||||
Direct,
|
||||
/// Only available to followers
|
||||
#[serde(rename = "private")]
|
||||
Private,
|
||||
/// Not shown in public timelines
|
||||
#[serde(rename = "unlisted")]
|
||||
Unlisted,
|
||||
/// Posted to public timelines
|
||||
#[serde(rename = "public")]
|
||||
Public,
|
||||
}
|
||||
|
||||
@@ -42,11 +39,11 @@ impl StatusBuilder {
|
||||
/// ```
|
||||
/// 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 {
|
||||
status,
|
||||
status: status.into(),
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
@@ -57,3 +54,28 @@ impl Default for Visibility {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user