(TEST): Filesystem tests and cleaned up
This commit is contained in:
parent
67542b8153
commit
929c569a18
@ -18,3 +18,32 @@ impl Filesystem {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
/// 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) {
|
||||
match self {
|
||||
// Structure Nodes
|
||||
|
||||
@ -2,7 +2,7 @@ use transpiler::parser::Parser;
|
||||
use transpiler::filesystem::Filesystem;
|
||||
|
||||
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;
|
||||
match file {
|
||||
Ok(s) => content = s,
|
||||
|
||||
1
test/filesystem_test.md
Normal file
1
test/filesystem_test.md
Normal file
@ -0,0 +1 @@
|
||||
DO NOT DELETE. Used in filesystem.rs tests.
|
||||
1
test/filesystem_test_output.md
Normal file
1
test/filesystem_test_output.md
Normal file
@ -0,0 +1 @@
|
||||
TESTING OUTPUT
|
||||
@ -1,5 +0,0 @@
|
||||
|
||||
# Large heading
|
||||
|
||||
Holy rust is magical
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user