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.
This commit is contained in:
		| @@ -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<Method,uint> = HashMap::new(); | ||||
|         counter.insert(Get, 1); | ||||
|         assert_eq!(Some(&1), counter.get(&Get)); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user