Browse Source

One unit tests crate.

Simon Sapin 10 năm trước cách đây
mục cha
commit
d0c2bc2783
3 tập tin đã thay đổi với 31 bổ sung31 xóa
  1. 1 2
      Cargo.toml
  2. 0 29
      tests/form_urlencoded.rs
  3. 30 0
      tests/tests.rs

+ 1 - 2
Cargo.toml

@@ -11,10 +11,9 @@ readme = "README.md"
 keywords = ["url", "parser"]
 license = "MIT/Apache-2.0"
 
-[[test]]
-name = "form_urlencoded"
 [[test]]
 name = "tests"
+
 [[test]]
 name = "wpt"
 harness = false

+ 0 - 29
tests/form_urlencoded.rs

@@ -1,29 +0,0 @@
-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);
-
-}

+ 30 - 0
tests/tests.rs

@@ -208,3 +208,33 @@ fn test_serialization() {
         assert_eq!(url.as_str(), result);
     }
 }
+
+#[test]
+fn test_form_urlencoded() {
+    use url::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() {
+    use url::form_urlencoded::*;
+
+    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);
+
+}