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"}, {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"}, } /* "[[#^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() } }) } }