// Copyright 2013 The rust-url developers. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms.
usecrate::test::TestFn; use idna::punycode::{decode, decode_to_string, encode_str}; use serde_json::map::Map; use serde_json::Value; use std::panic::catch_unwind; use std::str::FromStr;
fn one_test(decoded: &str, encoded: &str) { match decode(encoded) {
None => panic!("Decoding {} failed.", encoded),
Some(result) => { let result = result.into_iter().collect::<String>();
assert!(
result == decoded, "Incorrect decoding of \"{}\":\n \"{}\"\n!= \"{}\"\n",
encoded,
result,
decoded
)
}
}
match decode_to_string(encoded) {
None => panic!("Decoding {} failed.", encoded),
Some(result) => assert!(
result == decoded, "Incorrect decoding of \"{}\":\n \"{}\"\n!= \"{}\"\n",
encoded,
result,
decoded
),
}
match encode_str(decoded) {
None => panic!("Encoding {} failed.", decoded),
Some(result) => assert!(
result == encoded, "Incorrect encoding of \"{}\":\n \"{}\"\n!= \"{}\"\n",
decoded,
result,
encoded
),
}
}
fn one_bad_test(encode: &str) { let result = catch_unwind(|| encode_str(encode));
assert!(
matches!(&result, Ok(None)), "Should neither panic nor return Some result, but got {:?}",
result
)
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.