Struct texlang_common::InMemoryFileSystem
source · pub struct InMemoryFileSystem { /* private fields */ }
Expand description
In-memory filesystem for use in unit tests.
This type mocks out the file system operations in the VM. It provides an in-memory system to which “files” can be added before the test runs. It is designed to help test primitives that interact with the filesystem.
Given a VM, the file system can be set as follows:
#[derive(Default)]
struct State {
file_system: Rc<RefCell<InMemoryFileSystem>>,
}
let mut vm = vm::VM::<State>::new_with_built_in_commands(
HashMap::new(), // empty set of built-in commands
);
let mut mock_file_system = InMemoryFileSystem::new(&vm.working_directory.as_ref().unwrap());
mock_file_system.add_string_file("file/path.tex", "file content");
vm.state.file_system = Rc::new(RefCell::new(mock_file_system));
Implementations§
source§impl InMemoryFileSystem
impl InMemoryFileSystem
sourcepub fn new(working_directory: &Path) -> Self
pub fn new(working_directory: &Path) -> Self
Create a new in-memory file system.
Typically the working directory is taken from the VM.
sourcepub fn add_string_file(&mut self, relative_path: &str, content: &str)
pub fn add_string_file(&mut self, relative_path: &str, content: &str)
Add a string file to the in-memory file system.
The provided path is relative to the working directory
sourcepub fn add_bytes_file(&mut self, relative_path: &str, content: &[u8])
pub fn add_bytes_file(&mut self, relative_path: &str, content: &[u8])
Add a bytes file to the in-memory file system.
The provided path is relative to the working directory
Trait Implementations§
source§impl Default for InMemoryFileSystem
impl Default for InMemoryFileSystem
source§fn default() -> InMemoryFileSystem
fn default() -> InMemoryFileSystem
Returns the “default value” for a type. Read more
source§impl FileSystem for InMemoryFileSystem
impl FileSystem for InMemoryFileSystem
Auto Trait Implementations§
impl Freeze for InMemoryFileSystem
impl RefUnwindSafe for InMemoryFileSystem
impl Send for InMemoryFileSystem
impl Sync for InMemoryFileSystem
impl Unpin for InMemoryFileSystem
impl UnwindSafe for InMemoryFileSystem
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more