You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.9 KiB
Go
76 lines
2.9 KiB
Go
package markdown_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.ndumas.com/ndumas/obsidian-markdown"
|
|
)
|
|
|
|
func _Test_Wikilink_Parsing(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tcs := []struct {
|
|
name string
|
|
in string
|
|
link, alias, fragment string
|
|
}{
|
|
{name: "wikilink", in: "[[wikilink]]", link: "wikilink"},
|
|
{name: "wikilink|display name", in: "[[wikilink|display name]]", link: "wikilink", alias: "display name"},
|
|
{name: "wikilink|display name|second pipe", in: "[[wikilink|display name|second pipe]]", link: "wikilink", alias: "display name|second pipe"},
|
|
{name: "wikilink with numeric alias|420|second pipe", in: "[[wikilink|420|second pipe]]", link: "wikilink with numeric aliases", alias: "420|second pipe"},
|
|
{name: "wikilink with spaces in filename", in: "[[wikilink spaces]]", link: "wikilink spaces"},
|
|
{name: "#heading", in: "[[#heading]]", link: "", fragment: "heading"},
|
|
{name: "wikilink#heading", in: "[[wikilink#heading]]", link: "wikilink", fragment: "heading"},
|
|
{name: "wikilink#heading|display name", in: "[[wikilink#heading|display name]]", link: "wikilink", alias: "display name", fragment: "heading"},
|
|
{name: "wikilink#heading|display name|second pipe", in: "[[wikilink#heading|display name|second pipe]]", link: "wikilink", alias: "display name|second pipe", fragment: "heading"},
|
|
{name: "wikilink with numeric aliases#heading|420|display name", in: "[[wikilink#heading|420|second pipe]]", link: "wikilink", alias: "420|second pipe", fragment: "heading"},
|
|
{name: "^blockRef", in: "[[^blockRef]]", link: "", fragment: "blockRef"},
|
|
{name: "wikilink^blockRef", in: "[[wikilink^blockRef]]", link: "wikilink", fragment: "blockRef"},
|
|
{name: "wikilink^blockRef|display name", in: "[[wikilink#^blockRef|display name]]", link: "wikilink", alias: "display name", fragment: "blockRef"},
|
|
{name: "wikilink^blockRef|display name|second pipe", in: "[[wikilink#^blockRef|display name|second pipe]]", link: "wikilink", alias: "display name|second pipe", fragment: "blockRef"},
|
|
{name: "wikilink with numeric aliases^blockRef|420|second pipe", in: "[[wikilink#^blockRef|420|second pipe]]", link: "wikilink", alias: "420|second pipe", fragment: "blockRef"},
|
|
}
|
|
|
|
t.Run("link", func(t *testing.T) {
|
|
for _, tc := range tcs {
|
|
tc := tc
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
out := markdown.Extract(tc.in)
|
|
if out.Link != tc.link {
|
|
t.Logf("got %#v\n", out)
|
|
t.Fail()
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|
|
t.Run("alias", func(t *testing.T) {
|
|
for _, tc := range tcs {
|
|
tc := tc
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
out := markdown.Extract(tc.in)
|
|
if out.Alias != tc.alias {
|
|
t.Logf("got %#v\n", out)
|
|
t.Fail()
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|
|
t.Run("fragment", func(t *testing.T) {
|
|
for _, tc := range tcs {
|
|
tc := tc
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
out := markdown.Extract(tc.in)
|
|
if out.Fragment != tc.fragment {
|
|
t.Logf("got %#v\n", out)
|
|
t.Fail()
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|