Commit aef712f6069ae8349c5d673af26bea779f186689

Add some unit tests for url parsing. Still failing some tests, but getting closer.
  
5151 # XXX: what if there is a # in the url?
5252 # XXX: + also breaks it
5353
54 new.gsub!(/(https?:\/\/[a-zA-Z0-9\/._%-]+)/, '<a href="">
54 # maybe laconica-0.7.3/lib/util.php:common_replace_urls_callback() ?
55 new.gsub!(/(https?:\/\/[a-zA-Z0-9\/._%-+?#]+)/, '<a href="\1">\1</a>')
5556 new.gsub!(/@([0-9a-zA-Z_]+)/, '@<a href="http://twitter.com/\1">\1</a>')
5657
5758 return new
6767
6868 # don't turn eg &#39; into a link.
6969
70 # hashtag regexp in laconica is /(?:^|\s)#([A-Za-z0-9_\-\.]{1,64})/
7071 new.gsub!(/#((?!39;)\S+)/, '#<a href="http://identi.ca/tag/\1">\1</a>')
72
73 # group regexp in laconica is /(?:^|\s)!([A-Za-z0-9]{1,64})
7174 new.gsub!(/(?:!(\S+))/, '!<a href="http://identi.ca/group/\1">\1</a>')
7275
7376 return new
  
1require 'test/unit'
2require 'coefficient'
3require 'shoulda'
4
5class UnitTests < Test::Unit::TestCase
6 context "correctly parse urls" do
7 setup do
8 end
9
10 should "correctly parse basic URLs with no slash on the end" do
11 assert_equal "<a href=\"http://www.google.com\">http://www.google.com</a>", linkify("http://www.google.com")
12 end
13
14 should "correctly parse URLs with a slash on the end" do
15 assert_equal "<a href=\"http://www.google.com/\">http://www.google.com/</a>", linkify("http://www.google.com/")
16 end
17
18 should "correctly parse https urls" do
19 assert_equal "<a href=\"https://www.google.com/\">https://www.google.com/</a>", linkify("https://www.google.com/")
20 end
21
22 should "correctly parse urls with pages after a slash" do
23 assert_equal "<a href=\"https://www.google.com/link.html\">https://www.google.com/link.html</a>", linkify("https://www.google.com/link.html")
24 end
25
26 should "correctly parse urls with pages with ? in the url" do
27 assert_equal "<a href=\"https://www.google.com/?whatever.com\">https://www.google.com/?whatever.com</a>", linkify("https://www.google.com/?whatever.com")
28 end
29
30 should "correctly parse urls ending with a '.'" do
31 assert_equal "<a href=\"https://www.google.com/\">https://www.google.com/</a>", linkify("https://www.google.com/.")
32 end
33
34 should "correctly parse urls containing #." do
35 assert_equal "<a href=\"https://www.google.com/#anchor\">https://www.google.com/#anchor</a>", linkify("https://www.google.com/#anchor")
36 end
37
38 should "correctly parse urls containing +." do
39 assert_equal "<a href=\"https://www.google.com/+stuff\">https://www.google.com/+stuff</a>", linkify("https://www.google.com/+stuff")
40 end
41
42 end
43end