diff options
| -rw-r--r-- | src/ast/container.rs | 2 | ||||
| -rw-r--r-- | tests/ast.rs | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/ast/container.rs b/src/ast/container.rs index 0d20193..bf4166c 100644 --- a/src/ast/container.rs +++ b/src/ast/container.rs @@ -206,7 +206,7 @@ impl Ast { .into_iter(); nodes.push(Node::Link { - to: split.next().expect("no location in link"), + to: split.next().unwrap_or_default(), text: { let rest = split.collect::<Vec<String>>().join(" "); diff --git a/tests/ast.rs b/tests/ast.rs index 397f752..7a71f5c 100644 --- a/tests/ast.rs +++ b/tests/ast.rs @@ -84,4 +84,18 @@ mod test { "=> / Home" ); } + + #[test] + fn build_malformed_link_without_url() { + let ast = Ast::from_string("=>"); + + assert_eq!(ast.inner().len(), 1); + + if let Node::Link { to, text } = ast.inner().first().unwrap() { + assert_eq!(to, ""); + assert_eq!(text, &None); + } else { + panic!("Expected Link node"); + } + } } |