Skip to content

Commit

Permalink
Improve doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Feb 10, 2025
1 parent d6a4702 commit 902cdb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion crates/ruff_db/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::error::Error;
use std::fmt::Debug;
use std::path::{Path, PathBuf};
use std::{fmt, io};
pub use test::{DbWithTestSystem, TestSystem};
pub use test::{DbWithTestSystem, InMemorySystem, TestSystem};
use walk_directory::WalkDirectoryBuilder;

use crate::file_revision::FileRevision;
Expand Down
24 changes: 15 additions & 9 deletions crates/ruff_db/src/system/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ pub struct TestSystem {
}

impl TestSystem {
/// Returns the `InMemorySystem`.
/// Returns the [`InMemorySystem`].
///
/// ## Panics
/// If this test db isn't the in memory system.
/// If the underlying test system isn't the [`InMemorySystem`].
pub fn in_memory(&self) -> &InMemorySystem {
self.as_in_memory()
.expect("The test db is not using a memory file system")
}

/// Returns the `InMemorySystem` or `None` if the test system is using an other underlying system.
/// Returns the `InMemorySystem` or `None` if the underlying test system isn't the [`InMemorySystem`].
pub fn as_in_memory(&self) -> Option<&InMemorySystem> {
self.system().as_any().downcast_ref::<InMemorySystem>()
}

/// Returns the memory file system.
///
/// ## Panics
/// If this test db isn't using a memory file system.
/// If the underlying test system isn't the [`InMemorySystem`].
pub fn memory_file_system(&self) -> &MemoryFileSystem {
self.in_memory().fs()
}
Expand Down Expand Up @@ -144,8 +144,8 @@ pub trait DbWithTestSystem: Db + Sized {

/// Writes the content of the given file and notifies the Db about the change.
///
/// # Panics
/// If the system isn't using the memory file system.
/// ## Panics
/// If the db isn't using the [`InMemorySystem`].
fn write_file(&mut self, path: impl AsRef<SystemPath>, content: impl ToString) -> Result<()> {
let path = path.as_ref();

Expand All @@ -172,6 +172,9 @@ pub trait DbWithTestSystem: Db + Sized {
}

/// Writes the content of the given virtual file.
///
/// ## Panics
/// If the db isn't using the [`InMemorySystem`].
fn write_virtual_file(&mut self, path: impl AsRef<SystemVirtualPath>, content: impl ToString) {
let path = path.as_ref();
self.test_system()
Expand All @@ -180,15 +183,18 @@ pub trait DbWithTestSystem: Db + Sized {
}

/// Writes auto-dedented text to a file.
///
/// ## Panics
/// If the db isn't using the [`InMemorySystem`].
fn write_dedented(&mut self, path: &str, content: &str) -> crate::system::Result<()> {
self.write_file(path, textwrap::dedent(content))?;
Ok(())
}

/// Writes the content of the given files and notifies the Db about the change.
///
/// # Panics
/// If the system isn't using the memory file system for testing.
/// ## Panics
/// If the db isn't using the [`InMemorySystem`].
fn write_files<P, C, I>(&mut self, files: I) -> crate::system::Result<()>
where
I: IntoIterator<Item = (P, C)>,
Expand Down Expand Up @@ -217,7 +223,7 @@ pub trait DbWithTestSystem: Db + Sized {
/// Returns the memory file system.
///
/// ## Panics
/// If this system isn't using a memory file system.
/// If the underlying test system isn't the [`InMemorySystem`].
fn memory_file_system(&self) -> &MemoryFileSystem {
self.test_system().memory_file_system()
}
Expand Down

0 comments on commit 902cdb4

Please sign in to comment.