|
@@ -8,11 +8,11 @@
|
|
|
|
|
|
|
|
use std::char;
|
|
use std::char;
|
|
|
use idna::uts46;
|
|
use idna::uts46;
|
|
|
|
|
+use test::TestFn;
|
|
|
|
|
|
|
|
-#[test]
|
|
|
|
|
-fn test_uts46() {
|
|
|
|
|
|
|
+pub fn collect_tests<F: FnMut(String, TestFn)>(add_test: &mut F) {
|
|
|
// http://www.unicode.org/Public/idna/latest/IdnaTest.txt
|
|
// http://www.unicode.org/Public/idna/latest/IdnaTest.txt
|
|
|
- for line in include_str!("IdnaTest.txt").lines() {
|
|
|
|
|
|
|
+ for (i, line) in include_str!("IdnaTest.txt").lines().enumerate() {
|
|
|
if line == "" || line.starts_with("#") {
|
|
if line == "" || line.starts_with("#") {
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
@@ -35,47 +35,54 @@ fn test_uts46() {
|
|
|
let source = unescape(original);
|
|
let source = unescape(original);
|
|
|
let to_unicode = pieces.remove(0);
|
|
let to_unicode = pieces.remove(0);
|
|
|
let to_ascii = pieces.remove(0);
|
|
let to_ascii = pieces.remove(0);
|
|
|
- let _nv8 = if pieces.len() > 0 { pieces.remove(0) } else { "" };
|
|
|
|
|
|
|
+ let nv8 = if pieces.len() > 0 { pieces.remove(0) } else { "" };
|
|
|
|
|
|
|
|
if expected_failure {
|
|
if expected_failure {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let result = uts46::to_ascii(&source, uts46::Flags {
|
|
|
|
|
- use_std3_ascii_rules: true,
|
|
|
|
|
- transitional_processing: test_type == "T",
|
|
|
|
|
- verify_dns_length: true,
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ let test_name = format!("UTS #46 line {}", i + 1);
|
|
|
|
|
+ add_test(test_name, TestFn::dyn_test_fn(move || {
|
|
|
|
|
+ let result = uts46::to_ascii(&source, uts46::Flags {
|
|
|
|
|
+ use_std3_ascii_rules: true,
|
|
|
|
|
+ transitional_processing: test_type == "T",
|
|
|
|
|
+ verify_dns_length: true,
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- if to_ascii.starts_with("[") {
|
|
|
|
|
- if to_ascii.starts_with("[C") {
|
|
|
|
|
- // http://unicode.org/reports/tr46/#Deviations
|
|
|
|
|
- // applications that perform IDNA2008 lookup are not required to check for these contexts
|
|
|
|
|
- continue;
|
|
|
|
|
|
|
+ if to_ascii.starts_with("[") {
|
|
|
|
|
+ if to_ascii.starts_with("[C") {
|
|
|
|
|
+ // http://unicode.org/reports/tr46/#Deviations
|
|
|
|
|
+ // applications that perform IDNA2008 lookup are not required to check
|
|
|
|
|
+ // for these contexts
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ let res = result.ok();
|
|
|
|
|
+ assert!(res == None, "Expected error. result: {} | original: {} | source: {}",
|
|
|
|
|
+ res.unwrap(), original, source);
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- let res = result.ok();
|
|
|
|
|
- assert!(res == None, "Expected error. result: {} | original: {} | source: {}", res.unwrap(), original, source);
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- let to_ascii = if to_ascii.len() > 0 {
|
|
|
|
|
- to_ascii.to_string()
|
|
|
|
|
- } else {
|
|
|
|
|
- if to_unicode.len() > 0 {
|
|
|
|
|
- to_unicode.to_string()
|
|
|
|
|
|
|
+ let to_ascii = if to_ascii.len() > 0 {
|
|
|
|
|
+ to_ascii.to_string()
|
|
|
} else {
|
|
} else {
|
|
|
- source.clone()
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ if to_unicode.len() > 0 {
|
|
|
|
|
+ to_unicode.to_string()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ source.clone()
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- if _nv8 == "NV8" {
|
|
|
|
|
- // This result isn't valid under IDNA2008. Skip it
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if nv8 == "NV8" {
|
|
|
|
|
+ // This result isn't valid under IDNA2008. Skip it
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- assert!(result.is_ok(), "Couldn't parse {} | original: {} | error: {:?}", source, original, result.err());
|
|
|
|
|
- let output = result.ok().unwrap();
|
|
|
|
|
- assert!(output == to_ascii, "result: {} | expected: {} | original: {} | source: {}", output, to_ascii, original, source);
|
|
|
|
|
|
|
+ assert!(result.is_ok(), "Couldn't parse {} | original: {} | error: {:?}",
|
|
|
|
|
+ source, original, result.err());
|
|
|
|
|
+ let output = result.ok().unwrap();
|
|
|
|
|
+ assert!(output == to_ascii, "result: {} | expected: {} | original: {} | source: {}",
|
|
|
|
|
+ output, to_ascii, original, source);
|
|
|
|
|
+ }))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|