From ccef7953f8c4de52a9d0310f741c03777b3a8bdb Mon Sep 17 00:00:00 2001 From: Eric Kidd Date: Mon, 24 Nov 2014 20:22:10 -0500 Subject: [PATCH] Add some basic tests for hyper::method::Method This test case does not attempt to test all the methods exhaustively, but it does at least test all the methods in the APIs. There's also a check to make sure that Method can be used as part of a hash-table key. --- src/method.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/method.rs b/src/method.rs index 8bd1b96e..0e0b89e1 100644 --- a/src/method.rs +++ b/src/method.rs @@ -100,3 +100,45 @@ impl fmt::Show for Method { }.fmt(fmt) } } + +#[cfg(test)] +mod tests { + use std::collections::HashMap; + use std::str::FromStr; + use super::Method; + use super::Method::{Get, Post, Put, Extension}; + + #[test] + fn test_safe() { + assert_eq!(true, Get.safe()); + assert_eq!(false, Post.safe()); + } + + #[test] + fn test_idempotent() { + assert_eq!(true, Get.idempotent()); + assert_eq!(true, Put.idempotent()); + assert_eq!(false, Post.idempotent()); + } + + #[test] + fn test_from_str() { + assert_eq!(Some(Get), FromStr::from_str("GET")); + assert_eq!(Some(Extension("MOVE".to_string())), + FromStr::from_str("MOVE")); + } + + #[test] + fn test_fmt() { + assert_eq!("GET".to_string(), format!("{}", Get)); + assert_eq!("MOVE".to_string(), + format!("{}", Extension("MOVE".to_string()))); + } + + #[test] + fn test_hashable() { + let mut counter: HashMap = HashMap::new(); + counter.insert(Get, 1); + assert_eq!(Some(&1), counter.get(&Get)); + } +}