]> git.wincent.com - wikitext.git/blob - spec/autolinking_spec.rb
c0090941a4fda859421d09e6e6581e156db39d0f
[wikitext.git] / spec / autolinking_spec.rb
1 # Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are met:
5 #
6 # 1. Redistributions of source code must retain the above copyright notice,
7 #    this list of conditions and the following disclaimer.
8 # 2. Redistributions in binary form must reproduce the above copyright notice,
9 #    this list of conditions and the following disclaimer in the documentation
10 #    and/or other materials provided with the distribution.
11
12 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
13 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
16 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
18 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22 # POSSIBILITY OF SUCH DAMAGE.
23
24 require 'spec_helper'
25
26 describe Wikitext::Parser, 'autolinking' do
27   before do
28     @parser = Wikitext::Parser.new
29   end
30
31   it 'should default to autolinking on' do
32     @parser.autolink.should == true
33   end
34
35   describe 'on' do
36     it 'should convert HTTP URIs into hyperlinks' do
37       uri = 'http://example.com/'
38       @parser.parse(uri).should == %Q{<p><a href="http://example.com/" class="external">http://example.com/</a></p>\n}
39     end
40
41     it 'should convert HTTPS URIs into hyperlinks' do
42       uri = 'https://example.com/'
43       @parser.parse(uri).should == %Q{<p><a href="https://example.com/" class="external">https://example.com/</a></p>\n}
44     end
45
46     it 'should convert FTP URIs into hyperlinks' do
47       uri = 'ftp://example.com/'
48       @parser.parse(uri).should == %Q{<p><a href="ftp://example.com/" class="external">ftp://example.com/</a></p>\n}
49     end
50
51     it 'should convert mailto URIs into hyperlinks' do
52       uri = 'mailto:user@example.com'
53       @parser.parse(uri).should == %Q{<p><a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a></p>\n}
54     end
55
56     it 'should convert SVN URIs into hyperlinks' do
57       uri = 'svn://example.com/'
58       @parser.parse(uri).should == %Q{<p><a href="svn://example.com/" class="external">svn://example.com/</a></p>\n}
59     end
60
61     it 'should apple the external_link_class CSS class if set' do
62       uri = 'http://example.com/'
63       @parser.external_link_class = 'bar'
64       @parser.parse(uri).should == %Q{<p><a href="http://example.com/" class="bar">http://example.com/</a></p>\n}
65     end
66
67     it 'should apply no CSS if external_link_class is set to nil' do
68       uri = 'http://example.com/'
69       @parser.external_link_class = nil
70       @parser.parse(uri).should == %Q{<p><a href="http://example.com/">http://example.com/</a></p>\n}
71     end
72
73     it 'should pass through URIs unchanged inside <nowiki></nowiki> spans' do
74       @parser.parse("<nowiki>http://example.com/</nowiki>").should == "<p>http://example.com/</p>\n"
75     end
76
77     it 'should autolink URIs inside <pre></pre> spans' do
78       input     = ' http://example.com/'
79       expected  = %Q{<pre><a href="http://example.com/" class="external">http://example.com/</a></pre>\n}
80       @parser.parse(input).should == expected
81       @parser.external_link_class = nil
82       expected  = %Q{<pre><a href="http://example.com/">http://example.com/</a></pre>\n}
83       @parser.parse(input).should == expected
84     end
85
86     it 'should convert emails into hyperlinks' do
87       uri = 'user@example.com'
88       @parser.parse(uri).should == %Q{<p><a href="mailto:user@example.com" class="mailto">user@example.com</a></p>\n}
89     end
90
91     it 'should apply the mailto CSS class if set (raw address)' do
92       uri = 'user@example.com'
93       @parser.mailto_class = 'foo'
94       @parser.parse(uri).should == %Q{<p><a href="mailto:user@example.com" class="foo">user@example.com</a></p>\n}
95     end
96
97     it 'should apply the mailto CSS class if set (mailto URI)' do
98       uri = 'mailto:user@example.com'
99       @parser.mailto_class = 'foo'
100       @parser.parse(uri).should == %Q{<p><a href="mailto:user@example.com" class="foo">mailto:user@example.com</a></p>\n}
101     end
102
103     it 'should apply no CSS if the mailto class is set to nil (raw address)' do
104       uri = 'user@example.com'
105       @parser.mailto_class = nil
106       @parser.parse(uri).should == %Q{<p><a href="mailto:user@example.com">user@example.com</a></p>\n}
107     end
108
109     it 'should apply no CSS if the mailto class is set to nil (mailto URI)' do
110       uri = 'mailto:user@example.com'
111       @parser.mailto_class = nil
112       @parser.parse(uri).should == %Q{<p><a href="mailto:user@example.com">mailto:user@example.com</a></p>\n}
113     end
114
115     it 'should pass through emails unchanged inside <nowiki></nowiki> spans' do
116       @parser.parse("<nowiki>user@example.com</nowiki>").should == "<p>user@example.com</p>\n"  # was a crasher
117     end
118
119     it 'should pass through emails unchanged inside <pre></pre> blocks' do
120       @parser.parse(" user@example.com").should == "<pre>user@example.com</pre>\n"  # was a crasher
121     end
122   end
123
124   describe 'off' do
125     before do
126       @parser.autolink = false
127     end
128
129     it 'should accept "autolink = false"' do
130       @parser.autolink.should == false
131     end
132
133     it 'should not convert URIs into hyperlinks' do
134       @parser.parse('http://example.com/').should == "<p>http://example.com/</p>\n"
135     end
136
137     it 'should not convert emails into hyperlinks' do
138       @parser.parse('user@example.com').should == "<p>user@example.com</p>\n"
139     end
140   end
141
142   # "special" URI characters are characters that are valid _within_ a URI
143   # but if they appear as delimiters (at the end of a URI) we want them to be excluded from the URI
144   describe 'handling "special" URI characters' do
145     describe 'after HTTP URIs' do
146       it 'should terminate if followed by a period' do
147         input     = 'Try http://example.com/.'
148         expected  = %Q{<p>Try <a href="http://example.com/" class="external">http://example.com/</a>.</p>\n}
149         @parser.parse(input).should == expected
150       end
151
152       it 'should not terminate on periods that occur within the URI' do
153         input     = 'Try http://www.example.com/.'
154         expected  = %Q{<p>Try <a href="http://www.example.com/" class="external">http://www.example.com/</a>.</p>\n}
155         @parser.parse(input).should == expected
156       end
157
158       it 'should terminate if followed by a colon' do
159         input     = 'Try http://example.com/:'
160         expected  = %Q{<p>Try <a href="http://example.com/" class="external">http://example.com/</a>:</p>\n}
161         @parser.parse(input).should == expected
162       end
163
164       it 'should not terminate on colons that occur within the URI' do
165         input     = 'Try http://example.com:3000/.'
166         expected  = %Q{<p>Try <a href="http://example.com:3000/" class="external">http://example.com:3000/</a>.</p>\n}
167         @parser.parse(input).should == expected
168       end
169
170       it 'should terminate if followed by a comma' do
171         input     = 'Try http://example.com/,'
172         expected  = %Q{<p>Try <a href="http://example.com/" class="external">http://example.com/</a>,</p>\n}
173         @parser.parse(input).should == expected
174       end
175
176       it 'should not terminate on commas that occur within the URI' do
177         input     = 'Try http://example.com/2008,10,12,index.html.'
178         expected  = %Q{<p>Try <a href="http://example.com/2008,10,12,index.html" class="external">http://example.com/2008,10,12,index.html</a>.</p>\n}
179         @parser.parse(input).should == expected
180       end
181
182       it 'should terminate if followed by an exclamation mark' do
183         input     = 'Try http://example.com/!'
184         expected  = %Q{<p>Try <a href="http://example.com/" class="external">http://example.com/</a>!</p>\n}
185         @parser.parse(input).should == expected
186       end
187
188       it 'should not terminate on exclamation marks that occur within the URI' do
189         input     = 'Try http://example.com/fun!.html.'
190         expected  = %Q{<p>Try <a href="http://example.com/fun!.html" class="external">http://example.com/fun!.html</a>.</p>\n}
191         @parser.parse(input).should == expected
192       end
193
194       it 'should terminate if followed by a question mark' do
195         input     = 'Try http://example.com/?'
196         expected  = %Q{<p>Try <a href="http://example.com/" class="external">http://example.com/</a>?</p>\n}
197         @parser.parse(input).should == expected
198       end
199
200       it 'should not terminate on question marks that occur within the URI' do
201         input     = 'Try http://example.com/fun.html?q=foo.'
202         expected  = %Q{<p>Try <a href="http://example.com/fun.html?q=foo" class="external">http://example.com/fun.html?q=foo</a>.</p>\n}
203         @parser.parse(input).should == expected
204       end
205
206       it 'should terminate if followed by a semi-colon' do
207         input     = 'Try http://example.com/;'
208         expected  = %Q{<p>Try <a href="http://example.com/" class="external">http://example.com/</a>;</p>\n}
209         @parser.parse(input).should == expected
210       end
211
212       it 'should not terminate on semi-colons that occur within the URI' do
213         input     = 'Try http://example.com/fun;edit.'
214         expected  = %Q{<p>Try <a href="http://example.com/fun;edit" class="external">http://example.com/fun;edit</a>.</p>\n}
215         @parser.parse(input).should == expected
216       end
217
218       it 'should terminate if followed by a right parenthesis' do
219         input     = '(Try http://example.com/)'
220         expected  = %Q{<p>(Try <a href="http://example.com/" class="external">http://example.com/</a>)</p>\n}
221         @parser.parse(input).should == expected
222       end
223
224       it 'should not terminate on right-parentheses that occur within the URI' do
225         input     = 'Try http://example.com/(fun).html.'
226         expected  = %Q{<p>Try <a href="http://example.com/(fun).html" class="external">http://example.com/(fun).html</a>.</p>\n}
227         @parser.parse(input).should == expected
228       end
229     end
230
231     describe 'after HTTPS URIs' do
232       it 'should terminate if followed by a period' do
233         input     = 'Try https://example.com/.'
234         expected  = %Q{<p>Try <a href="https://example.com/" class="external">https://example.com/</a>.</p>\n}
235         @parser.parse(input).should == expected
236       end
237
238       it 'should not terminate on periods that occur within the URI' do
239         input     = 'Try https://www.example.com/.'
240         expected  = %Q{<p>Try <a href="https://www.example.com/" class="external">https://www.example.com/</a>.</p>\n}
241         @parser.parse(input).should == expected
242       end
243
244       it 'should terminate if followed by a colon' do
245         input     = 'Try https://example.com/:'
246         expected  = %Q{<p>Try <a href="https://example.com/" class="external">https://example.com/</a>:</p>\n}
247         @parser.parse(input).should == expected
248       end
249
250       it 'should not terminate on colons that occur within the URI' do
251         input     = 'Try https://example.com:3000/.'
252         expected  = %Q{<p>Try <a href="https://example.com:3000/" class="external">https://example.com:3000/</a>.</p>\n}
253         @parser.parse(input).should == expected
254       end
255
256       it 'should terminate if followed by a comma' do
257         input     = 'Try https://example.com/,'
258         expected  = %Q{<p>Try <a href="https://example.com/" class="external">https://example.com/</a>,</p>\n}
259         @parser.parse(input).should == expected
260       end
261
262       it 'should not terminate on commas that occur within the URI' do
263         input     = 'Try https://example.com/2008,10,12,index.html.'
264         expected  = %Q{<p>Try <a href="https://example.com/2008,10,12,index.html" class="external">https://example.com/2008,10,12,index.html</a>.</p>\n}
265         @parser.parse(input).should == expected
266       end
267
268       it 'should terminate if followed by an exclamation mark' do
269         input     = 'Try https://example.com/!'
270         expected  = %Q{<p>Try <a href="https://example.com/" class="external">https://example.com/</a>!</p>\n}
271         @parser.parse(input).should == expected
272       end
273
274       it 'should not terminate on exclamation marks that occur within the URI' do
275         input     = 'Try https://example.com/fun!.html.'
276         expected  = %Q{<p>Try <a href="https://example.com/fun!.html" class="external">https://example.com/fun!.html</a>.</p>\n}
277         @parser.parse(input).should == expected
278       end
279
280       it 'should terminate if followed by a question mark' do
281         input     = 'Try https://example.com/?'
282         expected  = %Q{<p>Try <a href="https://example.com/" class="external">https://example.com/</a>?</p>\n}
283         @parser.parse(input).should == expected
284       end
285
286       it 'should not terminate on question marks that occur within the URI' do
287         input     = 'Try https://example.com/fun.html?q=foo.'
288         expected  = %Q{<p>Try <a href="https://example.com/fun.html?q=foo" class="external">https://example.com/fun.html?q=foo</a>.</p>\n}
289         @parser.parse(input).should == expected
290       end
291
292       it 'should terminate if followed by a semi-colon' do
293         input     = 'Try https://example.com/;'
294         expected  = %Q{<p>Try <a href="https://example.com/" class="external">https://example.com/</a>;</p>\n}
295         @parser.parse(input).should == expected
296       end
297
298       it 'should not terminate on semi-colons that occur within the URI' do
299         input     = 'Try https://example.com/fun;edit.'
300         expected  = %Q{<p>Try <a href="https://example.com/fun;edit" class="external">https://example.com/fun;edit</a>.</p>\n}
301         @parser.parse(input).should == expected
302       end
303
304       it 'should terminate if followed by a right parenthesis' do
305         input     = '(Try https://example.com/)'
306         expected  = %Q{<p>(Try <a href="https://example.com/" class="external">https://example.com/</a>)</p>\n}
307         @parser.parse(input).should == expected
308       end
309
310       it 'should not terminate on right-parentheses that occur within the URI' do
311         input     = 'Try https://example.com/(fun).html.'
312         expected  = %Q{<p>Try <a href="https://example.com/(fun).html" class="external">https://example.com/(fun).html</a>.</p>\n}
313         @parser.parse(input).should == expected
314       end
315     end
316
317     # note: these are just like the HTTP specs seeing as both URI types are treated the same syntactically
318     # (even though these aren't "real" FTP URIs)
319     describe 'after FTP URIs' do
320       it 'should terminate if followed by a period' do
321         input     = 'Try ftp://example.com/.'
322         expected  = %Q{<p>Try <a href="ftp://example.com/" class="external">ftp://example.com/</a>.</p>\n}
323         @parser.parse(input).should == expected
324       end
325
326       it 'should not terminate on periods that occur within the URI' do
327         input     = 'Try ftp://www.example.com/.'
328         expected  = %Q{<p>Try <a href="ftp://www.example.com/" class="external">ftp://www.example.com/</a>.</p>\n}
329         @parser.parse(input).should == expected
330       end
331
332       it 'should terminate if followed by a colon' do
333         input     = 'Try ftp://example.com/:'
334         expected  = %Q{<p>Try <a href="ftp://example.com/" class="external">ftp://example.com/</a>:</p>\n}
335         @parser.parse(input).should == expected
336       end
337
338       it 'should not terminate on colons that occur within the URI' do
339         input     = 'Try ftp://example.com:3000/.'
340         expected  = %Q{<p>Try <a href="ftp://example.com:3000/" class="external">ftp://example.com:3000/</a>.</p>\n}
341         @parser.parse(input).should == expected
342       end
343
344       it 'should terminate if followed by a comma' do
345         input     = 'Try ftp://example.com/,'
346         expected  = %Q{<p>Try <a href="ftp://example.com/" class="external">ftp://example.com/</a>,</p>\n}
347         @parser.parse(input).should == expected
348       end
349
350       it 'should not terminate on commas that occur within the URI' do
351         input     = 'Try ftp://example.com/2008,10,12,index.html.'
352         expected  = %Q{<p>Try <a href="ftp://example.com/2008,10,12,index.html" class="external">ftp://example.com/2008,10,12,index.html</a>.</p>\n}
353         @parser.parse(input).should == expected
354       end
355
356       it 'should terminate if followed by an exclamation mark' do
357         input     = 'Try ftp://example.com/!'
358         expected  = %Q{<p>Try <a href="ftp://example.com/" class="external">ftp://example.com/</a>!</p>\n}
359         @parser.parse(input).should == expected
360       end
361
362       it 'should not terminate on exclamation marks that occur within the URI' do
363         input     = 'Try ftp://example.com/fun!.html.'
364         expected  = %Q{<p>Try <a href="ftp://example.com/fun!.html" class="external">ftp://example.com/fun!.html</a>.</p>\n}
365         @parser.parse(input).should == expected
366       end
367
368       it 'should terminate if followed by a question mark' do
369         input     = 'Try ftp://example.com/?'
370         expected  = %Q{<p>Try <a href="ftp://example.com/" class="external">ftp://example.com/</a>?</p>\n}
371         @parser.parse(input).should == expected
372       end
373
374       it 'should not terminate on question marks that occur within the URI' do
375         input     = 'Try ftp://example.com/fun.html?q=foo.'
376         expected  = %Q{<p>Try <a href="ftp://example.com/fun.html?q=foo" class="external">ftp://example.com/fun.html?q=foo</a>.</p>\n}
377         @parser.parse(input).should == expected
378       end
379
380       it 'should terminate if followed by a semi-colon' do
381         input     = 'Try ftp://example.com/;'
382         expected  = %Q{<p>Try <a href="ftp://example.com/" class="external">ftp://example.com/</a>;</p>\n}
383         @parser.parse(input).should == expected
384       end
385
386       it 'should not terminate on semi-colons that occur within the URI' do
387         input     = 'Try ftp://example.com/fun;edit.'
388         expected  = %Q{<p>Try <a href="ftp://example.com/fun;edit" class="external">ftp://example.com/fun;edit</a>.</p>\n}
389         @parser.parse(input).should == expected
390       end
391
392       it 'should terminate if followed by a right parenthesis' do
393         input     = '(Try ftp://example.com/)'
394         expected  = %Q{<p>(Try <a href="ftp://example.com/" class="external">ftp://example.com/</a>)</p>\n}
395         @parser.parse(input).should == expected
396       end
397
398       it 'should not terminate on right-parentheses that occur within the URI' do
399         input     = 'Try ftp://example.com/(fun).html.'
400         expected  = %Q{<p>Try <a href="ftp://example.com/(fun).html" class="external">ftp://example.com/(fun).html</a>.</p>\n}
401         @parser.parse(input).should == expected
402       end
403     end
404
405     # note: these are just like the HTTP specs seeing as both URI types are treated the same syntactically
406     # (even though these aren't "real" SVN URIs)
407     describe 'after SVN URIs' do
408       it 'should terminate if followed by a period' do
409         input     = 'Try svn://example.com/.'
410         expected  = %Q{<p>Try <a href="svn://example.com/" class="external">svn://example.com/</a>.</p>\n}
411         @parser.parse(input).should == expected
412       end
413
414       it 'should not terminate on periods that occur within the URI' do
415         input     = 'Try svn://www.example.com/.'
416         expected  = %Q{<p>Try <a href="svn://www.example.com/" class="external">svn://www.example.com/</a>.</p>\n}
417         @parser.parse(input).should == expected
418       end
419
420       it 'should terminate if followed by a colon' do
421         input     = 'Try svn://example.com/:'
422         expected  = %Q{<p>Try <a href="svn://example.com/" class="external">svn://example.com/</a>:</p>\n}
423         @parser.parse(input).should == expected
424       end
425
426       it 'should not terminate on colons that occur within the URI' do
427         input     = 'Try svn://example.com:3000/.'
428         expected  = %Q{<p>Try <a href="svn://example.com:3000/" class="external">svn://example.com:3000/</a>.</p>\n}
429         @parser.parse(input).should == expected
430       end
431
432       it 'should terminate if followed by a comma' do
433         input     = 'Try svn://example.com/,'
434         expected  = %Q{<p>Try <a href="svn://example.com/" class="external">svn://example.com/</a>,</p>\n}
435         @parser.parse(input).should == expected
436       end
437
438       it 'should not terminate on commas that occur within the URI' do
439         input     = 'Try svn://example.com/2008,10,12,index.html.'
440         expected  = %Q{<p>Try <a href="svn://example.com/2008,10,12,index.html" class="external">svn://example.com/2008,10,12,index.html</a>.</p>\n}
441         @parser.parse(input).should == expected
442       end
443
444       it 'should terminate if followed by an exclamation mark' do
445         input     = 'Try svn://example.com/!'
446         expected  = %Q{<p>Try <a href="svn://example.com/" class="external">svn://example.com/</a>!</p>\n}
447         @parser.parse(input).should == expected
448       end
449
450       it 'should not terminate on exclamation marks that occur within the URI' do
451         input     = 'Try svn://example.com/fun!.html.'
452         expected  = %Q{<p>Try <a href="svn://example.com/fun!.html" class="external">svn://example.com/fun!.html</a>.</p>\n}
453         @parser.parse(input).should == expected
454       end
455
456       it 'should terminate if followed by a question mark' do
457         input     = 'Try svn://example.com/?'
458         expected  = %Q{<p>Try <a href="svn://example.com/" class="external">svn://example.com/</a>?</p>\n}
459         @parser.parse(input).should == expected
460       end
461
462       it 'should not terminate on question marks that occur within the URI' do
463         input     = 'Try svn://example.com/fun.html?q=foo'
464         expected  = %Q{<p>Try <a href="svn://example.com/fun.html?q=foo" class="external">svn://example.com/fun.html?q=foo</a></p>\n}
465         @parser.parse(input).should == expected
466       end
467
468       it 'should terminate if followed by a semi-colon' do
469         input     = 'Try svn://example.com/;'
470         expected  = %Q{<p>Try <a href="svn://example.com/" class="external">svn://example.com/</a>;</p>\n}
471         @parser.parse(input).should == expected
472       end
473
474       it 'should not terminate on semi-colons that occur within the URI' do
475         input     = 'Try svn://example.com/fun;edit.'
476         expected  = %Q{<p>Try <a href="svn://example.com/fun;edit" class="external">svn://example.com/fun;edit</a>.</p>\n}
477         @parser.parse(input).should == expected
478       end
479
480       it 'should terminate if followed by a right parenthesis' do
481         input     = '(Try svn://example.com/)'
482         expected  = %Q{<p>(Try <a href="svn://example.com/" class="external">svn://example.com/</a>)</p>\n}
483         @parser.parse(input).should == expected
484       end
485
486       it 'should not terminate on right-parentheses that occur within the URI' do
487         input     = 'Try svn://example.com/(fun).html.'
488         expected  = %Q{<p>Try <a href="svn://example.com/(fun).html" class="external">svn://example.com/(fun).html</a>.</p>\n}
489         @parser.parse(input).should == expected
490       end
491     end
492
493     # fewer specs here because the range of "mailto:" URIs recognized by the scanner is more limited
494     # (compared with, say, HTTP or HTTPS)
495     describe 'after "mailto:" URIs' do
496       it 'should terminate if followed by a period' do
497         input     = 'Try mailto:user@example.com.'
498         expected  = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a>.</p>\n}
499         @parser.parse(input).should == expected
500       end
501
502       it 'should not terminate on periods that occur within the URI' do
503         input     = 'Try mailto:user.name@example.com.'
504         expected  = %Q{<p>Try <a href="mailto:user.name@example.com" class="mailto">mailto:user.name@example.com</a>.</p>\n}
505         @parser.parse(input).should == expected
506       end
507
508       it 'should terminate if followed by a colon' do
509         input     = 'Try mailto:user@example.com:'
510         expected  = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a>:</p>\n}
511         @parser.parse(input).should == expected
512       end
513
514       it 'should terminate if followed by a comma' do
515         input     = 'Try mailto:user@example.com,'
516         expected  = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a>,</p>\n}
517         @parser.parse(input).should == expected
518       end
519
520       it 'should terminate if followed by an exclamation mark' do
521         input     = 'Try mailto:user@example.com!'
522         expected  = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a>!</p>\n}
523         @parser.parse(input).should == expected
524       end
525
526       it 'should terminate if followed by a question mark' do
527         input     = 'Try mailto:user@example.com?'
528         expected  = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a>?</p>\n}
529         @parser.parse(input).should == expected
530       end
531
532       it 'should not terminate on question marks that occur within the URI' do
533         pending
534         # this kind of autolink never worked (will require changes to the Ragel scanner)
535         input     = 'Try mailto:user@example.com?subject=foo?'
536         expected  = %Q{<p>Try <a href="mailto:user@example.com?subject=foo" class="external">mailto:user@example.com?subject=foo</a>.</p>\n}
537         @parser.parse(input).should == expected
538       end
539
540       it 'should terminate if followed by a semi-colon' do
541         input     = 'Try mailto:user@example.com;'
542         expected  = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a>;</p>\n}
543         @parser.parse(input).should == expected
544       end
545
546       it 'should terminate if followed by a right parenthesis' do
547         input     = '(Try mailto:user@example.com)'
548         expected  = %Q{<p>(Try <a href="mailto:user@example.com" class="mailto">mailto:user@example.com</a>)</p>\n}
549         @parser.parse(input).should == expected
550       end
551     end
552
553     describe 'after email addresses' do
554       it 'should terminate if followed by a period' do
555         input     = 'Try user@example.com.'
556         expected  = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">user@example.com</a>.</p>\n}
557         @parser.parse(input).should == expected
558       end
559
560       it 'should not terminate on periods that occur within the email address' do
561         input     = 'Try user.name@example.com.'
562         expected  = %Q{<p>Try <a href="mailto:user.name@example.com" class="mailto">user.name@example.com</a>.</p>\n}
563         @parser.parse(input).should == expected
564       end
565
566       it 'should terminate if followed by a colon' do
567         input     = 'Try user@example.com:'
568         expected  = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">user@example.com</a>:</p>\n}
569         @parser.parse(input).should == expected
570       end
571
572       it 'should terminate if followed by a comma' do
573         input     = 'Try user@example.com,'
574         expected  = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">user@example.com</a>,</p>\n}
575         @parser.parse(input).should == expected
576       end
577
578       it 'should terminate if followed by an exclamation mark' do
579         input     = 'Try user@example.com!'
580         expected  = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">user@example.com</a>!</p>\n}
581         @parser.parse(input).should == expected
582       end
583
584       it 'should terminate if followed by a question mark' do
585         input     = 'Try user@example.com?'
586         expected  = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">user@example.com</a>?</p>\n}
587         @parser.parse(input).should == expected
588       end
589
590       it 'should terminate if followed by a semi-colon' do
591         input     = 'Try user@example.com;'
592         expected  = %Q{<p>Try <a href="mailto:user@example.com" class="mailto">user@example.com</a>;</p>\n}
593         @parser.parse(input).should == expected
594       end
595
596       it 'should terminate if followed by a right parenthesis' do
597         input     = '(Try user@example.com)'
598         expected  = %Q{<p>(Try <a href="mailto:user@example.com" class="mailto">user@example.com</a>)</p>\n}
599         @parser.parse(input).should == expected
600       end
601     end
602
603     describe 'before HTTP URIs' do
604       it 'should handle left parenthesis before' do
605         input = "The site (http://example.com/)"
606         expected = %Q{<p>The site (<a href="http://example.com/" class="external">http://example.com/</a>)</p>\n}
607         @parser.parse(input).should == expected
608       end
609     end
610
611     describe 'before email addresses' do
612       it 'should handle left parenthesis before' do
613         input = "Email me (user@example.com)"
614         expected = %Q{<p>Email me (<a href="mailto:user@example.com" class="mailto">user@example.com</a>)</p>\n}
615         @parser.parse(input).should == expected
616       end
617     end
618   end
619 end