Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_mail/tests/parser_compare.rs

3.1 KiB, 1 run

created by r1870400018:74950, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1//! Every corpus message through the reader as it stood before the `fe2o3_text::mime` walker
2//! (d81121d5) and the reader now. Each field that differs must be listed in `FIXED`, with the
3//! case it belongs to: an unlisted difference is a regression, a listed one that no longer
4//! differs is a stale entry.
5
6mod mime_corpus;
7
8use crate::mime_corpus::{
9 corpus,
10 old_message,
11};
12
13use oxedyne_fe2o3_mail::message::ParsedMessage;
14
15
16const FIXED: &[(&str, &str)] = &[
17 // An inline image under `mixed` is listed, as the old reader listed it under `related`.
18 ("05 outlook mixed>alt>related+pdf", "attach"),
19 // Latin-1, Windows-1252 and 8-bit bodies transcoded, not replaced by U+FFFD.
20 ("10 qp latin1", "body"),
21 ("12 cp1252", "body"),
22 ("33 8bit latin1", "body"),
23 // The parts of a `mixed` in order: the body and the list footer after it.
24 ("19 mailman footer after related", "body"),
25 ("19 mailman footer after related", "attach"),
26 ("19b mailman footer after alt", "body"),
27 ("19c mailman footer after html", "body"),
28 ("34 plain part with name only (no disposition)", "body"),
29 // RFC 2231 file name decoded.
30 ("21 rfc2231", "attach"),
31 // The bounced message is the bounce's one attachment, named by its Subject.
32 ("23 bounce report", "attach"),
33 // An attached text file is not the body.
34 ("24 txt attachment + html", "body"),
35 // `boundary = "SP"` read; a delimiter only at the start of a line.
36 ("28 boundary = spaced", "body"),
37 ("35 boundary mid-line", "body"),
38];
39
40#[test]
41fn only_the_listed_fields_differ_from_the_old_reader() {
42 let mut found = Vec::new();
43 for (name, raw) in corpus() {
44 let o = old_message::ParsedMessage::parse(&raw);
45 let n = ParsedMessage::parse(&raw);
46 let fields = [
47 ("from", o.from.clone(), n.from.clone()),
48 ("subject", o.subject.clone(), n.subject.clone()),
49 ("date", o.date.clone(), n.date.clone()),
50 ("msgid", o.message_id.clone(), n.message_id.clone()),
51 ("body", o.body.clone(), n.body.clone()),
52 ("attach", format!("{:?}", o.attachments), format!("{:?}", n.attachments)),
53 ];
54 for (f, a, b) in fields {
55 if a != b {
56 eprintln!("{} {}\n OLD {:?}\n NEW {:?}", name, f, a, b);
57 found.push((name, f));
58 }
59 }
60 }
61 eprintln!("corpus {} messages, {} field differences", corpus().len(), found.len());
62 let unlisted: Vec<_> = found.iter().filter(|d| !FIXED.contains(d)).collect();
63 let stale: Vec<_> = FIXED.iter().filter(|d| !found.contains(d)).collect();
64 assert!(unlisted.is_empty(), "differences not listed as fixes: {:?}", unlisted);
65 assert!(stale.is_empty(), "listed fixes that no longer differ: {:?}", stale);
66}