package wikilink_test import ( "testing" "code.ndumas.com/ndumas/wikilink-parser" ) 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 := wikilink.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 := wikilink.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 := wikilink.Extract(tc.in) if out.Fragment != tc.fragment { t.Logf("got %#v\n", out) t.Fail() } }) } }) }