Explorar o código

Address code review issues

Tomasz %!s(int64=9) %!d(string=hai) anos
pai
achega
8f6e4f9ff7
Modificáronse 2 ficheiros con 23 adicións e 17 borrados
  1. 2 2
      src/host.rs
  2. 21 15
      tests/unit.rs

+ 2 - 2
src/host.rs

@@ -166,8 +166,8 @@ impl<S: AsRef<str>> fmt::Display for Host<S> {
             Host::Domain(ref domain) => domain.as_ref().fmt(f),
             Host::Domain(ref domain) => domain.as_ref().fmt(f),
             Host::Ipv4(ref addr) => addr.fmt(f),
             Host::Ipv4(ref addr) => addr.fmt(f),
             Host::Ipv6(ref addr) => {
             Host::Ipv6(ref addr) => {
-                try!(f.write_str("["));
-                try!(write_ipv6(addr, f));
+                f.write_str("[")?;
+                write_ipv6(addr, f)?;
                 f.write_str("]")
                 f.write_str("]")
             }
             }
         }
         }

+ 21 - 15
tests/unit.rs

@@ -256,26 +256,32 @@ fn test_form_serialize() {
 
 
 #[test]
 #[test]
 fn host_and_port_display() {
 fn host_and_port_display() {
-    let data = [
-        (HostAndPort{ host: Host::Domain("www.mozilla.org"), port: 80}, "www.mozilla.org:80"),
-        (
-            HostAndPort{ host: Host::Ipv4(Ipv4Addr::new(1, 35, 33, 49)), port: 65535 },
-            "1.35.33.49:65535"
+    assert_eq!(
+        format!(
+            "{}",
+            HostAndPort{ host: Host::Domain("www.mozilla.org"), port: 80}
+        ),
+        "www.mozilla.org:80"
+    );
+    assert_eq!(
+        format!(
+            "{}",
+            HostAndPort::<String>{ host: Host::Ipv4(Ipv4Addr::new(1, 35, 33, 49)), port: 65535 }
         ),
         ),
-        (
-            HostAndPort{
+        "1.35.33.49:65535"
+    );
+    assert_eq!(
+        format!(
+            "{}",
+            HostAndPort::<String>{
                 host: Host::Ipv6(Ipv6Addr::new(
                 host: Host::Ipv6(Ipv6Addr::new(
                     0x2001, 0x0db8, 0x85a3, 0x08d3, 0x1319, 0x8a2e, 0x0370, 0x7344
                     0x2001, 0x0db8, 0x85a3, 0x08d3, 0x1319, 0x8a2e, 0x0370, 0x7344
                 )),
                 )),
                 port: 1337
                 port: 1337
-            },
-            "[2001:db8:85a3:8d3:1319:8a2e:370:7344]:1337"
-        )
-    ];
-
-    for &(ref input, result) in &data {
-        assert_eq!(format!("{}", input), result)
-    }
+            })
+        ,
+        "[2001:db8:85a3:8d3:1319:8a2e:370:7344]:1337"
+    )
 }
 }
 
 
 #[test]
 #[test]