Compare commits

...

1 Commits

Author SHA1 Message Date
Nicolás Hatcher
7d189905ba UPDATE: Skeleton for the garbage collector 2024-03-09 14:32:54 +01:00
4 changed files with 36 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
use crate::model::Model;
// The gc (Garbage Collector) cleans up leftover elements in the workbook:
// * Strings that are no longe reachable
// * Styles that are no longer reachable
// * ...
impl Model {
pub(crate) fn gc(&mut self) -> Result<(), String> {
todo!()
}
}

View File

@@ -50,6 +50,7 @@ mod implicit_intersection;
mod units;
mod utils;
mod workbook;
mod garbage_collector;
#[cfg(test)]
mod test;

View File

@@ -53,3 +53,4 @@ mod test_frozen_rows_and_columns;
mod test_get_cell_content;
mod test_percentage;
mod test_today;
mod test_gc;

22
base/src/test/test_gc.rs Normal file
View File

@@ -0,0 +1,22 @@
#![allow(clippy::unwrap_used)]
use crate::test::util::new_empty_model;
#[test]
fn test_empty_model() {
let mut model = new_empty_model();
// set a string
model._set("A1", "Hello");
assert_eq!(model.shared_strings.len(), 1);
// calling the gc doesn't do anything
model.gc().unwrap();
assert_eq!(model.shared_strings.len(), 1);
// If we delete the cell the string is still in the list
model.delete_cell(0, 1, 1).unwrap();
assert_eq!(model.shared_strings.len(), 1);
// after the gc the string is no longer present
model.gc().unwrap();
assert_eq!(model.shared_strings.len(), 0);
}