Cotton code
67 lines · 2.4 KB · RustRaw
//! The shared vocabulary: what a source is called, and what "dropped" counts.use super::*;#[test]fn every_source_has_one_name_and_it_round_trips() {    for id in SourceId::ALL {        assert_eq!(SourceId::parse(id.as_str()), Some(id));    }    assert_eq!(SourceId::parse("nothing this Mac reads"), None);    assert_eq!(SourceId::CallHistory.as_str(), "callHistory");    assert_eq!(SourceId::Photos.as_str(), "photos");}#[test]fn a_cursor_key_names_its_source_so_two_readers_can_never_share_a_position() {    assert_eq!(SourceId::Photos.cursor_key("mac:finch"), "ingest:mac:finch:photos:cursor");    assert_eq!(        SourceId::CallHistory.cursor_key("mac:finch"),        "ingest:mac:finch:callHistory:cursor"    );    let keys: std::collections::BTreeSet<String> =        SourceId::ALL.iter().map(|id| id.cursor_key("mac:finch")).collect();    assert_eq!(keys.len(), SourceId::ALL.len());}#[test]fn droppped_counts_what_the_reader_threw_away_and_not_what_it_looked_at() {    let mut notes = IngestNotes::new();    count(&mut notes, "read:chats", 12);    count(&mut notes, "read:messages", 400);    count(&mut notes, "no_body", 3);    count(&mut notes, "no_body", 2);    count(&mut notes, "group_event", 1);    // A file this Mac could not find is a message that lands without its    // picture, never a message somebody lost.    count(&mut notes, "media:missing", 7);    assert_eq!(dropped_from(&notes), 6);    assert_eq!(notes.get("no_body"), Some(&5));}#[test]fn an_empty_run_dropped_nothing() {    assert_eq!(dropped_from(&IngestNotes::new()), 0);}#[test]fn a_status_serialises_in_the_words_the_panel_renders() {    let json = serde_json::to_value(SourceStatus::no_permission("ask macOS")).expect("json");    assert_eq!(json["state"], "no_permission");    assert_eq!(json["detail"], "ask macOS");    assert!(json.get("total").is_none(), "no count to report");    let ready = serde_json::to_value(SourceStatus::ready(42)).expect("json");    assert_eq!(ready["state"], "ready");    assert_eq!(ready["total"], 42);    assert!(ready.get("detail").is_none());}#[test]fn every_state_has_one_spelling_and_the_panel_knows_all_four() {    assert_eq!(SourceState::Ready.as_str(), "ready");    assert_eq!(SourceState::NoPermission.as_str(), "no_permission");    assert_eq!(SourceState::NotFound.as_str(), "not_found");    assert_eq!(SourceState::Error.as_str(), "error");}