red-knot: Add directory support to MemoryFileSystem (#11825)

This commit is contained in:
Micha Reiser 2024-06-13 08:48:28 +01:00 committed by GitHub
parent d4dd96d1f4
commit 22b6488550
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 463 additions and 93 deletions

View file

@ -66,28 +66,34 @@ mod tests {
use crate::Db;
#[test]
fn re_runs_query_when_file_revision_changes() {
fn re_runs_query_when_file_revision_changes() -> crate::file_system::Result<()> {
let mut db = TestDb::new();
let path = FileSystemPath::new("test.py");
db.file_system_mut().write_file(path, "x = 10".to_string());
db.file_system_mut()
.write_file(path, "x = 10".to_string())?;
let file = db.file(path);
assert_eq!(&*source_text(&db, file), "x = 10");
db.file_system_mut().write_file(path, "x = 20".to_string());
db.file_system_mut()
.write_file(path, "x = 20".to_string())
.unwrap();
file.set_revision(&mut db).to(FileTime::now().into());
assert_eq!(&*source_text(&db, file), "x = 20");
Ok(())
}
#[test]
fn text_is_cached_if_revision_is_unchanged() {
fn text_is_cached_if_revision_is_unchanged() -> crate::file_system::Result<()> {
let mut db = TestDb::new();
let path = FileSystemPath::new("test.py");
db.file_system_mut().write_file(path, "x = 10".to_string());
db.file_system_mut()
.write_file(path, "x = 10".to_string())?;
let file = db.file(path);
@ -104,15 +110,17 @@ mod tests {
assert!(!events
.iter()
.any(|event| matches!(event.kind, EventKind::WillExecute { .. })));
Ok(())
}
#[test]
fn line_index_for_source() {
fn line_index_for_source() -> crate::file_system::Result<()> {
let mut db = TestDb::new();
let path = FileSystemPath::new("test.py");
db.file_system_mut()
.write_file(path, "x = 10\ny = 20".to_string());
.write_file(path, "x = 10\ny = 20".to_string())?;
let file = db.file(path);
let index = line_index(&db, file);
@ -123,5 +131,7 @@ mod tests {
index.line_start(OneIndexed::from_zero_indexed(0), &text),
TextSize::new(0)
);
Ok(())
}
}