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