Automatically provide a resource reader for tests

This commit is contained in:
Paul Rouget 2018-04-30 22:19:33 +08:00
parent bf667677f7
commit e02a23b2f6
20 changed files with 72 additions and 109 deletions

View file

@ -2,17 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
extern crate embedder_traits;
extern crate net_traits;
use embedder_traits::resources::register_resources_for_tests;
use net_traits::pub_domains::{is_pub_domain, is_reg_domain, pub_suffix, reg_suffix};
// These tests may need to be updated if the PSL changes.
#[test]
fn test_is_pub_domain_plain() {
register_resources_for_tests();
assert!(is_pub_domain("com"));
assert!(is_pub_domain(".org"));
assert!(is_pub_domain("za.org"));
@ -22,7 +19,6 @@ fn test_is_pub_domain_plain() {
#[test]
fn test_is_pub_domain_wildcard() {
register_resources_for_tests();
assert!(is_pub_domain("hello.bd"));
assert!(is_pub_domain("world.jm"));
assert!(is_pub_domain("toto.kobe.jp"));
@ -30,7 +26,6 @@ fn test_is_pub_domain_wildcard() {
#[test]
fn test_is_pub_domain_exception() {
register_resources_for_tests();
assert_eq!(is_pub_domain("www.ck"), false);
assert_eq!(is_pub_domain("city.kawasaki.jp"), false);
assert_eq!(is_pub_domain("city.nagoya.jp"), false);
@ -39,7 +34,6 @@ fn test_is_pub_domain_exception() {
#[test]
fn test_is_pub_domain_not() {
register_resources_for_tests();
assert_eq!(is_pub_domain(""), false);
assert_eq!(is_pub_domain("."), false);
assert_eq!(is_pub_domain("..."), false);
@ -52,7 +46,6 @@ fn test_is_pub_domain_not() {
#[test]
fn test_is_pub_domain() {
register_resources_for_tests();
assert!(!is_pub_domain("city.yokohama.jp"));
assert!(!is_pub_domain("foo.bar.baz.yokohama.jp"));
assert!(!is_pub_domain("foo.bar.city.yokohama.jp"));
@ -71,7 +64,6 @@ fn test_is_pub_domain() {
#[test]
fn test_is_reg_domain() {
register_resources_for_tests();
assert!(!is_reg_domain("com"));
assert!(!is_reg_domain("foo.bar.baz.yokohama.jp"));
assert!(!is_reg_domain("foo.bar.com"));
@ -89,7 +81,6 @@ fn test_is_reg_domain() {
#[test]
fn test_pub_suffix() {
register_resources_for_tests();
assert_eq!(pub_suffix("city.yokohama.jp"), "yokohama.jp");
assert_eq!(pub_suffix("com"), "com");
assert_eq!(pub_suffix("foo.bar.baz.yokohama.jp"), "baz.yokohama.jp");
@ -107,7 +98,6 @@ fn test_pub_suffix() {
#[test]
fn test_reg_suffix() {
register_resources_for_tests();
assert_eq!(reg_suffix("city.yokohama.jp"), "city.yokohama.jp");
assert_eq!(reg_suffix("com"), "com");
assert_eq!(reg_suffix("foo.bar.baz.yokohama.jp"), "bar.baz.yokohama.jp");
@ -125,7 +115,6 @@ fn test_reg_suffix() {
#[test]
fn test_weirdness() {
register_resources_for_tests();
// These are weird results, but AFAICT they are spec-compliant.
assert_ne!(pub_suffix("city.yokohama.jp"), pub_suffix(pub_suffix("city.yokohama.jp")));
assert!(!is_pub_domain(pub_suffix("city.yokohama.jp")));