Skip to content

Commit 0471792

Browse files
committed
chore(gas): add test for history with holes
1 parent cd862c4 commit 0471792

File tree

1 file changed

+75
-0
lines changed
  • engine/packages/gasoline/src/history

1 file changed

+75
-0
lines changed

engine/packages/gasoline/src/history/cursor.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,4 +776,79 @@ mod tests {
776776
let new = cursor.current_location_for(&HistoryResult::<()>::Insertion);
777777
assert_eq!(loc![coord![1], coord![2, 1, 0, 1]], new);
778778
}
779+
780+
#[test]
781+
fn holes_in_coordinates() {
782+
let events = [(
783+
loc![],
784+
vec![
785+
Event {
786+
coordinate: coord![1],
787+
version: 1,
788+
data: EventData::VersionCheck,
789+
},
790+
Event {
791+
coordinate: coord![3],
792+
version: 1,
793+
data: EventData::VersionCheck,
794+
},
795+
Event {
796+
coordinate: coord![6],
797+
version: 1,
798+
data: EventData::VersionCheck,
799+
},
800+
],
801+
)]
802+
.into_iter()
803+
.collect::<HashMap<_, _>>();
804+
let mut cursor = Cursor::new(Arc::new(events), Location::empty());
805+
806+
// First event should be at coordinate 1
807+
assert_eq!(coord![1], cursor.current_coord());
808+
cursor.update(&cursor.current_location_for(&HistoryResult::<()>::Event(())));
809+
810+
// Second event should be at coordinate 3 (with hole at 2)
811+
assert_eq!(coord![3], cursor.current_coord());
812+
cursor.update(&cursor.current_location_for(&HistoryResult::<()>::Event(())));
813+
814+
// Third event should be at coordinate 6 (with holes at 4, 5)
815+
assert_eq!(coord![6], cursor.current_coord());
816+
cursor.update(&cursor.current_location_for(&HistoryResult::<()>::Event(())));
817+
818+
// After all events, coords should continue from last event's coordinate
819+
assert_eq!(coord![7], cursor.current_coord());
820+
}
821+
822+
#[test]
823+
fn holes_in_coordinates2() {
824+
let events = [(
825+
loc![],
826+
vec![
827+
Event {
828+
coordinate: coord![1],
829+
version: 1,
830+
data: EventData::VersionCheck,
831+
},
832+
Event {
833+
coordinate: coord![3],
834+
version: 1,
835+
data: EventData::VersionCheck,
836+
},
837+
Event {
838+
coordinate: coord![6],
839+
version: 1,
840+
data: EventData::VersionCheck,
841+
},
842+
],
843+
)]
844+
.into_iter()
845+
.collect::<HashMap<_, _>>();
846+
847+
let mut cursor = Cursor::new(Arc::new(events), Location::empty());
848+
cursor.update(&cursor.current_location_for(&HistoryResult::<()>::Event(())));
849+
850+
// Insert after coordinate 1, before coordinate 3
851+
let new = cursor.current_location_for(&HistoryResult::<()>::Insertion);
852+
assert_eq!(loc![coord![1, 1]], new);
853+
}
779854
}

0 commit comments

Comments
 (0)