package main import ( "testing" ) func Test_ExtractLink(t *testing.T) { tcs := []struct { name string in string expected Link }{ {"link", `[[Regular Link]]`, Link{Dest: "Regular Link"}}, {"transclude+link", `![[Transcluded Link]]`, Link{Dest: "Transcluded Link"}}, {"link+alias", `[[Regular Link|Alias]]`, Link{Dest: "Regular Link", Alias: "Alias"}}, {"link+subsection", `[[Regular Link#Subsection of page]]`, Link{Dest: "Regular Link", Subsection: "Subsection of page"}}, {"link+block", `[[Regular Link#^link to block]]`, Link{Dest: "Regular Link", Block: "link to block"}}, {"link+subsection+alias", `[[Regular Link#Subsection of page|Alias]]`, Link{Dest: "Regular Link", Subsection: "Subsection of page", Alias: "Alias"}}, {"link+block+alias", `[[Regular Link#^link to block|Alias]]`, Link{Dest: "Regular Link", Block: "link to block", Alias: "Alias"}}, {"link+alias+escape", `[[Regular Link\|Alias]]`, Link{Dest: "Regular Link", Alias: "Alias"}}, {"link+subsection+alias+escape", `[[Regular Link#Subsection of page\|Alias]]`, Link{Dest: "Regular Link", Subsection: "Subsection of page", Alias: "Alias"}}, {"link+block+alias+escape", `[[Regular Link#^link to block\|Alias]]`, Link{Dest: "Regular Link", Block: "link to block", Alias: "Alias"}}, } for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { out := ExtractLink(tc.in) if out != tc.expected { t.Logf("got %#v\n", out) t.Fail() } }) } }