Explorar el Código

Increase Origin test coverage

Add unit tests for unicode_serialization() and is_tuple().

New test coverage:
|| ../idna/src/lib.rs: 4/6 +33.33333333333333%
|| ../idna/src/uts46.rs: 158/299 +2.341137123745818%
|| src/origin.rs: 32/37 +40.54054054054054%
|| src/parser.rs: 681/848 +0.1179245283018826%
Bram Bonné hace 5 años
padre
commit
be4809e903
Se han modificado 1 ficheros con 46 adiciones y 1 borrados
  1. 46 1
      url/tests/unit.rs

+ 46 - 1
url/tests/unit.rs

@@ -12,7 +12,7 @@ use std::borrow::Cow;
 use std::cell::{Cell, RefCell};
 use std::net::{Ipv4Addr, Ipv6Addr};
 use std::path::{Path, PathBuf};
-use url::{form_urlencoded, Host, Url};
+use url::{form_urlencoded, Host, Origin, Url};
 
 #[test]
 fn size() {
@@ -517,6 +517,51 @@ fn test_origin_hash() {
     assert_ne!(hash(&opaque_origin), hash(&other_opaque_origin));
 }
 
+#[test]
+fn test_origin_blob_equality() {
+    let origin = &Url::parse("http://example.net/").unwrap().origin();
+    let blob_origin = &Url::parse("blob:http://example.net/").unwrap().origin();
+
+    assert_eq!(origin, blob_origin);
+}
+
+#[test]
+fn test_origin_opaque() {
+    assert!(!Origin::new_opaque().is_tuple());
+    assert!(!&Url::parse("blob:malformed//").unwrap().origin().is_tuple())
+}
+
+#[test]
+fn test_origin_unicode_serialization() {
+    let unicode_urls = [
+        "http://😅.com",
+        "ftp://🙂.com"
+    ];
+    for unicode_url in &unicode_urls {
+        let origin = Url::parse(unicode_url).unwrap().origin();
+        assert_eq!(origin.unicode_serialization(), *unicode_url);
+    }
+
+    let ascii_origins = [
+        Url::parse("http://example.net/").unwrap().origin(),
+        Url::parse("http://example.net:80/").unwrap().origin(),
+        Url::parse("http://example.net:81/").unwrap().origin(),
+        Url::parse("http://example.net").unwrap().origin(),
+        Url::parse("http://example.net/hello").unwrap().origin(),
+        Url::parse("https://example.net").unwrap().origin(),
+        Url::parse("ftp://example.net").unwrap().origin(),
+        Url::parse("file://example.net").unwrap().origin(),
+        Url::parse("http://user@example.net/").unwrap().origin(),
+        Url::parse("http://user:pass@example.net/")
+            .unwrap()
+            .origin(),
+        Url::parse("http://127.0.0.1").unwrap().origin(),
+    ];
+    for ascii_origin in &ascii_origins {
+        assert_eq!(ascii_origin.ascii_serialization(), ascii_origin.unicode_serialization());
+    }
+}
+
 #[test]
 fn test_windows_unc_path() {
     if !cfg!(windows) {