use uri_formatter::authority::{Authority, Host, Port, UserInfo}; use uri_formatter::fragment::Fragment; use uri_formatter::Parser; use uri_formatter::rpart::RPart; use uri_formatter::scheme::Scheme; use uri_formatter::uri::URI; use uri_formatter::path::Path; use uri_formatter::query::Query; #[test] fn decode() { // create uri value by decode let a = "https://root:passwd@www.baidu.com:8081/path/to/my/value?arg1=bar&arg2=foo&arg2=hello#L18"; let r = URI::decode(a).unwrap(); // create uri value by hand let mut query = Query::new(); query.set("arg1", "bar"); query.set("arg2", "foo"); query.set("arg2", "hello"); let uri = URI { scheme: Some(Scheme::new("https")), rpart: Some(RPart { authority: Some(Authority { user_info: Some(UserInfo("root:passwd".to_string())), host: Host::RegName("www.baidu.com".to_string()), port: Some(Port(8081)), }), path: Some(Path("/path/to/my/value".to_string())), }), query: Some(query), fragment: Some(Fragment("L18".to_string())), }; // compare if two values are equal assert_eq!(r, uri); } // test may failed when there are multiple query args, because of uncertain of the hashset order #[test] fn encode() { // create uri value by hand let mut query = Query::new(); query.set("arg2", "hello"); let uri = URI { scheme: Some(Scheme::new("https")), rpart: Some(RPart { authority: Some(Authority { user_info: Some(UserInfo("root:passwd".to_string())), host: Host::RegName("www.baidu.com".to_string()), port: Some(Port(8081)), }), path: Some(Path("/path/to/my/value".to_string())), }), query: Some(query), fragment: Some(Fragment("L18".to_string())), }; let r = uri.encode().unwrap(); let a = "https://root:passwd@www.baidu.com:8081/path/to/my/value?arg2=hello#L18"; assert_eq!(r.as_str(), a) }