use crate::base_types::TgqeReader;
use crate::singletons::SourceManager;
#[test]
fn store_file_computes_line_offsets() {
let path =
std::env::temp_dir().join(format!(
"tgqe_store_{}.txt",
std::time::SystemTime::now()
.duration_since(
std::time::UNIX_EPOCH,
)
.unwrap()
.as_nanos()
));
std::fs::write(&path, "ab\ncde\nf")
.unwrap();
assert!(
TgqeReader::store_file(
path.to_str().unwrap(),
)
.unwrap()
);
let cache =
SourceManager.lock().unwrap();
let (text, start, end, display) = cache
.source_window(
path.to_str().unwrap(),
4,
8,
)
.unwrap();
assert_eq!(text, "cde\nf");
assert_eq!((start, end), (1, 5));
assert_eq!(display, 1);
assert_eq!(
cache
.source_text(
path.to_str().unwrap()
)
.as_deref(),
Some("ab\ncde\nf")
);
drop(cache);
let _ = std::fs::remove_file(&path);
}