1use onestore::{
2 Arena, ExGuid, RevisionIndex, Section, Store,
3 op::{Edit, Op, PageOp},
4};
5
6/// `source` with revisions of `space` appended until its chain is 512 deep, so its next
7/// revision is a checkpoint. Each retouches the text object `text`, typing a character and
8/// removing it again.
9pub fn pending(source: &[u8], space: ExGuid, text: ExGuid) -> Vec<u8> {
10 let depth = |image: &[u8]| {
11 let store = Store::parse(image).unwrap();
12 let index = RevisionIndex::parse(&store).unwrap();
13 let rid = index.spaces[&space].labels[&(ExGuid::default(), 1)];
14 std::iter::successors(Some(rid), |id| {
15 index.spaces[&space].revisions[id].dependency
16 })
17 .count()
18 };
19 let arena = Arena::default();
20 let mut section = Section::open(&arena, source.to_vec()).unwrap();
21 let retouch = |range, with: &str| Op::Page {
22 space,
23 op: PageOp::Text {
24 text,
25 range,
26 with: with.into(),
27 },
28 };
29 for at in 0..512 - depth(source) as u64 {
30 let ops = vec![retouch(0..0, "x"), retouch(0..1, "")];
31 let at = 134_000_000_000_000_000 + at * 10_000_000;
32 section.apply("Author", &Edit { at, ops }).unwrap();
33 section.seal().unwrap().unwrap();
34 }
35 let image = section.image();
36 assert_eq!(depth(&image), 512);
37 image
38}