okami.mom/glamour
git clone https://git.nkp.pet/okami.mom/glamour
cf874d7
main
1package autolink_test 2 3import ( 4"testing" 5 6"charm.land/glamour/v2/internal/autolink" 7) 8 9func TestDetect (t * testing.T ) { 10tests := []struct { 11url string 12expected string 13 }{ 14 {"https://github.com/owner/repo/issue/123" ,"owner/repo#123" }, 15 {"https://github.com/owner/repo/issues/123" ,"owner/repo#123" }, 16 {"https://github.com/owner/repo/pull/123" ,"owner/repo#123" }, 17 {"https://github.com/owner/repo/pulls/123" ,"owner/repo#123" }, 18 {"https://github.com/owner/repo/discussions/123" ,"owner/repo#123" }, 19 20 {"https://github.com/owner/repo/issue/123#issuecomment-456" ,"owner/repo#123 (comment)" }, 21 {"https://github.com/owner/repo/issues/123#issuecomment-456" ,"owner/repo#123 (comment)" }, 22 {"https://github.com/owner/repo/pull/123#issuecomment-456" ,"owner/repo#123 (comment)" }, 23 {"https://github.com/owner/repo/pulls/123#issuecomment-456" ,"owner/repo#123 (comment)" }, 24 25 {"https://github.com/owner/repo/pull/123#discussion_r456" ,"owner/repo#123 (comment)" }, 26 {"https://github.com/owner/repo/pulls/123#discussion_r456" ,"owner/repo#123 (comment)" }, 27 28 {"https://github.com/owner/repo/pull/123#pullrequestreview-456" ,"owner/repo#123 (review)" }, 29 {"https://github.com/owner/repo/pulls/123#pullrequestreview-456" ,"owner/repo#123 (review)" }, 30 31 {"https://github.com/owner/repo/discussions/123#discussioncomment-456" ,"owner/repo#123 (comment)" }, 32 33 {"https://github.com/owner/repo/commit/abcdefghijklmnopqrsxyz" ,"owner/repo@abcdefg" }, 34 35 {"https://github.com/owner/repo/pull/123/commits/abcdefghijklmnopqrsxyz" ,"owner/repo@abcdefg" }, 36 {"https://github.com/owner/repo/pulls/123/commits/abcdefghijklmnopqrsxyz" ,"owner/repo@abcdefg" }, 37 38 {"https://github.com/owner/repo/commit/abcdefghijklmnopqrsxyz#diff-123" ,"owner/repo@abcdefg" }, 39 {"https://github.com/owner/repo/pull/123/commits/abcdefghijklmnopqrsxyz#diff-123" ,"owner/repo@abcdefg" }, 40 {"https://github.com/owner/repo/pulls/123/commits/abcdefghijklmnopqrsxyz#diff-123" ,"owner/repo@abcdefg" }, 41 } 42for _ ,test := range tests { 43t .Run (test .url ,func (t * testing.T ) { 44result ,ok := autolink .Detect (test .url ) 45if ! ok { 46t .Errorf ("expected to detect URL, got nil" ) 47 } 48if result != test .expected { 49t .Errorf ("expected %s, got %s" ,test .expected ,result ) 50 } 51 }) 52 } 53}