]> git.wincent.com - wikitext.git/blob - spec/tt_spec.rb
1a7c2d7df723f5aecb0a04ae0c601bd724ee1245
[wikitext.git] / spec / tt_spec.rb
1 #!/usr/bin/env ruby
2 # Copyright 2007-2009 Wincent Colaiuta. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
6 #
7 # 1. Redistributions of source code must retain the above copyright notice,
8 #    this list of conditions and the following disclaimer.
9 # 2. Redistributions in binary form must reproduce the above copyright notice,
10 #    this list of conditions and the following disclaimer in the documentation
11 #    and/or other materials provided with the distribution.
12
13 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
17 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 # POSSIBILITY OF SUCH DAMAGE.
24
25 require File.join(File.dirname(__FILE__), 'spec_helper.rb')
26 require 'wikitext'
27
28 describe Wikitext::Parser, 'parsing <tt> spans' do
29   before do
30     @parser = Wikitext::Parser.new
31   end
32
33   it 'should recognize paired <tt> and </tt> tags' do
34     @parser.parse('foo <tt>bar</tt> baz').should == "<p>foo <tt>bar</tt> baz</p>\n"
35   end
36
37   it 'should recognize <tt> tags case-insensitively' do
38     @parser.parse('foo <TT>bar</tT> baz').should == "<p>foo <tt>bar</tt> baz</p>\n"
39     @parser.parse('foo <tT>bar</Tt> baz').should == "<p>foo <tt>bar</tt> baz</p>\n"
40     @parser.parse('foo <Tt>bar</TT> baz').should == "<p>foo <tt>bar</tt> baz</p>\n"
41   end
42
43   it 'should automatically insert missing closing tags' do
44     @parser.parse('foo <tt>bar').should == "<p>foo <tt>bar</tt></p>\n"
45   end
46
47   it 'should automatically close unclosed spans upon hitting newline' do
48     @parser.parse("foo <tt>bar\nbaz").should == "<p>foo <tt>bar</tt> baz</p>\n"
49   end
50
51   it 'should convert unexpected closing tags into entities' do
52     @parser.parse('foo </tt>bar').should == "<p>foo &lt;/tt&gt;bar</p>\n"
53   end
54
55   it 'should handle (illegal) nested <tt> spans' do
56     @parser.parse('foo <tt>bar <tt>inner</tt></tt> baz').should == "<p>foo <tt>bar &lt;tt&gt;inner</tt>&lt;/tt&gt; baz</p>\n"
57   end
58
59   it 'should handle (illegal) interleaved spans' do
60     @parser.parse("foo <tt>bar '''inner</tt> baz'''").should == "<p>foo <tt>bar <strong>inner</strong></tt> baz<strong></strong></p>\n"
61   end
62
63   it 'should have no effect inside <pre> blocks' do
64     @parser.parse(' <tt>foo</tt>').should == "<pre>&lt;tt&gt;foo&lt;/tt&gt;</pre>\n"
65   end
66
67   it 'should have no effect inside <nowiki> spans' do
68     @parser.parse('<nowiki><tt>foo</tt></nowiki>').should == "<p>&lt;tt&gt;foo&lt;/tt&gt;</p>\n"
69   end
70
71   it 'should have no effect if a backtick span is already open' do
72     @parser.parse('foo `<tt>bar</tt>` baz').should == "<p>foo <tt>&lt;tt&gt;bar&lt;/tt&gt;</tt> baz</p>\n"
73   end
74 end
75
76 describe Wikitext::Parser, 'parsing backtick spans' do
77   before do
78     @parser = Wikitext::Parser.new
79   end
80
81   it 'should recognize paired backticks' do
82     @parser.parse('foo `bar` baz').should == "<p>foo <tt>bar</tt> baz</p>\n"
83   end
84
85   it 'should automatically insert missing closing backtick' do
86     @parser.parse('foo `bar').should == "<p>foo <tt>bar</tt></p>\n"
87   end
88
89   it 'should automatically close unclosed spans upon hitting newline' do
90     @parser.parse("foo `bar\nbaz").should == "<p>foo <tt>bar</tt> baz</p>\n"
91   end
92
93   it 'should handle (illegal) interleaved spans' do
94     @parser.parse("foo `bar '''inner` baz'''").should == "<p>foo <tt>bar <strong>inner</strong></tt> baz<strong></strong></p>\n"
95   end
96
97   it 'should have no effect inside <pre> blocks' do
98     @parser.parse(' `foo`').should == "<pre>`foo`</pre>\n"
99   end
100
101   it 'should have no effect inside <nowiki> spans' do
102     @parser.parse('<nowiki>`foo`</nowiki>').should == "<p>`foo`</p>\n"
103   end
104
105   it 'should have no effect if a <tt> span is already open' do
106     @parser.parse('foo <tt>`bar`</tt> baz').should == "<p>foo <tt>`bar`</tt> baz</p>\n"
107   end
108 end
109