Skip to content

Commit 9b52fb8

Browse files
committed
[idna] Move unit tests to tests/unit.rs
1 parent 57ebcdf commit 9b52fb8

File tree

3 files changed

+43
-39
lines changed

3 files changed

+43
-39
lines changed

idna/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ test = false
1414
name = "tests"
1515
harness = false
1616

17+
[[test]]
18+
name = "unit"
19+
1720
[dev-dependencies]
1821
rustc-test = "0.1"
1922
rustc-serialize = "0.3"

idna/src/uts46.rs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -413,42 +413,3 @@ pub fn to_unicode(domain: &str, mut flags: Flags) -> (String, Result<(), Errors>
413413
};
414414
(domain, errors)
415415
}
416-
417-
#[cfg(test)]
418-
mod tests {
419-
use super::*;
420-
421-
fn _to_ascii(domain: &str) -> Result<String, Errors> {
422-
to_ascii(domain, Flags {
423-
transitional_processing: false,
424-
use_std3_ascii_rules: true,
425-
verify_dns_length: true,
426-
})
427-
}
428-
429-
#[test]
430-
fn test_v5() {
431-
// IdnaTest:784 蔏。𑰺
432-
assert!(is_combining_mark('\u{11C3A}'));
433-
assert!(_to_ascii("\u{11C3A}").is_err());
434-
assert!(_to_ascii("\u{850f}.\u{11C3A}").is_err());
435-
assert!(_to_ascii("\u{850f}\u{ff61}\u{11C3A}").is_err());
436-
}
437-
438-
#[test]
439-
fn test_v8_bidi_rules() {
440-
assert_eq!(_to_ascii("abc").unwrap(), "abc");
441-
assert_eq!(_to_ascii("123").unwrap(), "123");
442-
assert_eq!(_to_ascii("אבּג").unwrap(), "xn--kdb3bdf");
443-
assert_eq!(_to_ascii("ابج").unwrap(), "xn--mgbcm");
444-
assert_eq!(_to_ascii("abc.ابج").unwrap(), "abc.xn--mgbcm");
445-
assert_eq!(_to_ascii("אבּג.ابج").unwrap(), "xn--kdb3bdf.xn--mgbcm");
446-
447-
// Bidi domain names cannot start with digits
448-
assert!(_to_ascii("0a.\u{05D0}").is_err());
449-
assert!(_to_ascii("0à.\u{05D0}").is_err());
450-
451-
// Bidi chars may be punycode-encoded
452-
assert!(_to_ascii("xn--0ca24w").is_err());
453-
}
454-
}

idna/tests/unit.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
extern crate idna;
2+
extern crate unicode_normalization;
3+
4+
use idna::uts46;
5+
use unicode_normalization::char::is_combining_mark;
6+
7+
8+
fn _to_ascii(domain: &str) -> Result<String, uts46::Errors> {
9+
uts46::to_ascii(domain, uts46::Flags {
10+
transitional_processing: false,
11+
use_std3_ascii_rules: true,
12+
verify_dns_length: true,
13+
})
14+
}
15+
16+
#[test]
17+
fn test_v5() {
18+
// IdnaTest:784 蔏。𑰺
19+
assert!(is_combining_mark('\u{11C3A}'));
20+
assert!(_to_ascii("\u{11C3A}").is_err());
21+
assert!(_to_ascii("\u{850f}.\u{11C3A}").is_err());
22+
assert!(_to_ascii("\u{850f}\u{ff61}\u{11C3A}").is_err());
23+
}
24+
25+
#[test]
26+
fn test_v8_bidi_rules() {
27+
assert_eq!(_to_ascii("abc").unwrap(), "abc");
28+
assert_eq!(_to_ascii("123").unwrap(), "123");
29+
assert_eq!(_to_ascii("אבּג").unwrap(), "xn--kdb3bdf");
30+
assert_eq!(_to_ascii("ابج").unwrap(), "xn--mgbcm");
31+
assert_eq!(_to_ascii("abc.ابج").unwrap(), "abc.xn--mgbcm");
32+
assert_eq!(_to_ascii("אבּג.ابج").unwrap(), "xn--kdb3bdf.xn--mgbcm");
33+
34+
// Bidi domain names cannot start with digits
35+
assert!(_to_ascii("0a.\u{05D0}").is_err());
36+
assert!(_to_ascii("0à.\u{05D0}").is_err());
37+
38+
// Bidi chars may be punycode-encoded
39+
assert!(_to_ascii("xn--0ca24w").is_err());
40+
}

0 commit comments

Comments
 (0)