jgarber / redcloth

RedCloth is a Ruby library for converting Textile into HTML.

This URL has Read+Write access

redcloth / spec / parser_spec.rb
b8074585 » jgarber 2009-05-19 Convert tests to RSpec. 1 require File.dirname(__FILE__) + '/spec_helper'
2
3 describe RedCloth do
4
5 describe "#new" do
6 it "should accept options" do
7 lambda {
8 RedCloth.new("test", [:hard_breaks])
9 }.should_not raise_error(ArgumentError)
10 end
11 end
12
13 it "should have a VERSION" do
14 RedCloth.const_defined?("VERSION").should be_true
15 RedCloth::VERSION.const_defined?("STRING").should be_true
16 end
17
18 it "should show the version as a string" do
19 RedCloth::VERSION::STRING.should == RedCloth::VERSION.to_s
20 RedCloth::VERSION.should == RedCloth::VERSION::STRING
21 end
22
23 it "should have EXTENSION_LANGUAGE" do
24 RedCloth.const_defined?("EXTENSION_LANGUAGE").should be_true
25 RedCloth::EXTENSION_LANGUAGE.should_not be_empty
26 RedCloth::DESCRIPTION.should include(RedCloth::EXTENSION_LANGUAGE)
27 end
28
29 it "should not segfault on a badly formatted table" do
30 RedCloth.new(%Q{| one | two |\nthree | four |}).to_html.should =~ /td/
31 end
32
33 it "should not segfault on a table without a block end" do
34 RedCloth.new("| a | b |\n| c | d |\nh3. foo").to_html.should =~ /h3/
35 end
36
37 it "should not segfault on a table with empty cells" do
38 RedCloth.new(%Q{|one || |\nthree | four |}).to_html.should =~ /td/
39 end
40
41 it "should not segfault on an unfinished html block with filter_html" do
42 lambda { RedCloth.new(%Q{<hr> Some text}, [:filter_html]).to_html }.should_not raise_error
43 end
44
45 it "should parse RedCloth::VERSION in input" do
46 RedCloth.new("RedCloth::VERSION").to_html.should == "<p>#{RedCloth::VERSION::STRING}</p>"
47 end
48
49 it "should not parse RedCloth::VERSION if it's not on a line by itself" do
50 input = "RedCloth::VERSION won't output the RedCloth::VERSION unless it's on a line all by itself.\n\nRedCloth::VERSION"
51 html = "<p>RedCloth::<span class=\"caps\">VERSION</span> won&#8217;t output the RedCloth::<span class=\"caps\">VERSION</span> unless it&#8217;s on a line all by itself.</p>\n<p>#{RedCloth::VERSION::STRING}</p>"
52 RedCloth.new(input).to_html.should == html
53 end
54
55 it "should output the RedCloth::VERSION if it's labeled on a line by itself" do
56 input = "RedCloth::VERSION: RedCloth::VERSION"
57 html = "<p>RedCloth::VERSION: #{RedCloth::VERSION::STRING}</p>"
58 RedCloth.new(input).to_html.should == html
59 end
60
61 it "should output the RedCloth::VERSION if it's labeled in a sentence on a line by itself" do
62 input = "RedCloth version RedCloth::VERSION"
63 html = "<p>RedCloth version #{RedCloth::VERSION::STRING}</p>"
64 RedCloth.new(input).to_html.should == html
65 end
66
67 it "should output the RedCloth::VERSION in brackets" do
68 input = "The current RedCloth version is [RedCloth::VERSION]"
69 html = "<p>The current RedCloth version is #{RedCloth::VERSION::STRING}</p>"
70 RedCloth.new(input).to_html.should == html
71 end
72
73 it "should strip carriage returns" do
74 input = "This is a paragraph\r\n\r\nThis is a\r\nline break.\r\n\r\n<div>\r\ntest\r\n\r\n</div>"
75 html = "<p>This is a paragraph</p>\n<p>This is a<br />\nline break.</p>\n<div>\n<p>test</p>\n</div>"
76 RedCloth.new(input).to_html.should == html
77 end
bd652f9f » jgarber 2009-06-10 Pass string encoding throug... 78
79 if RUBY_VERSION > "1.9.0"
80 it "should preserve character encoding" do
81 input = "This is an ISO-8859-1 string"
82 input.force_encoding 'iso-8859-1'
83 output = RedCloth.new(input).to_html
84
85 output.should == "<p>This is an <span class=\"caps\">ISO</span>-8859-1 string</p>"
86 output.encoding.to_s.should == "ISO-8859-1"
87 end
88
89 it "should not raise ArgumentError: invalid byte sequence" do
90 s = "\xa3"
91 s.force_encoding 'iso-8859-1'
92 lambda { RedCloth.new(s).to_html }.should_not raise_error
93 end
94 end
b8074585 » jgarber 2009-05-19 Convert tests to RSpec. 95 end