Debian Codegraph @

tests/wpt.rs

raw symbols SCIP
1 use testerrust-analyzer cargo tester 0.9.1 crate/ as testrust-analyzer cargo tester 0.9.1 crate/;
2
3 #[macro_use]
4 extern crate serderust-analyzer cargo data-url 0.3.2 serde/;
5
6 fn run_data_urlrust-analyzer cargo data-url 0.3.2 run_data_url().(
7 input: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
8 expected_mime: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
9 expected_body: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>,
10 expected_panic: bool,
11 ) {
12 let priorhook = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/::take_hookrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panicking/take_hook().();
13 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/::set_hookrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panicking/set_hook().(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(move |p| {
14 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().expected_panic {
15 priorhook(p);
16 }
17 }));
18 let url = data_urlrust-analyzer cargo data-url 0.3.2 crate/::DataUrlrust-analyzer cargo data-url 0.3.2 DataUrl#::processrust-analyzer cargo data-url 0.3.2 impl#[`DataUrl<'a>`]process().(&input);
19 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expected_mime) = expected_mime {
20 let url = url.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
21 let (body, _) = url.decode_to_vecrust-analyzer cargo data-url 0.3.2 impl#[`DataUrl<'a>`]decode_to_vec().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
22 if expected_mime.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
23 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(url.mime_typerust-analyzer cargo data-url 0.3.2 impl#[`DataUrl<'a>`]mime_type().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "text/plain;charset=US-ASCII")
24 } else {
25 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(url.mime_typerust-analyzer cargo data-url 0.3.2 impl#[`DataUrl<'a>`]mime_type().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), expected_mime)
26 }
27 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expected_body) = expected_body {
28 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(body, expected_body)
29 }
30 } else if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(url) = url {
31 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(url.decode_to_vecrust-analyzer cargo data-url 0.3.2 impl#[`DataUrl<'a>`]decode_to_vec().().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().(), "{:?}", url.mime_typerust-analyzer cargo data-url 0.3.2 impl#[`DataUrl<'a>`]mime_type().())
32 }
33 }
34
35 fn collect_data_urlrust-analyzer cargo data-url 0.3.2 collect_data_url().<F>(add_test: &mut F)
36 where
37 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, bool, testrust-analyzer cargo tester 0.9.1 crate/::TestFnrust-analyzer cargo tester 0.9.1 types/TestFn#),
38 {
39 let known_failures = ["data://test:test/,X"];
40
41 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.210 Deserialize:)]
42 #[serde(untagged)]
43 enum TestCaserust-analyzer cargo data-url 0.3.2 TestCase# {
44 Tworust-analyzer cargo data-url 0.3.2 TestCase#Two#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>),
45 Threerust-analyzer cargo data-url 0.3.2 TestCase#Three#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>),
46 }
47
48 let v: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<TestCaserust-analyzer cargo data-url 0.3.2 TestCase#> = serde_jsonrust-analyzer cargo serde_json 1.0.128 crate/::from_strrust-analyzer cargo serde_json 1.0.128 de/from_str().(include_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include_str!!("data-urls.json")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
49 for test in v {
50 let (input, expected_mime, expected_body) = match test {
51 TestCaserust-analyzer cargo data-url 0.3.2 TestCase#::Tworust-analyzer cargo data-url 0.3.2 TestCase#Two#(i, m) => (i, m, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
52 TestCaserust-analyzer cargo data-url 0.3.2 TestCase#::Threerust-analyzer cargo data-url 0.3.2 TestCase#Three#(i, m, b) => (i, m, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b)),
53 };
54 let should_panic = known_failures.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Deref]deref().input);
55 add_test(
56 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("data: URL {:?}", input),
57 should_panic,
58 testrust-analyzer cargo tester 0.9.1 crate/::TestFnrust-analyzer cargo tester 0.9.1 types/TestFn#::DynTestFnrust-analyzer cargo tester 0.9.1 types/TestFn#DynTestFn#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(move || {
59 run_data_urlrust-analyzer cargo data-url 0.3.2 run_data_url().(input, expected_mime, expected_body, should_panic)
60 })),
61 );
62 }
63 }
64
65 fn run_base64rust-analyzer cargo data-url 0.3.2 run_base64().(input: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, expected: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>) {
66 let result = data_urlrust-analyzer cargo data-url 0.3.2 crate/::forgiving_base64rust-analyzer cargo data-url 0.3.2 forgiving_base64/::decode_to_vecrust-analyzer cargo data-url 0.3.2 forgiving_base64/decode_to_vec().(input.as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().());
67 match (result, expected) {
68 (Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(bytes), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expected)) => assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bytes, expected),
69 (Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(bytes), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected error, got {:?}", bytes),
70 (Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expected)) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected {:?}, got error {:?}", expected, e),
71 (Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => {}
72 }
73 }
74
75 fn collect_base64rust-analyzer cargo data-url 0.3.2 collect_base64().<F>(add_test: &mut F)
76 where
77 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, bool, testrust-analyzer cargo tester 0.9.1 crate/::TestFnrust-analyzer cargo tester 0.9.1 types/TestFn#),
78 {
79 let known_failures = [];
80
81 let v: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>)> =
82 serde_jsonrust-analyzer cargo serde_json 1.0.128 crate/::from_strrust-analyzer cargo serde_json 1.0.128 de/from_str().(include_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include_str!!("base64.json")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
83 for (input, expected) in v {
84 let should_panic = known_failures.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Deref]deref().input);
85 add_test(
86 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("base64 {:?}", input),
87 should_panic,
88 testrust-analyzer cargo tester 0.9.1 crate/::TestFnrust-analyzer cargo tester 0.9.1 types/TestFn#::DynTestFnrust-analyzer cargo tester 0.9.1 types/TestFn#DynTestFn#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(move || run_base64rust-analyzer cargo data-url 0.3.2 run_base64().(input, expected))),
89 );
90 }
91 }
92
93 fn run_mimerust-analyzer cargo data-url 0.3.2 run_mime().(input: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, expected: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>) {
94 let result = input.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<data_urlrust-analyzer cargo data-url 0.3.2 crate/::mimerust-analyzer cargo data-url 0.3.2 mime/::Mimerust-analyzer cargo data-url 0.3.2 mime/Mime#>();
95 match (result, expected) {
96 (Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(mime), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expected)) => assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(mime.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), expected),
97 (Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(mime), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected error, got {:?}", mime),
98 (Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expected)) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected {:?}, got error {:?}", expected, e),
99 (Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => {}
100 }
101 }
102
103 fn collect_mimerust-analyzer cargo data-url 0.3.2 collect_mime().<F>(add_test: &mut F)
104 where
105 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, bool, testrust-analyzer cargo tester 0.9.1 crate/::TestFnrust-analyzer cargo tester 0.9.1 types/TestFn#),
106 {
107 let known_failures = [];
108
109 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.210 Deserialize:)]
110 #[serde(untagged)]
111 enum Entryrust-analyzer cargo data-url 0.3.2 Entry# {
112 Commentrust-analyzer cargo data-url 0.3.2 Entry#Comment#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
113 TestCaserust-analyzer cargo data-url 0.3.2 Entry#TestCase# {
114 inputrust-analyzer cargo data-url 0.3.2 Entry#TestCase#input.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
115 outputrust-analyzer cargo data-url 0.3.2 Entry#TestCase#output.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
116 },
117 }
118
119 let v: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Entryrust-analyzer cargo data-url 0.3.2 Entry#> = serde_jsonrust-analyzer cargo serde_json 1.0.128 crate/::from_strrust-analyzer cargo serde_json 1.0.128 de/from_str().(include_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include_str!!("mime-types.json")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
120 let v2: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Entryrust-analyzer cargo data-url 0.3.2 Entry#> = serde_jsonrust-analyzer cargo serde_json 1.0.128 crate/::from_strrust-analyzer cargo serde_json 1.0.128 de/from_str().(include_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include_str!!("generated-mime-types.json")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
121 let entries = v.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().chainrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#chain().(v2);
122
123 let mut last_comment = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
124 for entry in entries {
125 let (input, expected) = match entry {
126 Entryrust-analyzer cargo data-url 0.3.2 Entry#::TestCaserust-analyzer cargo data-url 0.3.2 Entry#TestCase# { inputrust-analyzer cargo data-url 0.3.2 Entry#TestCase#input., outputrust-analyzer cargo data-url 0.3.2 Entry#TestCase#output. } => (input, output),
127 Entryrust-analyzer cargo data-url 0.3.2 Entry#::Commentrust-analyzer cargo data-url 0.3.2 Entry#Comment#(s) => {
128 last_comment = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s);
129 continue;
130 }
131 };
132
133 let should_panic = known_failures.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Deref]deref().input);
134 add_test(
135 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref s) = last_comment {
136 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("MIME type {:?} {:?}", s, input)
137 } else {
138 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("MIME type {:?}", input)
139 },
140 should_panic,
141 testrust-analyzer cargo tester 0.9.1 crate/::TestFnrust-analyzer cargo tester 0.9.1 types/TestFn#::DynTestFnrust-analyzer cargo tester 0.9.1 types/TestFn#DynTestFn#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(move || run_mimerust-analyzer cargo data-url 0.3.2 run_mime().(input, expected))),
142 );
143 }
144 }
145
146 fn mainrust-analyzer cargo data-url 0.3.2 main().() {
147 let mut tests = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
148 {
149 let mut add_one = |name: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, should_panic: bool, run: testrust-analyzer cargo tester 0.9.1 crate/::TestFnrust-analyzer cargo tester 0.9.1 types/TestFn#| {
150 let desc = testrust-analyzer cargo tester 0.9.1 crate/::TestDescrust-analyzer cargo tester 0.9.1 types/TestDesc# {
151 namerust-analyzer cargo tester 0.9.1 types/TestDesc#name.: testrust-analyzer cargo tester 0.9.1 crate/::DynTestNamerust-analyzer cargo tester 0.9.1 types/TestName#DynTestName#(name),
152 ignorerust-analyzer cargo tester 0.9.1 types/TestDesc#ignore.: false,
153 should_panicrust-analyzer cargo tester 0.9.1 types/TestDesc#should_panic.: match should_panic {
154 true => testrust-analyzer cargo tester 0.9.1 crate/::ShouldPanicrust-analyzer cargo tester 0.9.1 options/ShouldPanic#::Yesrust-analyzer cargo tester 0.9.1 options/ShouldPanic#Yes#,
155 false => testrust-analyzer cargo tester 0.9.1 crate/::ShouldPanicrust-analyzer cargo tester 0.9.1 options/ShouldPanic#::Norust-analyzer cargo tester 0.9.1 options/ShouldPanic#No#,
156 },
157 allow_failrust-analyzer cargo tester 0.9.1 types/TestDesc#allow_fail.: false,
158 test_typerust-analyzer cargo tester 0.9.1 types/TestDesc#test_type.: testrust-analyzer cargo tester 0.9.1 crate/::TestTyperust-analyzer cargo tester 0.9.1 types/TestType#::Unknownrust-analyzer cargo tester 0.9.1 types/TestType#Unknown#,
159 };
160 tests.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(testrust-analyzer cargo tester 0.9.1 crate/::TestDescAndFnrust-analyzer cargo tester 0.9.1 types/TestDescAndFn# { descrust-analyzer cargo tester 0.9.1 types/TestDescAndFn#desc., testfnrust-analyzer cargo tester 0.9.1 types/TestDescAndFn#testfn.: run })
161 };
162 collect_data_urlrust-analyzer cargo data-url 0.3.2 collect_data_url().(&mut add_one);
163 collect_base64rust-analyzer cargo data-url 0.3.2 collect_base64().(&mut add_one);
164 collect_mimerust-analyzer cargo data-url 0.3.2 collect_mime().(&mut add_one);
165 }
166 testrust-analyzer cargo tester 0.9.1 crate/::test_mainrust-analyzer cargo tester 0.9.1 test_main().(&stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::argsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/args().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), tests, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)
167 }