Add some unit tests for ObsidianNoteReference::from_str
This commit is contained in:
parent
2fa34fb5db
commit
25233cec4a
51
src/lib.rs
51
src/lib.rs
@ -117,7 +117,7 @@ struct Context {
|
||||
frontmatter_strategy: FrontmatterStrategy,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
/// ObsidianNoteReference represents the structure of a `[[note]]` or `![[embed]]` reference.
|
||||
struct ObsidianNoteReference<'a> {
|
||||
/// The file (note name or partial path) being referenced.
|
||||
@ -761,3 +761,52 @@ fn codeblock_kind_to_owned<'a>(codeblock_kind: CodeBlockKind) -> CodeBlockKind<'
|
||||
CodeBlockKind::Fenced(cowstr) => CodeBlockKind::Fenced(CowStr::from(cowstr.into_string())),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn parse_note_refs_from_strings() {
|
||||
assert_eq!(
|
||||
ObsidianNoteReference::from_str("Just a note"),
|
||||
ObsidianNoteReference {
|
||||
file: Some("Just a note"),
|
||||
label: None,
|
||||
section: None,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
ObsidianNoteReference::from_str("A note?"),
|
||||
ObsidianNoteReference {
|
||||
file: Some("A note?"),
|
||||
label: None,
|
||||
section: None,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
ObsidianNoteReference::from_str("Note#with heading"),
|
||||
ObsidianNoteReference {
|
||||
file: Some("Note"),
|
||||
label: None,
|
||||
section: Some("with heading"),
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
ObsidianNoteReference::from_str("Note#Heading|Label"),
|
||||
ObsidianNoteReference {
|
||||
file: Some("Note"),
|
||||
label: Some("Label"),
|
||||
section: Some("Heading"),
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
ObsidianNoteReference::from_str("#Heading|Label"),
|
||||
ObsidianNoteReference {
|
||||
file: None,
|
||||
label: Some("Label"),
|
||||
section: Some("Heading"),
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user