2 # Copyright 2007-2009 Wincent Colaiuta. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
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.
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.
25 require File.join(File.dirname(__FILE__), 'spec_helper.rb')
28 describe Wikitext::Parser, 'parsing <tt> spans' do
30 @parser = Wikitext::Parser.new
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"
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"
43 it 'should automatically insert missing closing tags' do
44 @parser.parse('foo <tt>bar').should == "<p>foo <tt>bar</tt></p>\n"
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"
51 it 'should convert unexpected closing tags into entities' do
52 @parser.parse('foo </tt>bar').should == "<p>foo </tt>bar</p>\n"
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 <tt>inner</tt></tt> baz</p>\n"
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"
63 it 'should have no effect inside <pre> blocks' do
64 @parser.parse(' <tt>foo</tt>').should == "<pre><tt>foo</tt></pre>\n"
67 it 'should have no effect inside <nowiki> spans' do
68 @parser.parse('<nowiki><tt>foo</tt></nowiki>').should == "<p><tt>foo</tt></p>\n"
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><tt>bar</tt></tt> baz</p>\n"
76 describe Wikitext::Parser, 'parsing backtick spans' do
78 @parser = Wikitext::Parser.new
81 it 'should recognize paired backticks' do
82 @parser.parse('foo `bar` baz').should == "<p>foo <tt>bar</tt> baz</p>\n"
85 it 'should automatically insert missing closing backtick' do
86 @parser.parse('foo `bar').should == "<p>foo <tt>bar</tt></p>\n"
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"
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"
97 it 'should have no effect inside <pre> blocks' do
98 @parser.parse(' `foo`').should == "<pre>`foo`</pre>\n"
101 it 'should have no effect inside <nowiki> spans' do
102 @parser.parse('<nowiki>`foo`</nowiki>').should == "<p>`foo`</p>\n"
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"