Add vCard X-label tests
This commit is contained in:
@@ -116,6 +116,7 @@ const VCARD_VARIANTS: &[fn(usize) -> String] = &[
|
||||
vcard_v4_with_address,
|
||||
vcard_v4_nickname,
|
||||
vcard_v4_birthday,
|
||||
vcard_v3_apple_item_labels,
|
||||
];
|
||||
|
||||
fn synth_vcards(n: usize) -> Vec<RawFixture> {
|
||||
@@ -240,6 +241,22 @@ fn vcard_v4_birthday(i: usize) -> String {
|
||||
)
|
||||
}
|
||||
|
||||
fn vcard_v3_apple_item_labels(i: usize) -> String {
|
||||
format!(
|
||||
"BEGIN:VCARD\r\n\
|
||||
VERSION:3.0\r\n\
|
||||
UID:vandelay-card-ablabels-{i}\r\n\
|
||||
FN:Apple Labels {i}\r\n\
|
||||
N:Contact{i};AppleLabels;;;\r\n\
|
||||
EMAIL;TYPE=INTERNET:ablabels-{i}@vandelay.test\r\n\
|
||||
ITEM1.X-ABLABEL:Name1\r\n\
|
||||
ITEM2.X-ABLABEL:Name2\r\n\
|
||||
ITEM1.X-ABDATE:20171111\r\n\
|
||||
ITEM2.X-ABDATE:20111111\r\n\
|
||||
END:VCARD\r\n"
|
||||
)
|
||||
}
|
||||
|
||||
const ICAL_VARIANTS: &[fn(usize) -> String] = &[
|
||||
ical_simple_dt,
|
||||
ical_all_day,
|
||||
|
||||
@@ -324,6 +324,22 @@ fn component_top_level_properties(text: &str, name: &str) -> Vec<String> {
|
||||
out
|
||||
}
|
||||
|
||||
pub fn grouped_property_values(text: &str, name: &str) -> Vec<String> {
|
||||
let unfolded = unfold_text(text);
|
||||
let mut out = Vec::new();
|
||||
for line in unfolded.lines() {
|
||||
let l = line.trim_end_matches('\r');
|
||||
let Some(colon) = l.find(':') else { continue };
|
||||
let head = &l[..colon];
|
||||
let name_part = head.split(';').next().unwrap_or(head);
|
||||
let bare = name_part.rsplit('.').next().unwrap_or(name_part);
|
||||
if bare.eq_ignore_ascii_case(name) {
|
||||
out.push(l[colon + 1..].to_owned());
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
pub fn has_line_prefix(text: &str, prefix: &str) -> bool {
|
||||
let unfolded = unfold_text(text);
|
||||
unfolded.lines().any(|l| l.starts_with(prefix))
|
||||
@@ -540,6 +556,15 @@ pub fn assert_contact_round_trip(conn: &Connection, source: &[u8], uid: &str, la
|
||||
);
|
||||
}
|
||||
|
||||
for label_name in ["X-ABLABEL", "X-ABDATE"] {
|
||||
for value in grouped_property_values(text, label_name) {
|
||||
assert!(
|
||||
json_contains_string(&data, &value),
|
||||
"{label}: contact {uid} {label_name} {value:?} not preserved in stored JSContact vCard roundtrip block"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(bday) = extract_property(text, "BDAY") {
|
||||
let iso = format_vcard_date_as_iso(&bday);
|
||||
let present_raw = json_contains_string(&data, &bday);
|
||||
|
||||
Reference in New Issue
Block a user