RPM build fix (reverted CI changes which will need to be un-reverted or made conditional) and vendor Rust dependencies to make builds much faster in any CI system.
This commit is contained in:
6334
zeroidc/vendor/idna/tests/IdnaTestV2.txt
vendored
Normal file
6334
zeroidc/vendor/idna/tests/IdnaTestV2.txt
vendored
Normal file
File diff suppressed because it is too large
Load Diff
77
zeroidc/vendor/idna/tests/punycode.rs
vendored
Normal file
77
zeroidc/vendor/idna/tests/punycode.rs
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
// 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.
|
||||
|
||||
use crate::test::TestFn;
|
||||
use idna::punycode::{decode, encode_str};
|
||||
use serde_json::map::Map;
|
||||
use serde_json::Value;
|
||||
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 encode_str(decoded) {
|
||||
None => panic!("Encoding {} failed.", decoded),
|
||||
Some(result) => assert!(
|
||||
result == encoded,
|
||||
"Incorrect encoding of \"{}\":\n \"{}\"\n!= \"{}\"\n",
|
||||
decoded,
|
||||
result,
|
||||
encoded
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_string<'a>(map: &'a Map<String, Value>, key: &str) -> &'a str {
|
||||
match map.get(&key.to_string()) {
|
||||
Some(&Value::String(ref s)) => s,
|
||||
None => "",
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn collect_tests<F: FnMut(String, TestFn)>(add_test: &mut F) {
|
||||
match Value::from_str(include_str!("punycode_tests.json")) {
|
||||
Ok(Value::Array(tests)) => {
|
||||
for (i, test) in tests.into_iter().enumerate() {
|
||||
match test {
|
||||
Value::Object(o) => {
|
||||
let test_name = {
|
||||
let desc = get_string(&o, "description");
|
||||
if desc.is_empty() {
|
||||
format!("Punycode {}", i + 1)
|
||||
} else {
|
||||
format!("Punycode {}: {}", i + 1, desc)
|
||||
}
|
||||
};
|
||||
add_test(
|
||||
test_name,
|
||||
TestFn::dyn_test_fn(move || {
|
||||
one_test(get_string(&o, "decoded"), get_string(&o, "encoded"))
|
||||
}),
|
||||
)
|
||||
}
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
other => panic!("{:?}", other),
|
||||
}
|
||||
}
|
||||
120
zeroidc/vendor/idna/tests/punycode_tests.json
vendored
Normal file
120
zeroidc/vendor/idna/tests/punycode_tests.json
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
[
|
||||
{
|
||||
"description": "These tests are copied from https://github.com/bestiejs/punycode.js/blob/master/tests/tests.js , used under the MIT license.",
|
||||
"decoded": "",
|
||||
"encoded": ""
|
||||
},
|
||||
{
|
||||
"description": "a single basic code point",
|
||||
"decoded": "Bach",
|
||||
"encoded": "Bach-"
|
||||
},
|
||||
{
|
||||
"description": "a single non-ASCII character",
|
||||
"decoded": "\u00FC",
|
||||
"encoded": "tda"
|
||||
},
|
||||
{
|
||||
"description": "multiple non-ASCII characters",
|
||||
"decoded": "\u00FC\u00EB\u00E4\u00F6\u2665",
|
||||
"encoded": "4can8av2009b"
|
||||
},
|
||||
{
|
||||
"description": "mix of ASCII and non-ASCII characters",
|
||||
"decoded": "b\u00FCcher",
|
||||
"encoded": "bcher-kva"
|
||||
},
|
||||
{
|
||||
"description": "long string with both ASCII and non-ASCII characters",
|
||||
"decoded": "Willst du die Bl\u00FCthe des fr\u00FChen, die Fr\u00FCchte des sp\u00E4teren Jahres",
|
||||
"encoded": "Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal"
|
||||
},
|
||||
{
|
||||
"description": "Arabic (Egyptian)",
|
||||
"decoded": "\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644\u0645\u0648\u0634\u0639\u0631\u0628\u064A\u061F",
|
||||
"encoded": "egbpdaj6bu4bxfgehfvwxn"
|
||||
},
|
||||
{
|
||||
"description": "Chinese (simplified)",
|
||||
"decoded": "\u4ED6\u4EEC\u4E3A\u4EC0\u4E48\u4E0D\u8BF4\u4E2d\u6587",
|
||||
"encoded": "ihqwcrb4cv8a8dqg056pqjye"
|
||||
},
|
||||
{
|
||||
"description": "Chinese (traditional)",
|
||||
"decoded": "\u4ED6\u5011\u7232\u4EC0\u9EBD\u4E0D\u8AAA\u4E2D\u6587",
|
||||
"encoded": "ihqwctvzc91f659drss3x8bo0yb"
|
||||
},
|
||||
{
|
||||
"description": "Czech",
|
||||
"decoded": "Pro\u010Dprost\u011Bnemluv\u00ED\u010Desky",
|
||||
"encoded": "Proprostnemluvesky-uyb24dma41a"
|
||||
},
|
||||
{
|
||||
"description": "Hebrew",
|
||||
"decoded": "\u05DC\u05DE\u05D4\u05D4\u05DD\u05E4\u05E9\u05D5\u05D8\u05DC\u05D0\u05DE\u05D3\u05D1\u05E8\u05D9\u05DD\u05E2\u05D1\u05E8\u05D9\u05EA",
|
||||
"encoded": "4dbcagdahymbxekheh6e0a7fei0b"
|
||||
},
|
||||
{
|
||||
"description": "Hindi (Devanagari)",
|
||||
"decoded": "\u092F\u0939\u0932\u094B\u0917\u0939\u093F\u0928\u094D\u0926\u0940\u0915\u094D\u092F\u094B\u0902\u0928\u0939\u0940\u0902\u092C\u094B\u0932\u0938\u0915\u0924\u0947\u0939\u0948\u0902",
|
||||
"encoded": "i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd"
|
||||
},
|
||||
{
|
||||
"description": "Japanese (kanji and hiragana)",
|
||||
"decoded": "\u306A\u305C\u307F\u3093\u306A\u65E5\u672C\u8A9E\u3092\u8A71\u3057\u3066\u304F\u308C\u306A\u3044\u306E\u304B",
|
||||
"encoded": "n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa"
|
||||
},
|
||||
{
|
||||
"description": "Korean (Hangul syllables)",
|
||||
"decoded": "\uC138\uACC4\uC758\uBAA8\uB4E0\uC0AC\uB78C\uB4E4\uC774\uD55C\uAD6D\uC5B4\uB97C\uC774\uD574\uD55C\uB2E4\uBA74\uC5BC\uB9C8\uB098\uC88B\uC744\uAE4C",
|
||||
"encoded": "989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c"
|
||||
},
|
||||
{
|
||||
"description": "Russian (Cyrillic)",
|
||||
"decoded": "\u043F\u043E\u0447\u0435\u043C\u0443\u0436\u0435\u043E\u043D\u0438\u043D\u0435\u0433\u043E\u0432\u043E\u0440\u044F\u0442\u043F\u043E\u0440\u0443\u0441\u0441\u043A\u0438",
|
||||
"encoded": "b1abfaaepdrnnbgefbadotcwatmq2g4l"
|
||||
},
|
||||
{
|
||||
"description": "Spanish",
|
||||
"decoded": "Porqu\u00E9nopuedensimplementehablarenEspa\u00F1ol",
|
||||
"encoded": "PorqunopuedensimplementehablarenEspaol-fmd56a"
|
||||
},
|
||||
{
|
||||
"description": "Vietnamese",
|
||||
"decoded": "T\u1EA1isaoh\u1ECDkh\u00F4ngth\u1EC3ch\u1EC9n\u00F3iti\u1EBFngVi\u1EC7t",
|
||||
"encoded": "TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g"
|
||||
},
|
||||
{
|
||||
"decoded": "3\u5E74B\u7D44\u91D1\u516B\u5148\u751F",
|
||||
"encoded": "3B-ww4c5e180e575a65lsy2b"
|
||||
},
|
||||
{
|
||||
"decoded": "\u5B89\u5BA4\u5948\u7F8E\u6075-with-SUPER-MONKEYS",
|
||||
"encoded": "-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n"
|
||||
},
|
||||
{
|
||||
"decoded": "Hello-Another-Way-\u305D\u308C\u305E\u308C\u306E\u5834\u6240",
|
||||
"encoded": "Hello-Another-Way--fc4qua05auwb3674vfr0b"
|
||||
},
|
||||
{
|
||||
"decoded": "\u3072\u3068\u3064\u5C4B\u6839\u306E\u4E0B2",
|
||||
"encoded": "2-u9tlzr9756bt3uc0v"
|
||||
},
|
||||
{
|
||||
"decoded": "Maji\u3067Koi\u3059\u308B5\u79D2\u524D",
|
||||
"encoded": "MajiKoi5-783gue6qz075azm5e"
|
||||
},
|
||||
{
|
||||
"decoded": "\u30D1\u30D5\u30A3\u30FCde\u30EB\u30F3\u30D0",
|
||||
"encoded": "de-jg4avhby1noc0d"
|
||||
},
|
||||
{
|
||||
"decoded": "\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067",
|
||||
"encoded": "d9juau41awczczp"
|
||||
},
|
||||
{
|
||||
"description": "ASCII string that breaks the existing rules for host-name labels (It's not a realistic example for IDNA, because IDNA never encodes pure ASCII labels.)",
|
||||
"decoded": "-> $1.00 <-",
|
||||
"encoded": "-> $1.00 <--"
|
||||
}
|
||||
]
|
||||
19
zeroidc/vendor/idna/tests/tests.rs
vendored
Normal file
19
zeroidc/vendor/idna/tests/tests.rs
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
use rustc_test as test;
|
||||
|
||||
mod punycode;
|
||||
mod uts46;
|
||||
|
||||
fn main() {
|
||||
let mut tests = Vec::new();
|
||||
{
|
||||
let mut add_test = |name, run| {
|
||||
tests.push(test::TestDescAndFn {
|
||||
desc: test::TestDesc::new(test::DynTestName(name)),
|
||||
testfn: run,
|
||||
})
|
||||
};
|
||||
punycode::collect_tests(&mut add_test);
|
||||
uts46::collect_tests(&mut add_test);
|
||||
}
|
||||
test::test_main(&std::env::args().collect::<Vec<_>>(), tests)
|
||||
}
|
||||
139
zeroidc/vendor/idna/tests/unit.rs
vendored
Normal file
139
zeroidc/vendor/idna/tests/unit.rs
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
use assert_matches::assert_matches;
|
||||
use unicode_normalization::char::is_combining_mark;
|
||||
|
||||
/// https://github.com/servo/rust-url/issues/373
|
||||
#[test]
|
||||
fn test_punycode_prefix_with_length_check() {
|
||||
let config = idna::Config::default()
|
||||
.verify_dns_length(true)
|
||||
.check_hyphens(true)
|
||||
.use_std3_ascii_rules(true);
|
||||
|
||||
assert!(config.to_ascii("xn--").is_err());
|
||||
assert!(config.to_ascii("xn---").is_err());
|
||||
assert!(config.to_ascii("xn-----").is_err());
|
||||
assert!(config.to_ascii("xn--.").is_err());
|
||||
assert!(config.to_ascii("xn--...").is_err());
|
||||
assert!(config.to_ascii(".xn--").is_err());
|
||||
assert!(config.to_ascii("...xn--").is_err());
|
||||
assert!(config.to_ascii("xn--.xn--").is_err());
|
||||
assert!(config.to_ascii("xn--.example.org").is_err());
|
||||
}
|
||||
|
||||
/// https://github.com/servo/rust-url/issues/373
|
||||
#[test]
|
||||
fn test_punycode_prefix_without_length_check() {
|
||||
let config = idna::Config::default()
|
||||
.verify_dns_length(false)
|
||||
.check_hyphens(true)
|
||||
.use_std3_ascii_rules(true);
|
||||
|
||||
assert_eq!(config.to_ascii("xn--").unwrap(), "");
|
||||
assert!(config.to_ascii("xn---").is_err());
|
||||
assert!(config.to_ascii("xn-----").is_err());
|
||||
assert_eq!(config.to_ascii("xn--.").unwrap(), ".");
|
||||
assert_eq!(config.to_ascii("xn--...").unwrap(), "...");
|
||||
assert_eq!(config.to_ascii(".xn--").unwrap(), ".");
|
||||
assert_eq!(config.to_ascii("...xn--").unwrap(), "...");
|
||||
assert_eq!(config.to_ascii("xn--.xn--").unwrap(), ".");
|
||||
assert_eq!(config.to_ascii("xn--.example.org").unwrap(), ".example.org");
|
||||
}
|
||||
|
||||
// http://www.unicode.org/reports/tr46/#Table_Example_Processing
|
||||
#[test]
|
||||
fn test_examples() {
|
||||
let mut codec = idna::Idna::default();
|
||||
let mut out = String::new();
|
||||
|
||||
assert_matches!(codec.to_unicode("Bloß.de", &mut out), Ok(()));
|
||||
assert_eq!(out, "bloß.de");
|
||||
|
||||
out.clear();
|
||||
assert_matches!(codec.to_unicode("xn--blo-7ka.de", &mut out), Ok(()));
|
||||
assert_eq!(out, "bloß.de");
|
||||
|
||||
out.clear();
|
||||
assert_matches!(codec.to_unicode("u\u{308}.com", &mut out), Ok(()));
|
||||
assert_eq!(out, "ü.com");
|
||||
|
||||
out.clear();
|
||||
assert_matches!(codec.to_unicode("xn--tda.com", &mut out), Ok(()));
|
||||
assert_eq!(out, "ü.com");
|
||||
|
||||
out.clear();
|
||||
assert_matches!(codec.to_unicode("xn--u-ccb.com", &mut out), Err(_));
|
||||
|
||||
out.clear();
|
||||
assert_matches!(codec.to_unicode("a⒈com", &mut out), Err(_));
|
||||
|
||||
out.clear();
|
||||
assert_matches!(codec.to_unicode("xn--a-ecp.ru", &mut out), Err(_));
|
||||
|
||||
out.clear();
|
||||
assert_matches!(codec.to_unicode("xn--0.pt", &mut out), Err(_));
|
||||
|
||||
out.clear();
|
||||
assert_matches!(codec.to_unicode("日本語。JP", &mut out), Ok(()));
|
||||
assert_eq!(out, "日本語.jp");
|
||||
|
||||
out.clear();
|
||||
assert_matches!(codec.to_unicode("☕.us", &mut out), Ok(()));
|
||||
assert_eq!(out, "☕.us");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_v5() {
|
||||
let config = idna::Config::default()
|
||||
.verify_dns_length(true)
|
||||
.use_std3_ascii_rules(true);
|
||||
|
||||
// IdnaTest:784 蔏。𑰺
|
||||
assert!(is_combining_mark('\u{11C3A}'));
|
||||
assert!(config.to_ascii("\u{11C3A}").is_err());
|
||||
assert!(config.to_ascii("\u{850f}.\u{11C3A}").is_err());
|
||||
assert!(config.to_ascii("\u{850f}\u{ff61}\u{11C3A}").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_v8_bidi_rules() {
|
||||
let config = idna::Config::default()
|
||||
.verify_dns_length(true)
|
||||
.use_std3_ascii_rules(true);
|
||||
|
||||
assert_eq!(config.to_ascii("abc").unwrap(), "abc");
|
||||
assert_eq!(config.to_ascii("123").unwrap(), "123");
|
||||
assert_eq!(config.to_ascii("אבּג").unwrap(), "xn--kdb3bdf");
|
||||
assert_eq!(config.to_ascii("ابج").unwrap(), "xn--mgbcm");
|
||||
assert_eq!(config.to_ascii("abc.ابج").unwrap(), "abc.xn--mgbcm");
|
||||
assert_eq!(config.to_ascii("אבּג.ابج").unwrap(), "xn--kdb3bdf.xn--mgbcm");
|
||||
|
||||
// Bidi domain names cannot start with digits
|
||||
assert!(config.to_ascii("0a.\u{05D0}").is_err());
|
||||
assert!(config.to_ascii("0à.\u{05D0}").is_err());
|
||||
|
||||
// Bidi chars may be punycode-encoded
|
||||
assert!(config.to_ascii("xn--0ca24w").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn emoji_domains() {
|
||||
// HOT BEVERAGE is allowed here...
|
||||
let config = idna::Config::default()
|
||||
.verify_dns_length(true)
|
||||
.use_std3_ascii_rules(true);
|
||||
assert_eq!(config.to_ascii("☕.com").unwrap(), "xn--53h.com");
|
||||
|
||||
// ... but not here
|
||||
let config = idna::Config::default()
|
||||
.verify_dns_length(true)
|
||||
.use_std3_ascii_rules(true)
|
||||
.use_idna_2008_rules(true);
|
||||
let error = format!("{:?}", config.to_ascii("☕.com").unwrap_err());
|
||||
assert!(error.contains("disallowed_in_idna_2008"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unicode_before_delimiter() {
|
||||
let config = idna::Config::default();
|
||||
assert!(config.to_ascii("xn--f\u{34a}-PTP").is_err());
|
||||
}
|
||||
193
zeroidc/vendor/idna/tests/uts46.rs
vendored
Normal file
193
zeroidc/vendor/idna/tests/uts46.rs
vendored
Normal file
@@ -0,0 +1,193 @@
|
||||
// Copyright 2013-2014 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.
|
||||
|
||||
use crate::test::TestFn;
|
||||
use std::char;
|
||||
|
||||
use idna::Errors;
|
||||
|
||||
pub fn collect_tests<F: FnMut(String, TestFn)>(add_test: &mut F) {
|
||||
// https://www.unicode.org/Public/idna/13.0.0/IdnaTestV2.txt
|
||||
for (i, line) in include_str!("IdnaTestV2.txt").lines().enumerate() {
|
||||
if line.is_empty() || line.starts_with('#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove comments
|
||||
let line = match line.find('#') {
|
||||
Some(index) => &line[0..index],
|
||||
None => line,
|
||||
};
|
||||
|
||||
let mut pieces = line.split(';').map(|x| x.trim()).collect::<Vec<&str>>();
|
||||
let source = unescape(&pieces.remove(0));
|
||||
|
||||
// ToUnicode
|
||||
let mut to_unicode = unescape(&pieces.remove(0));
|
||||
if to_unicode.is_empty() {
|
||||
to_unicode = source.clone();
|
||||
}
|
||||
let to_unicode_status = status(pieces.remove(0));
|
||||
|
||||
// ToAsciiN
|
||||
let to_ascii_n = pieces.remove(0);
|
||||
let to_ascii_n = if to_ascii_n.is_empty() {
|
||||
to_unicode.clone()
|
||||
} else {
|
||||
to_ascii_n.to_owned()
|
||||
};
|
||||
let to_ascii_n_status = pieces.remove(0);
|
||||
let to_ascii_n_status = if to_ascii_n_status.is_empty() {
|
||||
to_unicode_status.clone()
|
||||
} else {
|
||||
status(to_ascii_n_status)
|
||||
};
|
||||
|
||||
// ToAsciiT
|
||||
let to_ascii_t = pieces.remove(0);
|
||||
let to_ascii_t = if to_ascii_t.is_empty() {
|
||||
to_ascii_n.clone()
|
||||
} else {
|
||||
to_ascii_t.to_owned()
|
||||
};
|
||||
let to_ascii_t_status = pieces.remove(0);
|
||||
let to_ascii_t_status = if to_ascii_t_status.is_empty() {
|
||||
to_ascii_n_status.clone()
|
||||
} else {
|
||||
status(to_ascii_t_status)
|
||||
};
|
||||
|
||||
let test_name = format!("UTS #46 line {}", i + 1);
|
||||
add_test(
|
||||
test_name,
|
||||
TestFn::dyn_test_fn(move || {
|
||||
let config = idna::Config::default()
|
||||
.use_std3_ascii_rules(true)
|
||||
.verify_dns_length(true)
|
||||
.check_hyphens(true);
|
||||
|
||||
// http://unicode.org/reports/tr46/#Deviations
|
||||
// applications that perform IDNA2008 lookup are not required to check
|
||||
// for these contexts, so we skip all tests annotated with C*
|
||||
|
||||
// Everybody ignores V2
|
||||
// https://github.com/servo/rust-url/pull/240
|
||||
// https://github.com/whatwg/url/issues/53#issuecomment-181528158
|
||||
// http://www.unicode.org/review/pri317/
|
||||
|
||||
// "The special error codes X3 and X4_2 are now returned where a toASCII error code
|
||||
// was formerly being generated in toUnicode due to an empty label."
|
||||
// This is not implemented yet, so we skip toUnicode X4_2 tests for now, too.
|
||||
|
||||
let (to_unicode_value, to_unicode_result) =
|
||||
config.transitional_processing(false).to_unicode(&source);
|
||||
let to_unicode_result = to_unicode_result.map(|()| to_unicode_value);
|
||||
check(
|
||||
&source,
|
||||
(&to_unicode, &to_unicode_status),
|
||||
to_unicode_result,
|
||||
|e| e.starts_with('C') || e == "V2" || e == "X4_2",
|
||||
);
|
||||
|
||||
let to_ascii_n_result = config.transitional_processing(false).to_ascii(&source);
|
||||
check(
|
||||
&source,
|
||||
(&to_ascii_n, &to_ascii_n_status),
|
||||
to_ascii_n_result,
|
||||
|e| e.starts_with('C') || e == "V2",
|
||||
);
|
||||
|
||||
let to_ascii_t_result = config.transitional_processing(true).to_ascii(&source);
|
||||
check(
|
||||
&source,
|
||||
(&to_ascii_t, &to_ascii_t_status),
|
||||
to_ascii_t_result,
|
||||
|e| e.starts_with('C') || e == "V2",
|
||||
);
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::redundant_clone)]
|
||||
fn check<F>(source: &str, expected: (&str, &[&str]), actual: Result<String, Errors>, ignore: F)
|
||||
where
|
||||
F: Fn(&str) -> bool,
|
||||
{
|
||||
if !expected.1.is_empty() {
|
||||
if !expected.1.iter().copied().any(ignore) {
|
||||
let res = actual.ok();
|
||||
assert_eq!(
|
||||
res.clone(),
|
||||
None,
|
||||
"Expected error {:?}. result: {} | source: {}",
|
||||
expected.1,
|
||||
res.unwrap(),
|
||||
source,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
assert!(
|
||||
actual.is_ok(),
|
||||
"Couldn't parse {} | error: {:?}",
|
||||
source,
|
||||
actual.err().unwrap(),
|
||||
);
|
||||
assert_eq!(actual.unwrap(), expected.0, "source: {}", source);
|
||||
}
|
||||
}
|
||||
|
||||
fn unescape(input: &str) -> String {
|
||||
let mut output = String::new();
|
||||
let mut chars = input.chars();
|
||||
loop {
|
||||
match chars.next() {
|
||||
None => return output,
|
||||
Some(c) => {
|
||||
if c == '\\' {
|
||||
match chars.next().unwrap() {
|
||||
'\\' => output.push('\\'),
|
||||
'u' => {
|
||||
let c1 = chars.next().unwrap().to_digit(16).unwrap();
|
||||
let c2 = chars.next().unwrap().to_digit(16).unwrap();
|
||||
let c3 = chars.next().unwrap().to_digit(16).unwrap();
|
||||
let c4 = chars.next().unwrap().to_digit(16).unwrap();
|
||||
match char::from_u32(((c1 * 16 + c2) * 16 + c3) * 16 + c4) {
|
||||
Some(c) => output.push(c),
|
||||
None => {
|
||||
output
|
||||
.push_str(&format!("\\u{:X}{:X}{:X}{:X}", c1, c2, c3, c4));
|
||||
}
|
||||
};
|
||||
}
|
||||
_ => panic!("Invalid test data input"),
|
||||
}
|
||||
} else {
|
||||
output.push(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn status(status: &str) -> Vec<&str> {
|
||||
if status.is_empty() || status == "[]" {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
let mut result = status.split(", ").collect::<Vec<_>>();
|
||||
assert!(result[0].starts_with('['));
|
||||
result[0] = &result[0][1..];
|
||||
|
||||
let idx = result.len() - 1;
|
||||
let last = &mut result[idx];
|
||||
assert!(last.ends_with(']'));
|
||||
*last = &last[..last.len() - 1];
|
||||
|
||||
result
|
||||
}
|
||||
Reference in New Issue
Block a user