aboutsummaryrefslogtreecommitdiff
path: root/src/model/user.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-08-01 08:08:23 -0700
committerZeyla Hellyer <[email protected]>2018-08-01 08:10:05 -0700
commit3fed313193356c6784a33b79d1c2f583ea3944f9 (patch)
tree875b4bab989fc573850d30317a1797bca5027e9f /src/model/user.rs
parentReword the inner doc comment in `complex_bucket` (diff)
downloadserenity-3fed313193356c6784a33b79d1c2f583ea3944f9.tar.xz
serenity-3fed313193356c6784a33b79d1c2f583ea3944f9.zip
Move unit tests into source
Move the unit tests into the relevant source files. There's no need for them to be seprate, especially when the `tests` directory is meant to be for integration tests. The deserialization tests that include JSON files are still in the `tests` dir, along with the public prelude re-export tests.
Diffstat (limited to 'src/model/user.rs')
-rw-r--r--src/model/user.rs68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/model/user.rs b/src/model/user.rs
index 859f168..d76b135 100644
--- a/src/model/user.rs
+++ b/src/model/user.rs
@@ -844,3 +844,71 @@ fn tag(name: &str, discriminator: u16) -> String {
tag
}
+
+#[cfg(test)]
+mod test {
+ #[cfg(feature = "model")]
+ mod model {
+ use model::id::UserId;
+ use model::user::User;
+
+ fn gen() -> User {
+ User {
+ id: UserId(210),
+ avatar: Some("abc".to_string()),
+ bot: true,
+ discriminator: 1432,
+ name: "test".to_string(),
+ }
+ }
+
+ #[test]
+ fn test_core() {
+ let mut user = gen();
+
+ assert!(
+ user.avatar_url()
+ .unwrap()
+ .ends_with("/avatars/210/abc.webp?size=1024")
+ );
+ assert!(
+ user.static_avatar_url()
+ .unwrap()
+ .ends_with("/avatars/210/abc.webp?size=1024")
+ );
+
+ user.avatar = Some("a_aaa".to_string());
+ assert!(
+ user.avatar_url()
+ .unwrap()
+ .ends_with("/avatars/210/a_aaa.gif?size=1024")
+ );
+ assert!(
+ user.static_avatar_url()
+ .unwrap()
+ .ends_with("/avatars/210/a_aaa.webp?size=1024")
+ );
+
+ user.avatar = None;
+ assert!(user.avatar_url().is_none());
+
+ assert_eq!(user.tag(), "test#1432");
+ }
+
+ #[test]
+ fn default_avatars() {
+ let mut user = gen();
+
+ user.discriminator = 0;
+ assert!(user.default_avatar_url().ends_with("0.png"));
+ user.discriminator = 1;
+ assert!(user.default_avatar_url().ends_with("1.png"));
+ user.discriminator = 2;
+ assert!(user.default_avatar_url().ends_with("2.png"));
+ user.discriminator = 3;
+ assert!(user.default_avatar_url().ends_with("3.png"));
+ user.discriminator = 4;
+ assert!(user.default_avatar_url().ends_with("4.png"));
+ }
+ }
+}