diff --git a/test/journal.md b/journal.md similarity index 100% rename from test/journal.md rename to journal.md diff --git a/lib/filesystem.rs b/lib/filesystem.rs index 8a1e566..3777ca8 100644 --- a/lib/filesystem.rs +++ b/lib/filesystem.rs @@ -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) + } + } +} diff --git a/lib/node.rs b/lib/node.rs index 61242d1..605bda2 100644 --- a/lib/node.rs +++ b/lib/node.rs @@ -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 diff --git a/src/main.rs b/src/main.rs index 3289050..314c9c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use transpiler::parser::Parser; use transpiler::filesystem::Filesystem; pub fn main() -> Result<(), Box> { - let file = Filesystem::read_file("./test/journal.md"); + let file = Filesystem::read_file("./journal.md"); let content; match file { Ok(s) => content = s, diff --git a/test/filesystem_test.md b/test/filesystem_test.md new file mode 100644 index 0000000..4f04516 --- /dev/null +++ b/test/filesystem_test.md @@ -0,0 +1 @@ +DO NOT DELETE. Used in filesystem.rs tests. diff --git a/test/filesystem_test_output.md b/test/filesystem_test_output.md new file mode 100644 index 0000000..cc55d13 --- /dev/null +++ b/test/filesystem_test_output.md @@ -0,0 +1 @@ +TESTING OUTPUT \ No newline at end of file diff --git a/test/input.md b/test/input.md deleted file mode 100644 index bea672e..0000000 --- a/test/input.md +++ /dev/null @@ -1,5 +0,0 @@ - -# Large heading - -Holy rust is magical -