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.
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package wikilink_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.ndumas.com/ndumas/wikilink-parser"
|
|
)
|
|
|
|
func Test_Extract_Link(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tcs := []struct {
|
|
name string
|
|
in string
|
|
expected 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"},
|
|
}
|
|
/*
|
|
|
|
|
|
"[[#^blockRef]]"
|
|
"[[wikilink#^blockRef]]"
|
|
"[[wikilink#^blockRef|display name]]"
|
|
"[[wikilink#^blockRef|display name|secondpipe]]"
|
|
|
|
"[[#^blockRef]]"
|
|
"[[wikilink#^blockRef]]"
|
|
"[[wikilink#^blockRef|display name|secondpipe]]"
|
|
*/
|
|
|
|
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()
|
|
}
|
|
})
|
|
}
|
|
}
|