浏览代码

Move all tests to tests/ folder.

The folder is provided by Cargo and makes it easier to find tests.
Pyfisch 10 年之前
父节点
当前提交
befcf7c3ed
共有 11 个文件被更改,包括 140 次插入153 次删除
  1. 1 1
      Cargo.toml
  2. 0 33
      src/form_urlencoded.rs
  3. 0 60
      src/format.rs
  4. 0 4
      src/lib.rs
  5. 0 54
      src/punycode.rs
  6. 29 0
      tests/form_urlencoded.rs
  7. 56 0
      tests/format.rs
  8. 52 0
      tests/punycode.rs
  9. 0 0
      tests/punycode_tests.json
  10. 2 1
      tests/tests.rs
  11. 0 0
      tests/urltestdata.txt

+ 1 - 1
Cargo.toml

@@ -1,7 +1,7 @@
 [package]
 
 name = "url"
-version = "0.5.0"
+version = "0.5.1"
 authors = [ "Simon Sapin <simon.sapin@exyr.org>" ]
 
 description = "URL library for Rust, based on the WHATWG URL Standard"

+ 0 - 33
src/form_urlencoded.rs

@@ -142,36 +142,3 @@ where I: IntoIterator, I::Item: Borrow<(K, V)>, K: AsRef<str>, V: AsRef<str> {
     }
     output
 }
-
-
-
-#[cfg(test)]
-mod tests {
-    use super::*;
-
-    #[test]
-    fn test_form_urlencoded() {
-        let pairs = &[
-            ("foo".to_string(), "é&".to_string()),
-            ("bar".to_string(), "".to_string()),
-            ("foo".to_string(), "#".to_string())
-        ];
-        let encoded = serialize(pairs);
-        assert_eq!(encoded, "foo=%C3%A9%26&bar=&foo=%23");
-        assert_eq!(parse(encoded.as_bytes()), pairs.to_vec());
-    }
-
-    #[test]
-    fn test_form_serialize() {
-        let pairs = [("foo", "é&"),
-                     ("bar", ""),
-                     ("foo", "#")];
-
-        let want = "foo=%C3%A9%26&bar=&foo=%23";
-        // Works with referenced tuples
-        assert_eq!(serialize(pairs.iter()), want);
-        // Works with owned tuples
-        assert_eq!(serialize(pairs.iter().map(|p| (p.0, p.1))), want);
-
-    }
-}

+ 0 - 60
src/format.rs

@@ -79,63 +79,3 @@ impl<'a> fmt::Display for UrlNoFragmentFormatter<'a> {
         Ok(())
     }
 }
-
-
-/// Formatting Tests
-#[cfg(test)]
-mod tests {
-    use super::super::Url;
-    use super::{PathFormatter, UserInfoFormatter};
-
-    #[test]
-    fn path_formatting() {
-        let data = [
-            (vec![], "/"),
-            (vec![""], "/"),
-            (vec!["test", "path"], "/test/path"),
-            (vec!["test", "path", ""], "/test/path/")
-        ];
-        for &(ref path, result) in &data {
-            assert_eq!(PathFormatter {
-                path: path
-            }.to_string(), result.to_string());
-        }
-    }
-
-    #[test]
-    fn userinfo_formatting() {
-        // Test data as (username, password, result) tuples.
-        let data = [
-            ("", None, ""),
-            ("", Some(""), ":@"),
-            ("", Some("password"), ":password@"),
-            ("username", None, "username@"),
-            ("username", Some(""), "username:@"),
-            ("username", Some("password"), "username:password@")
-        ];
-        for &(username, password, result) in &data {
-            assert_eq!(UserInfoFormatter {
-                username: username,
-                password: password
-            }.to_string(), result.to_string());
-        }
-    }
-
-    #[test]
-    fn relative_scheme_url_formatting() {
-        let data = [
-            ("http://example.com/", "http://example.com/"),
-            ("http://addslash.com", "http://addslash.com/"),
-            ("http://@emptyuser.com/", "http://emptyuser.com/"),
-            ("http://:@emptypass.com/", "http://:@emptypass.com/"),
-            ("http://user@user.com/", "http://user@user.com/"),
-            ("http://user:pass@userpass.com/", "http://user:pass@userpass.com/"),
-            ("http://slashquery.com/path/?q=something", "http://slashquery.com/path/?q=something"),
-            ("http://noslashquery.com/path?q=something", "http://noslashquery.com/path?q=something")
-        ];
-        for &(input, result) in &data {
-            let url = Url::parse(input).unwrap();
-            assert_eq!(url.to_string(), result.to_string());
-        }
-    }
-}

+ 0 - 4
src/lib.rs

@@ -162,10 +162,6 @@ pub mod form_urlencoded;
 pub mod punycode;
 pub mod format;
 
-#[cfg(test)]
-mod tests;
-
-
 /// The parsed representation of an absolute URL.
 #[derive(PartialEq, Eq, Clone, Debug, Hash, PartialOrd, Ord)]
 #[cfg_attr(feature="heap_size", derive(HeapSizeOf))]

+ 0 - 54
src/punycode.rs

@@ -211,57 +211,3 @@ fn value_to_digit(value: u32, output: &mut String) {
     };
     unsafe { output.as_mut_vec().push(code_point as u8) }
 }
-
-
-#[cfg(test)]
-mod tests {
-    use super::{decode, encode_str};
-    use rustc_serialize::json::{Json, Object};
-
-    fn one_test(description: &str, decoded: &str, encoded: &str) {
-        match decode(encoded) {
-            None => panic!("Decoding {} failed.", encoded),
-            Some(result) => {
-                let result = result.into_iter().collect::<String>();
-                assert!(result == decoded,
-                        format!("Incorrect decoding of {}:\n   {}\n!= {}\n{}",
-                                encoded, result, decoded, description))
-            }
-        }
-
-        match encode_str(decoded) {
-            None => panic!("Encoding {} failed.", decoded),
-            Some(result) => {
-                assert!(result == encoded,
-                        format!("Incorrect encoding of {}:\n   {}\n!= {}\n{}",
-                                decoded, result, encoded, description))
-            }
-        }
-    }
-
-    fn get_string<'a>(map: &'a Object, key: &str) -> &'a str {
-        match map.get(&key.to_string()) {
-            Some(&Json::String(ref s)) => s,
-            None => "",
-            _ => panic!(),
-        }
-    }
-
-    #[test]
-    fn test_punycode() {
-
-        match Json::from_str(include_str!("punycode_tests.json")) {
-            Ok(Json::Array(tests)) => for test in &tests {
-                match test {
-                    &Json::Object(ref o) => one_test(
-                        get_string(o, "description"),
-                        get_string(o, "decoded"),
-                        get_string(o, "encoded")
-                    ),
-                    _ => panic!(),
-                }
-            },
-            other => panic!("{:?}", other)
-        }
-    }
-}

+ 29 - 0
tests/form_urlencoded.rs

@@ -0,0 +1,29 @@
+extern crate url;
+
+use url::form_urlencoded::*;
+
+#[test]
+fn test_form_urlencoded() {
+    let pairs = &[
+        ("foo".to_string(), "é&".to_string()),
+        ("bar".to_string(), "".to_string()),
+        ("foo".to_string(), "#".to_string())
+    ];
+    let encoded = serialize(pairs);
+    assert_eq!(encoded, "foo=%C3%A9%26&bar=&foo=%23");
+    assert_eq!(parse(encoded.as_bytes()), pairs.to_vec());
+}
+
+#[test]
+fn test_form_serialize() {
+    let pairs = [("foo", "é&"),
+                 ("bar", ""),
+                 ("foo", "#")];
+
+    let want = "foo=%C3%A9%26&bar=&foo=%23";
+    // Works with referenced tuples
+    assert_eq!(serialize(pairs.iter()), want);
+    // Works with owned tuples
+    assert_eq!(serialize(pairs.iter().map(|p| (p.0, p.1))), want);
+
+}

+ 56 - 0
tests/format.rs

@@ -0,0 +1,56 @@
+extern crate url;
+
+use url::Url;
+use url::format::{PathFormatter, UserInfoFormatter};
+
+#[test]
+fn path_formatting() {
+    let data = [
+        (vec![], "/"),
+        (vec![""], "/"),
+        (vec!["test", "path"], "/test/path"),
+        (vec!["test", "path", ""], "/test/path/")
+    ];
+    for &(ref path, result) in &data {
+        assert_eq!(PathFormatter {
+            path: path
+        }.to_string(), result.to_string());
+    }
+}
+
+#[test]
+fn userinfo_formatting() {
+    // Test data as (username, password, result) tuples.
+    let data = [
+        ("", None, ""),
+        ("", Some(""), ":@"),
+        ("", Some("password"), ":password@"),
+        ("username", None, "username@"),
+        ("username", Some(""), "username:@"),
+        ("username", Some("password"), "username:password@")
+    ];
+    for &(username, password, result) in &data {
+        assert_eq!(UserInfoFormatter {
+            username: username,
+            password: password
+        }.to_string(), result.to_string());
+    }
+}
+
+#[test]
+fn relative_scheme_url_formatting() {
+    let data = [
+        ("http://example.com/", "http://example.com/"),
+        ("http://addslash.com", "http://addslash.com/"),
+        ("http://@emptyuser.com/", "http://emptyuser.com/"),
+        ("http://:@emptypass.com/", "http://:@emptypass.com/"),
+        ("http://user@user.com/", "http://user@user.com/"),
+        ("http://user:pass@userpass.com/", "http://user:pass@userpass.com/"),
+        ("http://slashquery.com/path/?q=something", "http://slashquery.com/path/?q=something"),
+        ("http://noslashquery.com/path?q=something", "http://noslashquery.com/path?q=something")
+    ];
+    for &(input, result) in &data {
+        let url = Url::parse(input).unwrap();
+        assert_eq!(url.to_string(), result.to_string());
+    }
+}

+ 52 - 0
tests/punycode.rs

@@ -0,0 +1,52 @@
+extern crate url;
+extern crate rustc_serialize;
+
+use url::punycode::{decode, encode_str};
+use rustc_serialize::json::{Json, Object};
+
+fn one_test(description: &str, decoded: &str, encoded: &str) {
+    match decode(encoded) {
+        None => panic!("Decoding {} failed.", encoded),
+        Some(result) => {
+            let result = result.into_iter().collect::<String>();
+            assert!(result == decoded,
+                    format!("Incorrect decoding of {}:\n   {}\n!= {}\n{}",
+                            encoded, result, decoded, description))
+        }
+    }
+
+    match encode_str(decoded) {
+        None => panic!("Encoding {} failed.", decoded),
+        Some(result) => {
+            assert!(result == encoded,
+                    format!("Incorrect encoding of {}:\n   {}\n!= {}\n{}",
+                            decoded, result, encoded, description))
+        }
+    }
+}
+
+fn get_string<'a>(map: &'a Object, key: &str) -> &'a str {
+    match map.get(&key.to_string()) {
+        Some(&Json::String(ref s)) => s,
+        None => "",
+        _ => panic!(),
+    }
+}
+
+#[test]
+fn test_punycode() {
+
+    match Json::from_str(include_str!("punycode_tests.json")) {
+        Ok(Json::Array(tests)) => for test in &tests {
+            match test {
+                &Json::Object(ref o) => one_test(
+                    get_string(o, "description"),
+                    get_string(o, "decoded"),
+                    get_string(o, "encoded")
+                ),
+                _ => panic!(),
+            }
+        },
+        other => panic!("{:?}", other)
+    }
+}

+ 0 - 0
src/punycode_tests.json → tests/punycode_tests.json


+ 2 - 1
src/tests.rs → tests/tests.rs

@@ -6,10 +6,11 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+extern crate url;
 
 use std::char;
 use std::net::{Ipv4Addr, Ipv6Addr};
-use super::{UrlParser, Url, SchemeData, RelativeSchemeData, Host};
+use url::{UrlParser, Url, SchemeData, RelativeSchemeData, Host};
 
 
 #[test]

+ 0 - 0
src/urltestdata.txt → tests/urltestdata.txt