/
url_spec.rb
66 lines (61 loc) · 1.61 KB
/
url_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# encoding: UTF-8
describe Regexy::Web::Url do
VALID_URL = [
'http://foo.com/blah_blah',
'http://foo.com/blah_blah/',
'http://foo.com/blah_blah_(wikipedia)',
'http://foo.com/blah_blah_(wikipedia)_(again)',
'http://www.example.com/wpstyle/?p=364',
'https://www.example.com/foo/?bar=baz&inga=42&quux',
'http://userid@example.com',
'http://userid@example.com/',
'http://userid@example.com:8080',
'http://userid@example.com:8080/',
'http://142.42.1.1/',
'http://foo.com/blah_(wikipedia)#cite-1',
'http://foo.com/blah_(wikipedia)_blah#cite-1',
'http://foo.com/(something)?after=parens',
'http://code.google.com/events/#&product=browser',
'http://j.mp',
'ftp://foo.bar/baz',
'http://foo.bar/?q=Test%20URL-encoded%20stuff',
'http://مثال.إختبار',
'http://例子.测试',
'http://1337.net',
'http://a.b-c.de',
'http://223.255.255.254',
'http://киррилический/адрес.рф',
'www.foo.bar',
'foo.bar',
'foo.bar#anchor'
]
INVALID_URL = [
'http://',
'http://?',
'http://??',
'http://??/',
'http://#',
'http://##',
'http://##/',
'http://foo.bar?q=Spaces should be encoded',
'//',
'//a',
'///a',
'///',
'http:///a',
'http:// shouldfail.com',
':// should fail',
'http://foo.bar/foo(bar)baz quux'
]
let(:r) { Regexy::Web::Url.new }
it 'accepts valid url' do
VALID_URL.each do |url|
expect(url =~ r).to be_truthy
end
end
it 'declines invalid url' do
INVALID_URL.each do |url|
expect(url =~ r).to be_nil
end
end
end