(TEST): Filesystem tests and cleaned up

This commit is contained in:
Hayden Hargreaves 2025-11-23 17:45:27 -07:00
parent 67542b8153
commit 929c569a18
7 changed files with 32 additions and 15 deletions

View File

@ -18,3 +18,32 @@ impl Filesystem {
file.write_all(contents.as_bytes()) file.write_all(contents.as_bytes())
} }
} }
#[cfg(test)]
mod filesystem_tests {
use std::fs;
use super::Filesystem;
#[test]
fn reads_file() {
match Filesystem::read_file("./test/filesystem_test.md") {
Ok(s) => assert_eq!(s, "DO NOT DELETE. Used in filesystem.rs tests.\n"),
Err(err) => unreachable!("{}", err)
}
}
#[test]
fn writes_file() {
let path = String::from("./test/filesystem_test_output.md");
let content = String::from("TESTING OUTPUT");
match Filesystem::write_file(&path, &content) {
Ok(_) => {
match fs::read_to_string(&path) {
Ok(s) => assert_eq!(s, content),
Err(err) => unreachable!("{}", err),
}
},
Err(err) => unreachable!("{}", err)
}
}
}

View File

@ -131,15 +131,6 @@ impl Node {
/// Add a child to the back of the list of children. If the node is a type which does not allow /// Add a child to the back of the list of children. If the node is a type which does not allow
/// children to be added, this function will panic. /// children to be added, this function will panic.
///
/// Example INVALID usage:
///
/// ```rust
/// // Attempting to add an inline node as a child of another inline node.
/// let mut inline = Node::Text { content: String::from("Hello world") };
/// let inline2 = Node::Bold { content: String::from(" bolded text") };
/// inline.add_child(inline2); // Will panic! 'Can't add child to this node type.'
/// ```
pub fn add_child(&mut self, child: Node) { pub fn add_child(&mut self, child: Node) {
match self { match self {
// Structure Nodes // Structure Nodes

View File

@ -2,7 +2,7 @@ use transpiler::parser::Parser;
use transpiler::filesystem::Filesystem; use transpiler::filesystem::Filesystem;
pub fn main() -> Result<(), Box<dyn std::error::Error>> { pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = Filesystem::read_file("./test/journal.md"); let file = Filesystem::read_file("./journal.md");
let content; let content;
match file { match file {
Ok(s) => content = s, Ok(s) => content = s,

1
test/filesystem_test.md Normal file
View File

@ -0,0 +1 @@
DO NOT DELETE. Used in filesystem.rs tests.

View File

@ -0,0 +1 @@
TESTING OUTPUT

View File

@ -1,5 +0,0 @@
# Large heading
Holy rust is magical