-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement From<Embed> for CreateEmbed
- Loading branch information
Austin Hellyer
committed
Dec 8, 2016
1 parent
f69512b
commit 7914274
Showing
3 changed files
with
155 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
extern crate serde_json; | ||
extern crate serenity; | ||
|
||
use serde_json::builder::ObjectBuilder; | ||
use serde_json::Value; | ||
use serenity::model::{Embed, EmbedField, EmbedImage}; | ||
use serenity::utils::builder::CreateEmbed; | ||
use serenity::utils::Colour; | ||
|
||
#[test] | ||
fn from_embed() { | ||
let embed = Embed { | ||
author: None, | ||
colour: Colour::new(0xFF0011), | ||
description: Some("This is a test description".to_owned()), | ||
fields: Some(vec![ | ||
EmbedField { | ||
inline: false, | ||
name: "a".to_owned(), | ||
value: "b".to_owned(), | ||
}, | ||
EmbedField { | ||
inline: true, | ||
name: "c".to_owned(), | ||
value: "z".to_owned(), | ||
}, | ||
]), | ||
image: Some(EmbedImage { | ||
height: 213, | ||
proxy_url: "a".to_owned(), | ||
url: "https://i.imgur.com/q9MqLqZ.png".to_owned(), | ||
width: 224, | ||
}), | ||
kind: "rich".to_owned(), | ||
provider: None, | ||
thumbnail: None, | ||
timestamp: None, | ||
title: Some("funny cat meme".to_owned()), | ||
url: Some("https://i.imgur.com/q9MqLqZ.png".to_owned()), | ||
video: None, | ||
}; | ||
|
||
let builder = CreateEmbed::from(embed) | ||
.colour(0xFF0000) | ||
.description("This is a cat description") | ||
.title("still a funny cat meme") | ||
.url("https://i.imgur.com/q9MqLqZ.jpg") | ||
.image(|i| i | ||
.height(426) | ||
.url("https://i.imgur.com/q9MqLqZ.jpg") | ||
.width(448)); | ||
|
||
let built = Value::Object(builder.0); | ||
|
||
let obj = ObjectBuilder::new() | ||
.insert("color", 0xFF0000) | ||
.insert("description", "This is a cat description") | ||
.insert_array("fields", |a| a | ||
.push_object(|o| o | ||
.insert("inline", false) | ||
.insert("name", "a") | ||
.insert("value", "b")) | ||
.push_object(|o| o | ||
.insert("inline", true) | ||
.insert("name", "c") | ||
.insert("value", "z"))) | ||
.insert_object("image", |o| o | ||
.insert("height", 426) | ||
.insert("url", "https://i.imgur.com/q9MqLqZ.jpg") | ||
.insert("width", 448)) | ||
.insert("title", "still a funny cat meme") | ||
.insert("type", "rich") | ||
.insert("url", "https://i.imgur.com/q9MqLqZ.jpg") | ||
.build(); | ||
|
||
assert_eq!(built, obj); | ||
} |