sable-markdown/src/parser/inline/tests/wikilink.rs@main
raw
1use crate::{ast::*, parser::parse_markdown};
2
3#[test]
4fn wikilink() {
5 let doc = parse_markdown("[[a]]").unwrap();
6 assert_eq!(
7 doc,
8 Document {
9 blocks: vec![Block::Paragraph(vec![Inline::Wikilink(Wikilink {
10 link: "a".to_owned(),
11 target: None,
12 name: None,
13 })])]
14 }
15 );
16
17 let doc = parse_markdown("before [[a]]").unwrap();
18 assert_eq!(
19 doc,
20 Document {
21 blocks: vec![Block::Paragraph(vec![
22 Inline::Text("before ".to_owned()),
23 Inline::Wikilink(Wikilink {
24 link: "a".to_owned(),
25 target: None,
26 name: None,
27 })
28 ])]
29 }
30 );
31}
32
33#[test]
34fn wikilink_targeted() {
35 let doc = parse_markdown("[[a#b]]").unwrap();
36 assert_eq!(
37 doc,
38 Document {
39 blocks: vec![Block::Paragraph(vec![Inline::Wikilink(Wikilink {
40 link: "a".to_owned(),
41 target: Some("b".to_owned()),
42 name: None,
43 })])]
44 }
45 );
46}
47
48#[test]
49fn wikilink_named() {
50 let doc = parse_markdown("[[a|b]]").unwrap();
51 assert_eq!(
52 doc,
53 Document {
54 blocks: vec![Block::Paragraph(vec![Inline::Wikilink(Wikilink {
55 link: "a".to_owned(),
56 target: None,
57 name: Some("b".to_owned()),
58 })])]
59 }
60 );
61}
62
63#[test]
64fn wikilink_targeted_named() {
65 let doc = parse_markdown("[[a#b|c]]").unwrap();
66 assert_eq!(
67 doc,
68 Document {
69 blocks: vec![Block::Paragraph(vec![Inline::Wikilink(Wikilink {
70 link: "a".to_owned(),
71 target: Some("b".to_owned()),
72 name: Some("c".to_owned()),
73 })])]
74 }
75 );
76}
77