expanding test case coverage

main
Nick Dumas 2 years ago
parent 2a57969dea
commit 2eda50a592

@ -6,40 +6,70 @@ import (
"code.ndumas.com/ndumas/wikilink-parser"
)
func Test_Extract_Link(t *testing.T) {
func Test_Wikilink_Parsing(t *testing.T) {
t.Parallel()
tcs := []struct {
name string
in string
expected string
name string
in string
link, alias, fragment string
}{
{name: "wikilink", in: "[[wikilink]]", expected: "wikilink"},
{name: "wikilink|display name", in: "[[wikilink|display name]]", expected: "wikilink"},
{name: "wikilink|display name|second pipe", in: "[[wikilink|display name|second pipe]]", expected: "wikilink"},
{name: "wikilink with numeric alias|420|second pipe", in: "[[wikilink|420|second pipe]]", expected: "wikilink with numeric aliases"},
{name: "wikilink with spaces in filename", in: "[[wikilink spaces]]", expected: "wikilink"},
{name: "#heading", in: "[[#heading]]", expected: ""},
{name: "wikilink#heading", in: "[[wikilink#heading]]", expected: "wikilink"},
{name: "wikilink#heading|display name", in: "[[wikilink#heading|display name]]", expected: "wikilink"},
{name: "wikilink#heading|display name", in: "[[wikilink#heading|display name]]", expected: "wikilink"},
{name: "wikilink with numeric aliases#heading|420|display name", in: "[[wikilink#heading|420|second pipe]]", expected: "wikilink"},
{name: "^blockRef", in: "[[^blockRef]]", expected: ""},
{name: "wikilink^blockRef", in: "[[wikilink^blockRef]]", expected: "wikilink"},
{name: "wikilink^blockRef|display name", in: "[[wikilink#^blockRef|display name]]", expected: "wikilink"},
{name: "wikilink^blockRef|display name|second pipe", in: "[[wikilink#^blockRef|display name|second pipe]]", expected: "wikilink"},
{name: "wikilink with numeric aliases^blockRef|420|second pipe", in: "[[wikilink#^blockRef|420|second pipe]]", expected: "wikilink"},
{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"},
}
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.expected {
t.Logf("got %#v\n", out)
t.Fail()
}
})
}
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()
}
})
}
})
}

Loading…
Cancel
Save