80 lines
2.5 KiB
Rust
80 lines
2.5 KiB
Rust
//! `notes.md` headers written and read back, and text the owner edited kept (M5a spec, section 3).
|
|
//! Do not edit.
|
|
|
|
use memoryd::notes::{Kind, Note, minute, parse};
|
|
use proto::{DataClass, MemoryFile, Timestamp};
|
|
|
|
fn note(kind: Kind, text: &str) -> Note {
|
|
Note {
|
|
kind,
|
|
time: "2026-09-24T20:14Z".to_string(),
|
|
session: "mm-s1".to_string(),
|
|
text: text.to_string(),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn every_kind_round_trips() {
|
|
let all = vec![
|
|
note(
|
|
Kind::Noted {
|
|
class: DataClass::Private,
|
|
untrusted: false,
|
|
},
|
|
"seen",
|
|
),
|
|
note(
|
|
Kind::Noted {
|
|
class: DataClass::Secret,
|
|
untrusted: true,
|
|
},
|
|
"two\nlines",
|
|
),
|
|
note(Kind::Moved(MemoryFile::User), "moved"),
|
|
note(Kind::Dropped(MemoryFile::Memory), "dropped"),
|
|
];
|
|
let text: String = all.iter().map(Note::render).collect();
|
|
assert_eq!(
|
|
text,
|
|
"§ noted 2026-09-24T20:14Z in session mm-s1 · private\nseen\n§ noted 2026-09-24T20:14Z in session mm-s1 · secret · untrusted\ntwo\nlines\n§ moved 2026-09-24T20:14Z from user.md in session mm-s1\nmoved\n§ dropped 2026-09-24T20:14Z from memory.md in session mm-s1\ndropped\n"
|
|
);
|
|
assert_eq!(parse(&text), all);
|
|
}
|
|
|
|
#[test]
|
|
fn lines_that_are_not_headers_belong_to_the_entry_above() {
|
|
let text = "stray text before any header\n§ noted 2026-09-24T20:14Z in session mm-s1 · private\nfirst\n§ not a header\n\n§ moved 2026-09-24T20:14Z from soul.md in session mm-s1\n";
|
|
let notes = parse(text);
|
|
assert_eq!(notes.len(), 1);
|
|
assert_eq!(
|
|
notes[0].text,
|
|
"first\n§ not a header\n\n§ moved 2026-09-24T20:14Z from soul.md in session mm-s1"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_time_is_shown_to_the_minute() {
|
|
assert_eq!(
|
|
minute(Timestamp::parse("2026-09-24T20:14:59.999Z").unwrap()),
|
|
"2026-09-24T20:14Z"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_noted_header_with_an_unknown_last_part_is_not_a_header() {
|
|
let text = "§ noted 2026-09-24T20:14Z in session mm-s1 · private · untrusted\nfirst\n§ noted 2026-09-24T20:15Z in session mm-s2 · private · trusted\nsecond\n";
|
|
let notes = parse(text);
|
|
assert_eq!(notes.len(), 1);
|
|
assert_eq!(
|
|
notes[0].kind,
|
|
Kind::Noted {
|
|
class: DataClass::Private,
|
|
untrusted: true,
|
|
}
|
|
);
|
|
assert_eq!(
|
|
notes[0].text,
|
|
"first\n§ noted 2026-09-24T20:15Z in session mm-s2 · private · trusted\nsecond"
|
|
);
|
|
}
|