diff options
| author | Fuwn <[email protected]> | 2024-06-19 07:37:57 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-06-19 07:38:02 +0000 |
| commit | ad1ae6079cf2ab7b384262f3a77100cfbf4fb5aa (patch) | |
| tree | 69e7405bf5139d0cabd6e2ef890328b0d4cb9bde | |
| parent | fix(ast): preserve newline structure at end of gemtext (diff) | |
| download | germ-ad1ae6079cf2ab7b384262f3a77100cfbf4fb5aa.tar.xz germ-ad1ae6079cf2ab7b384262f3a77100cfbf4fb5aa.zip | |
refactor(Node): rename content() to to_gemtext()
This commit adds a `tests/node.rs` file to test `Node::to_gemtext`.
| -rw-r--r-- | src/ast/node.rs | 4 | ||||
| -rw-r--r-- | tests/ast.rs | 35 | ||||
| -rw-r--r-- | tests/node.rs | 14 |
3 files changed, 38 insertions, 15 deletions
diff --git a/src/ast/node.rs b/src/ast/node.rs index 1040d2b..95190d2 100644 --- a/src/ast/node.rs +++ b/src/ast/node.rs @@ -173,9 +173,9 @@ pub enum Node { } impl Node { - /// Obtain the Gemtext content of a single [`Node`] as a [`String`] + /// Convert a single [`Node`] of any node type to a Gemtext [`String`] #[must_use] - pub fn content(&self) -> String { + pub fn to_gemtext(&self) -> String { super::Ast::from_nodes(vec![self.to_owned()]).to_gemtext() } } diff --git a/tests/ast.rs b/tests/ast.rs index eedd546..f95591a 100644 --- a/tests/ast.rs +++ b/tests/ast.rs @@ -51,27 +51,36 @@ That was a link without text."#; #[test] fn build_multi_line_list_with_text() { - assert_eq!(*Ast::from_string("* item1\n* 2\nhi text").inner(), vec![ - Node::List(vec!["item1".to_string(), "2".to_string()]), - Node::Text("hi text".to_string()), - ],); + assert_eq!( + *Ast::from_string("* item1\n* 2\nhi text").inner(), + vec![ + Node::List(vec!["item1".to_string(), "2".to_string()]), + Node::Text("hi text".to_string()), + ], + ); } #[test] fn build_multi_line_vec() { - assert_eq!(*Ast::from_string("=> /test hi\nhi there\n> hi").inner(), vec![ - Node::Link { to: "/test".to_string(), text: Some("hi".to_string()) }, - Node::Text("hi there".to_string()), - Node::Blockquote("hi".to_string()), - ],); + assert_eq!( + *Ast::from_string("=> /test hi\nhi there\n> hi").inner(), + vec![ + Node::Link { to: "/test".to_string(), text: Some("hi".to_string()) }, + Node::Text("hi there".to_string()), + Node::Blockquote("hi".to_string()), + ], + ); } #[test] fn build_single_0th_from_vec() { - assert_eq!(Ast::from_string("=> /test hi").inner(), &vec![Node::Link { - to: "/test".to_string(), - text: Some("hi".to_string()), - }],); + assert_eq!( + Ast::from_string("=> /test hi").inner(), + &vec![Node::Link { + to: "/test".to_string(), + text: Some("hi".to_string()), + }], + ); } #[test] diff --git a/tests/node.rs b/tests/node.rs new file mode 100644 index 0000000..ff224a4 --- /dev/null +++ b/tests/node.rs @@ -0,0 +1,14 @@ +#[cfg(test)] +mod test { + #[test] + fn node_to_gemtext() { + assert_eq!( + germ::ast::Node::Link { + to: "/faq".to_string(), + text: Some("FAQ".to_string()) + } + .to_gemtext(), + "=> /faq FAQ", + ); + } +} |