gitee.com/mirrors/goreporter@v0.0.0-20180902115603-df1b20f7c5d0/linters/spellcheck/misspell/url_test.go (about) 1 package misspell 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 // Test suite partiall from https://mathiasbynens.be/demo/url-regex 9 // 10 func TestStripURL(t *testing.T) { 11 cases := []string{ 12 "HTTP://FOO.COM/BLAH_BLAH", 13 "http://foo.com/blah_blah", 14 "http://foo.com/blah_blah/", 15 "http://foo.com/blah_blah_(wikipedia)", 16 "http://foo.com/blah_blah_(wikipedia)_(again)", 17 "http://www.example.com/wpstyle/?p=364", 18 "https://www.example.com/foo/?bar=baz&inga=42&quux", 19 "http://✪df.ws/123", 20 "http://userid:password@example.com:8080", 21 "http://userid:password@example.com:8080/", 22 "http://userid@example.com", 23 "http://userid@example.com/", 24 "http://userid@example.com:8080", 25 "http://userid@example.com:8080/", 26 "http://userid:password@example.com", 27 "http://userid:password@example.com/", 28 "http://142.42.1.1/", 29 "http://142.42.1.1:8080/", 30 "http://➡.ws/䨹", 31 "http://⌘.ws", 32 "http://⌘.ws/", 33 "http://foo.com/blah_(wikipedia)#cite-1", 34 "http://foo.com/blah_(wikipedia)_blah#cite-1", 35 "http://foo.com/unicode_(✪)_in_parens", 36 "http://foo.com/(something)?after=parens", 37 "http://☺.damowmow.com/a", 38 "http://code.google.com/events/#&product=browser", 39 "http://j.mp", 40 "ftp://foo.bar/baz", 41 "http://foo.bar/?q=Test%20URL-encoded%20stuff", 42 "http://مثال.إختبار", 43 "http://例子.测试", 44 "http://उदाहरण.परीक्षा", 45 "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", 46 "http://1337.net", 47 "http://a.b-c.de", 48 "http://223.255.255.254", 49 } 50 51 for num, tt := range cases { 52 got := strings.TrimSpace(StripURL(tt)) 53 if len(got) != 0 { 54 t.Errorf("case %d: unable to match %q", num, tt) 55 } 56 } 57 58 cases = []string{ 59 "http://", 60 "http://.", 61 "http://..", 62 "http://../", 63 "http://?", 64 "http://??", 65 "http://??/", 66 "http://#", 67 "http://##", 68 "http://##/", 69 "http://foo.bar?q=Spaces should be encoded", 70 "//", 71 "//a", 72 "///a", 73 "///", 74 "http:///a", 75 "foo.com", 76 "rdar://1234", 77 "h://test", 78 "http:// shouldfail.com", 79 ":// should fail", 80 "http://foo.bar/foo(bar)baz quux", 81 "ftps://foo.bar/", 82 //"http://-error-.invalid/", 83 //"http://a.b--c.de/", 84 //"http://-a.b.co", 85 //"http://a.b-.co", 86 //"http://0.0.0.0", 87 //"http://10.1.1.0", 88 //"http://10.1.1.255", 89 //"http://224.1.1.1", 90 //"http://1.1.1.1.1", 91 //"http://123.123.123", 92 //"http://3628126748", 93 "http://.www.foo.bar/", 94 //"http://www.foo.bar./", 95 "http://.www.foo.bar./", 96 //"http://10.1.1.1", 97 } 98 99 for num, tt := range cases { 100 got := strings.TrimSpace(StripURL(tt)) 101 if len(got) == 0 { 102 t.Errorf("case %d: incorrect match %q", num, tt) 103 } 104 } 105 }