Vendor things

This commit is contained in:
John Doty 2024-03-08 11:03:01 -08:00
parent 5deceec006
commit 977e3c17e5
19434 changed files with 10682014 additions and 0 deletions

View file

@ -0,0 +1,82 @@
[
["", []],
["abcd", [105, 183, 29]],
[" abcd", [105, 183, 29]],
["abcd ", [105, 183, 29]],
[" abcd===", null],
["abcd=== ", null],
["abcd ===", null],
["a", null],
["ab", [105]],
["abc", [105, 183]],
["abcde", null],
["𐀀", null],
["=", null],
["==", null],
["===", null],
["====", null],
["=====", null],
["a=", null],
["a==", null],
["a===", null],
["a====", null],
["a=====", null],
["ab=", null],
["ab==", [105]],
["ab===", null],
["ab====", null],
["ab=====", null],
["abc=", [105, 183]],
["abc==", null],
["abc===", null],
["abc====", null],
["abc=====", null],
["abcd=", null],
["abcd==", null],
["abcd===", null],
["abcd====", null],
["abcd=====", null],
["abcde=", null],
["abcde==", null],
["abcde===", null],
["abcde====", null],
["abcde=====", null],
["=a", null],
["=a=", null],
["a=b", null],
["a=b=", null],
["ab=c", null],
["ab=c=", null],
["abc=d", null],
["abc=d=", null],
["ab\u000Bcd", null],
["ab\u3000cd", null],
["ab\u3001cd", null],
["ab\tcd", [105, 183, 29]],
["ab\ncd", [105, 183, 29]],
["ab\fcd", [105, 183, 29]],
["ab\rcd", [105, 183, 29]],
["ab cd", [105, 183, 29]],
["ab\u00a0cd", null],
["ab\t\n\f\r cd", [105, 183, 29]],
[" \t\n\f\r ab\t\n\f\r cd\t\n\f\r ", [105, 183, 29]],
["ab\t\n\f\r =\t\n\f\r =\t\n\f\r ", [105]],
["A", null],
["/A", [252]],
["//A", [255, 240]],
["///A", [255, 255, 192]],
["////A", null],
["/", null],
["A/", [3]],
["AA/", [0, 15]],
["AAAA/", null],
["AAA/", [0, 0, 63]],
["\u0000nonsense", null],
["abcd\u0000nonsense", null],
["YQ", [97]],
["YR", [97]],
["~~", null],
["..", null],
["--", null],
["__", null]
]

View file

@ -0,0 +1,214 @@
[
["data://test/,X",
"text/plain;charset=US-ASCII",
[88]],
["data://test:test/,X",
null],
["data:,X",
"text/plain;charset=US-ASCII",
[88]],
["data:",
null],
["data:text/html",
null],
["data:text/html ;charset=x ",
null],
["data:,",
"text/plain;charset=US-ASCII",
[]],
["data:,X#X",
"text/plain;charset=US-ASCII",
[88]],
["data:,%FF",
"text/plain;charset=US-ASCII",
[255]],
["data:text/plain,X",
"text/plain",
[88]],
["data:text/plain ,X",
"text/plain",
[88]],
["data:text/plain%20,X",
"text/plain%20",
[88]],
["data:text/plain\f,X",
"text/plain%0c",
[88]],
["data:text/plain%0C,X",
"text/plain%0c",
[88]],
["data:text/plain;,X",
"text/plain",
[88]],
["data:;x=x;charset=x,X",
"text/plain;x=x;charset=x",
[88]],
["data:;x=x,X",
"text/plain;x=x",
[88]],
["data:text/plain;charset=windows-1252,%C2%B1",
"text/plain;charset=windows-1252",
[194, 177]],
["data:text/plain;Charset=UTF-8,%C2%B1",
"text/plain;charset=UTF-8",
[194, 177]],
["data:text/plain;charset=windows-1252,áñçə💩",
"text/plain;charset=windows-1252",
[195, 161, 195, 177, 195, 167, 201, 153, 240, 159, 146, 169]],
["data:text/plain;charset=UTF-8,áñçə💩",
"text/plain;charset=UTF-8",
[195, 161, 195, 177, 195, 167, 201, 153, 240, 159, 146, 169]],
["data:image/gif,%C2%B1",
"image/gif",
[194, 177]],
["data:IMAGE/gif,%C2%B1",
"image/gif",
[194, 177]],
["data:IMAGE/gif;hi=x,%C2%B1",
"image/gif;hi=x",
[194, 177]],
["data:IMAGE/gif;CHARSET=x,%C2%B1",
"image/gif;charset=x",
[194, 177]],
["data: ,%FF",
"text/plain;charset=US-ASCII",
[255]],
["data:%20,%FF",
"text/plain;charset=US-ASCII",
[255]],
["data:\f,%FF",
"text/plain;charset=US-ASCII",
[255]],
["data:%1F,%FF",
"text/plain;charset=US-ASCII",
[255]],
["data:\u0000,%FF",
"text/plain;charset=US-ASCII",
[255]],
["data:%00,%FF",
"text/plain;charset=US-ASCII",
[255]],
["data:text/html ,X",
"text/html",
[88]],
["data:text / html,X",
"text/plain;charset=US-ASCII",
[88]],
["data:†,X",
"text/plain;charset=US-ASCII",
[88]],
["data:†/†,X",
"%e2%80%a0/%e2%80%a0",
[88]],
["data:X,X",
"text/plain;charset=US-ASCII",
[88]],
["data:image/png,X X",
"image/png",
[88, 32, 88]],
["data:application/javascript,X X",
"application/javascript",
[88, 32, 88]],
["data:application/xml,X X",
"application/xml",
[88, 32, 88]],
["data:text/javascript,X X",
"text/javascript",
[88, 32, 88]],
["data:text/plain,X X",
"text/plain",
[88, 32, 88]],
["data:unknown/unknown,X X",
"unknown/unknown",
[88, 32, 88]],
["data:text/plain;a=\",\",X",
"text/plain;a=\"\"",
[34, 44, 88]],
["data:text/plain;a=%2C,X",
"text/plain;a=%2C",
[88]],
["data:;base64;base64,WA",
"text/plain",
[88]],
["data:x/x;base64;base64,WA",
"x/x",
[88]],
["data:x/x;base64;charset=x,WA",
"x/x;charset=x",
[87, 65]],
["data:x/x;base64;charset=x;base64,WA",
"x/x;charset=x",
[88]],
["data:x/x;base64;base64x,WA",
"x/x",
[87, 65]],
["data:;base64,W%20A",
"text/plain;charset=US-ASCII",
[88]],
["data:;base64,W%0CA",
"text/plain;charset=US-ASCII",
[88]],
["data:x;base64x,WA",
"text/plain;charset=US-ASCII",
[87, 65]],
["data:x;base64;x,WA",
"text/plain;charset=US-ASCII",
[87, 65]],
["data:x;base64=x,WA",
"text/plain;charset=US-ASCII",
[87, 65]],
["data:; base64,WA",
"text/plain;charset=US-ASCII",
[88]],
["data:; base64,WA",
"text/plain;charset=US-ASCII",
[88]],
["data: ;charset=x ; base64,WA",
"text/plain;charset=x",
[88]],
["data:;base64;,WA",
"text/plain",
[87, 65]],
["data:;base64 ,WA",
"text/plain;charset=US-ASCII",
[88]],
["data:;base64 ,WA",
"text/plain;charset=US-ASCII",
[88]],
["data:;base 64,WA",
"text/plain",
[87, 65]],
["data:;BASe64,WA",
"text/plain;charset=US-ASCII",
[88]],
["data:;%62ase64,WA",
"text/plain",
[87, 65]],
["data:%3Bbase64,WA",
"text/plain;charset=US-ASCII",
[87, 65]],
["data:;charset=x,X",
"text/plain;charset=x",
[88]],
["data:; charset=x,X",
"text/plain;charset=x",
[88]],
["data:;charset =x,X",
"text/plain",
[88]],
["data:;charset= x,X",
"text/plain;charset=\" x\"",
[88]],
["data:;charset=,X",
"text/plain",
[88]],
["data:;charset,X",
"text/plain",
[88]],
["data:;charset=\"x\",X",
"text/plain;charset=x",
[88]],
["data:;CHARSET=\"X\",X",
"text/plain;charset=X",
[88]]
]

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,397 @@
[
"Basics",
{
"input": "text/html;charset=gbk",
"output": "text/html;charset=gbk",
"navigable": true,
"encoding": "GBK"
},
{
"input": "TEXT/HTML;CHARSET=GBK",
"output": "text/html;charset=GBK",
"navigable": true,
"encoding": "GBK"
},
"Legacy comment syntax",
{
"input": "text/html;charset=gbk(",
"output": "text/html;charset=\"gbk(\"",
"navigable": true,
"encoding": null
},
{
"input": "text/html;x=(;charset=gbk",
"output": "text/html;x=\"(\";charset=gbk",
"navigable": true,
"encoding": "GBK"
},
"Duplicate parameter",
{
"input": "text/html;charset=gbk;charset=windows-1255",
"output": "text/html;charset=gbk",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;charset=();charset=GBK",
"output": "text/html;charset=\"()\"",
"navigable": true,
"encoding": null
},
"Spaces",
{
"input": "text/html;charset =gbk",
"output": "text/html",
"navigable": true,
"encoding": null
},
{
"input": "text/html ;charset=gbk",
"output": "text/html;charset=gbk",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html; charset=gbk",
"output": "text/html;charset=gbk",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;charset= gbk",
"output": "text/html;charset=\" gbk\"",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;charset= \"gbk\"",
"output": "text/html;charset=\" \\\"gbk\\\"\"",
"navigable": true,
"encoding": null
},
"0x0B and 0x0C",
{
"input": "text/html;charset=\u000Bgbk",
"output": "text/html",
"navigable": true,
"encoding": null
},
{
"input": "text/html;charset=\u000Cgbk",
"output": "text/html",
"navigable": true,
"encoding": null
},
{
"input": "text/html;\u000Bcharset=gbk",
"output": "text/html",
"navigable": true,
"encoding": null
},
{
"input": "text/html;\u000Ccharset=gbk",
"output": "text/html",
"navigable": true,
"encoding": null
},
"Single quotes are a token, not a delimiter",
{
"input": "text/html;charset='gbk'",
"output": "text/html;charset='gbk'",
"navigable": true,
"encoding": null
},
{
"input": "text/html;charset='gbk",
"output": "text/html;charset='gbk",
"navigable": true,
"encoding": null
},
{
"input": "text/html;charset=gbk'",
"output": "text/html;charset=gbk'",
"navigable": true,
"encoding": null
},
{
"input": "text/html;charset=';charset=GBK",
"output": "text/html;charset='",
"navigable": true,
"encoding": null
},
"Invalid parameters",
{
"input": "text/html;test;charset=gbk",
"output": "text/html;charset=gbk",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;test=;charset=gbk",
"output": "text/html;charset=gbk",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;';charset=gbk",
"output": "text/html;charset=gbk",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;\";charset=gbk",
"output": "text/html;charset=gbk",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html ; ; charset=gbk",
"output": "text/html;charset=gbk",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;;;;charset=gbk",
"output": "text/html;charset=gbk",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;charset= \"\u007F;charset=GBK",
"output": "text/html;charset=GBK",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;charset=\"\u007F;charset=foo\";charset=GBK",
"output": "text/html;charset=GBK",
"navigable": true,
"encoding": "GBK"
},
"Double quotes",
{
"input": "text/html;charset=\"gbk\"",
"output": "text/html;charset=gbk",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;charset=\"gbk",
"output": "text/html;charset=gbk",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;charset=gbk\"",
"output": "text/html;charset=\"gbk\\\"\"",
"navigable": true,
"encoding": null
},
{
"input": "text/html;charset=\" gbk\"",
"output": "text/html;charset=\" gbk\"",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;charset=\"gbk \"",
"output": "text/html;charset=\"gbk \"",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;charset=\"\\ gbk\"",
"output": "text/html;charset=\" gbk\"",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;charset=\"\\g\\b\\k\"",
"output": "text/html;charset=gbk",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;charset=\"gbk\"x",
"output": "text/html;charset=gbk",
"navigable": true,
"encoding": "GBK"
},
{
"input": "text/html;charset=\"\";charset=GBK",
"output": "text/html;charset=\"\"",
"navigable": true,
"encoding": null
},
{
"input": "text/html;charset=\";charset=GBK",
"output": "text/html;charset=\";charset=GBK\"",
"navigable": true,
"encoding": null
},
"Unexpected code points",
{
"input": "text/html;charset={gbk}",
"output": "text/html;charset=\"{gbk}\"",
"navigable": true,
"encoding": null
},
"Parameter name longer than 127",
{
"input": "text/html;0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789=x;charset=gbk",
"output": "text/html;0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789=x;charset=gbk",
"navigable": true,
"encoding": "GBK"
},
"type/subtype longer than 127",
{
"input": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
"output": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
},
"Invalid names",
{
"input": "text/html;a]=bar;b[=bar;c=bar",
"output": "text/html;c=bar"
},
"Semicolons in value",
{
"input": "text/html;valid=\";\";foo=bar",
"output": "text/html;valid=\";\";foo=bar"
},
{
"input": "text/html;in]valid=\";asd=foo\";foo=bar",
"output": "text/html;foo=bar"
},
"Valid",
{
"input": "!#$%&'*+-.^_`|~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/!#$%&'*+-.^_`|~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz;!#$%&'*+-.^_`|~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=!#$%&'*+-.^_`|~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
"output": "!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz/!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz;!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz=!#$%&'*+-.^_`|~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
},
{
"input": "x/x;x=\"\t !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0080\u0081\u0082\u0083\u0084\u0085\u0086\u0087\u0088\u0089\u008A\u008B\u008C\u008D\u008E\u008F\u0090\u0091\u0092\u0093\u0094\u0095\u0096\u0097\u0098\u0099\u009A\u009B\u009C\u009D\u009E\u009F\u00A0\u00A1\u00A2\u00A3\u00A4\u00A5\u00A6\u00A7\u00A8\u00A9\u00AA\u00AB\u00AC\u00AD\u00AE\u00AF\u00B0\u00B1\u00B2\u00B3\u00B4\u00B5\u00B6\u00B7\u00B8\u00B9\u00BA\u00BB\u00BC\u00BD\u00BE\u00BF\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5\u00C6\u00C7\u00C8\u00C9\u00CA\u00CB\u00CC\u00CD\u00CE\u00CF\u00D0\u00D1\u00D2\u00D3\u00D4\u00D5\u00D6\u00D7\u00D8\u00D9\u00DA\u00DB\u00DC\u00DD\u00DE\u00DF\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5\u00E6\u00E7\u00E8\u00E9\u00EA\u00EB\u00EC\u00ED\u00EE\u00EF\u00F0\u00F1\u00F2\u00F3\u00F4\u00F5\u00F6\u00F7\u00F8\u00F9\u00FA\u00FB\u00FC\u00FD\u00FE\u00FF\"",
"output": "x/x;x=\"\t !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0080\u0081\u0082\u0083\u0084\u0085\u0086\u0087\u0088\u0089\u008A\u008B\u008C\u008D\u008E\u008F\u0090\u0091\u0092\u0093\u0094\u0095\u0096\u0097\u0098\u0099\u009A\u009B\u009C\u009D\u009E\u009F\u00A0\u00A1\u00A2\u00A3\u00A4\u00A5\u00A6\u00A7\u00A8\u00A9\u00AA\u00AB\u00AC\u00AD\u00AE\u00AF\u00B0\u00B1\u00B2\u00B3\u00B4\u00B5\u00B6\u00B7\u00B8\u00B9\u00BA\u00BB\u00BC\u00BD\u00BE\u00BF\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5\u00C6\u00C7\u00C8\u00C9\u00CA\u00CB\u00CC\u00CD\u00CE\u00CF\u00D0\u00D1\u00D2\u00D3\u00D4\u00D5\u00D6\u00D7\u00D8\u00D9\u00DA\u00DB\u00DC\u00DD\u00DE\u00DF\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5\u00E6\u00E7\u00E8\u00E9\u00EA\u00EB\u00EC\u00ED\u00EE\u00EF\u00F0\u00F1\u00F2\u00F3\u00F4\u00F5\u00F6\u00F7\u00F8\u00F9\u00FA\u00FB\u00FC\u00FD\u00FE\u00FF\""
},
"End-of-file handling",
{
"input": "x/x;test",
"output": "x/x"
},
{
"input": "x/x;test=\"\\",
"output": "x/x;test=\"\\\\\""
},
"Whitespace (not handled by generated-mime-types.json or above)",
{
"input": "x/x;x= ",
"output": "x/x"
},
{
"input": "x/x;x=\t",
"output": "x/x"
},
{
"input": "x/x\n\r\t ;x=x",
"output": "x/x;x=x"
},
{
"input": "\n\r\t x/x;x=x\n\r\t ",
"output": "x/x;x=x"
},
{
"input": "x/x;\n\r\t x=x\n\r\t ;x=y",
"output": "x/x;x=x"
},
"Latin1",
{
"input": "text/html;test=\u00FF;charset=gbk",
"output": "text/html;test=\"\u00FF\";charset=gbk",
"navigable": true,
"encoding": "GBK"
},
">Latin1",
{
"input": "x/x;test=\uFFFD;x=x",
"output": "x/x;x=x"
},
"Failure",
{
"input": "\u000Bx/x",
"output": null
},
{
"input": "\u000Cx/x",
"output": null
},
{
"input": "x/x\u000B",
"output": null
},
{
"input": "x/x\u000C",
"output": null
},
{
"input": "",
"output": null
},
{
"input": "\t",
"output": null
},
{
"input": "/",
"output": null
},
{
"input": "bogus",
"output": null
},
{
"input": "bogus/",
"output": null
},
{
"input": "bogus/ ",
"output": null
},
{
"input": "bogus/bogus/;",
"output": null
},
{
"input": "</>",
"output": null
},
{
"input": "(/)",
"output": null
},
{
"input": "ÿ/ÿ",
"output": null
},
{
"input": "text/html(;doesnot=matter",
"output": null
},
{
"input": "{/}",
"output": null
},
{
"input": "\u0100/\u0100",
"output": null
},
{
"input": "text /html",
"output": null
},
{
"input": "text/ html",
"output": null
},
{
"input": "\"text/html\"",
"output": null
}
]

167
third-party/vendor/data-url/tests/wpt.rs vendored Normal file
View file

@ -0,0 +1,167 @@
use tester as test;
#[macro_use]
extern crate serde;
fn run_data_url(
input: String,
expected_mime: Option<String>,
expected_body: Option<Vec<u8>>,
expected_panic: bool,
) {
let priorhook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |p| {
if !expected_panic {
priorhook(p);
}
}));
let url = data_url::DataUrl::process(&input);
if let Some(expected_mime) = expected_mime {
let url = url.unwrap();
let (body, _) = url.decode_to_vec().unwrap();
if expected_mime.is_empty() {
assert_eq!(url.mime_type().to_string(), "text/plain;charset=US-ASCII")
} else {
assert_eq!(url.mime_type().to_string(), expected_mime)
}
if let Some(expected_body) = expected_body {
assert_eq!(body, expected_body)
}
} else if let Ok(url) = url {
assert!(url.decode_to_vec().is_err(), "{:?}", url.mime_type())
}
}
fn collect_data_url<F>(add_test: &mut F)
where
F: FnMut(String, bool, test::TestFn),
{
let known_failures = ["data://test:test/,X"];
#[derive(Deserialize)]
#[serde(untagged)]
enum TestCase {
Two(String, Option<String>),
Three(String, Option<String>, Vec<u8>),
}
let v: Vec<TestCase> = serde_json::from_str(include_str!("data-urls.json")).unwrap();
for test in v {
let (input, expected_mime, expected_body) = match test {
TestCase::Two(i, m) => (i, m, None),
TestCase::Three(i, m, b) => (i, m, Some(b)),
};
let should_panic = known_failures.contains(&&*input);
add_test(
format!("data: URL {:?}", input),
should_panic,
test::TestFn::DynTestFn(Box::new(move || {
run_data_url(input, expected_mime, expected_body, should_panic)
})),
);
}
}
fn run_base64(input: String, expected: Option<Vec<u8>>) {
let result = data_url::forgiving_base64::decode_to_vec(input.as_bytes());
match (result, expected) {
(Ok(bytes), Some(expected)) => assert_eq!(bytes, expected),
(Ok(bytes), None) => panic!("Expected error, got {:?}", bytes),
(Err(e), Some(expected)) => panic!("Expected {:?}, got error {:?}", expected, e),
(Err(_), None) => {}
}
}
fn collect_base64<F>(add_test: &mut F)
where
F: FnMut(String, bool, test::TestFn),
{
let known_failures = [];
let v: Vec<(String, Option<Vec<u8>>)> =
serde_json::from_str(include_str!("base64.json")).unwrap();
for (input, expected) in v {
let should_panic = known_failures.contains(&&*input);
add_test(
format!("base64 {:?}", input),
should_panic,
test::TestFn::DynTestFn(Box::new(move || run_base64(input, expected))),
);
}
}
fn run_mime(input: String, expected: Option<String>) {
let result = input.parse::<data_url::mime::Mime>();
match (result, expected) {
(Ok(mime), Some(expected)) => assert_eq!(mime.to_string(), expected),
(Ok(mime), None) => panic!("Expected error, got {:?}", mime),
(Err(e), Some(expected)) => panic!("Expected {:?}, got error {:?}", expected, e),
(Err(_), None) => {}
}
}
fn collect_mime<F>(add_test: &mut F)
where
F: FnMut(String, bool, test::TestFn),
{
let known_failures = [];
#[derive(Deserialize)]
#[serde(untagged)]
enum Entry {
Comment(String),
TestCase {
input: String,
output: Option<String>,
},
}
let v: Vec<Entry> = serde_json::from_str(include_str!("mime-types.json")).unwrap();
let v2: Vec<Entry> = serde_json::from_str(include_str!("generated-mime-types.json")).unwrap();
let entries = v.into_iter().chain(v2);
let mut last_comment = None;
for entry in entries {
let (input, expected) = match entry {
Entry::TestCase { input, output } => (input, output),
Entry::Comment(s) => {
last_comment = Some(s);
continue;
}
};
let should_panic = known_failures.contains(&&*input);
add_test(
if let Some(ref s) = last_comment {
format!("MIME type {:?} {:?}", s, input)
} else {
format!("MIME type {:?}", input)
},
should_panic,
test::TestFn::DynTestFn(Box::new(move || run_mime(input, expected))),
);
}
}
fn main() {
let mut tests = Vec::new();
{
let mut add_one = |name: String, should_panic: bool, run: test::TestFn| {
let desc = test::TestDesc {
name: test::DynTestName(name),
ignore: false,
should_panic: match should_panic {
true => test::ShouldPanic::Yes,
false => test::ShouldPanic::No,
},
allow_fail: false,
test_type: test::TestType::Unknown,
};
tests.push(test::TestDescAndFn { desc, testfn: run })
};
collect_data_url(&mut add_one);
collect_base64(&mut add_one);
collect_mime(&mut add_one);
}
test::test_main(&std::env::args().collect::<Vec<_>>(), tests, None)
}