aboutsummaryrefslogtreecommitdiff
path: root/src/utils/mod.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/utils/mod.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/utils/mod.rs')
-rw-r--r--src/utils/mod.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index e20dd22..6c84384 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -500,3 +500,54 @@ pub fn with_cache_mut<T, F>(mut f: F) -> T
let mut cache = CACHE.write();
f(&mut cache)
}
+
+#[cfg(test)]
+mod test {
+ use super::*;
+
+ #[test]
+ fn test_invite_parser() {
+ assert_eq!(parse_invite("https://discord.gg/abc"), "abc");
+ assert_eq!(parse_invite("http://discord.gg/abc"), "abc");
+ assert_eq!(parse_invite("discord.gg/abc"), "abc");
+ }
+
+ #[test]
+ fn test_username_parser() {
+ assert_eq!(parse_username("<@12345>").unwrap(), 12_345);
+ assert_eq!(parse_username("<@!12345>").unwrap(), 12_345);
+ }
+
+ #[test]
+ fn role_parser() {
+ assert_eq!(parse_role("<@&12345>").unwrap(), 12_345);
+ }
+
+ #[test]
+ fn test_channel_parser() {
+ assert_eq!(parse_channel("<#12345>").unwrap(), 12_345);
+ }
+
+ #[test]
+ fn test_emoji_parser() {
+ let emoji = parse_emoji("<:name:12345>").unwrap();
+ assert_eq!(emoji.name, "name");
+ assert_eq!(emoji.id, 12_345);
+ }
+
+ #[test]
+ fn test_quote_parser() {
+ let parsed = parse_quotes("a \"b c\" d\"e f\" g");
+ assert_eq!(parsed, ["a", "b c", "d", "e f", "g"]);
+ }
+
+ #[test]
+ fn test_is_nsfw() {
+ assert!(!is_nsfw("general"));
+ assert!(is_nsfw("nsfw"));
+ assert!(is_nsfw("nsfw-test"));
+ assert!(!is_nsfw("nsfw-"));
+ assert!(!is_nsfw("général"));
+ assert!(is_nsfw("nsfw-général"));
+ }
+}