@@ -1,211 +1,211 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 |
# Copyright (C) 2006-201 |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 |
# |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 |
# |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../../../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../../../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class Redmine::WikiFormatting::TextileFormatterTest < HelperTestCase |
|
20 | class Redmine::WikiFormatting::TextileFormatterTest < HelperTestCase | |
21 |
|
21 | |||
22 | def setup |
|
22 | def setup | |
23 | @formatter = Redmine::WikiFormatting::Textile::Formatter |
|
23 | @formatter = Redmine::WikiFormatting::Textile::Formatter | |
24 | end |
|
24 | end | |
25 |
|
25 | |||
26 | MODIFIERS = { |
|
26 | MODIFIERS = { | |
27 | "*" => 'strong', # bold |
|
27 | "*" => 'strong', # bold | |
28 | "_" => 'em', # italic |
|
28 | "_" => 'em', # italic | |
29 | "+" => 'ins', # underline |
|
29 | "+" => 'ins', # underline | |
30 | "-" => 'del', # deleted |
|
30 | "-" => 'del', # deleted | |
31 | "^" => 'sup', # superscript |
|
31 | "^" => 'sup', # superscript | |
32 | "~" => 'sub' # subscript |
|
32 | "~" => 'sub' # subscript | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | def test_modifiers |
|
35 | def test_modifiers | |
36 | assert_html_output( |
|
36 | assert_html_output( | |
37 | '*bold*' => '<strong>bold</strong>', |
|
37 | '*bold*' => '<strong>bold</strong>', | |
38 | 'before *bold*' => 'before <strong>bold</strong>', |
|
38 | 'before *bold*' => 'before <strong>bold</strong>', | |
39 | '*bold* after' => '<strong>bold</strong> after', |
|
39 | '*bold* after' => '<strong>bold</strong> after', | |
40 | '*two words*' => '<strong>two words</strong>', |
|
40 | '*two words*' => '<strong>two words</strong>', | |
41 | '*two*words*' => '<strong>two*words</strong>', |
|
41 | '*two*words*' => '<strong>two*words</strong>', | |
42 | '*two * words*' => '<strong>two * words</strong>', |
|
42 | '*two * words*' => '<strong>two * words</strong>', | |
43 | '*two* *words*' => '<strong>two</strong> <strong>words</strong>', |
|
43 | '*two* *words*' => '<strong>two</strong> <strong>words</strong>', | |
44 | '*(two)* *(words)*' => '<strong>(two)</strong> <strong>(words)</strong>', |
|
44 | '*(two)* *(words)*' => '<strong>(two)</strong> <strong>(words)</strong>', | |
45 | # with class |
|
45 | # with class | |
46 | '*(foo)two words*' => '<strong class="foo">two words</strong>' |
|
46 | '*(foo)two words*' => '<strong class="foo">two words</strong>' | |
47 | ) |
|
47 | ) | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
50 | def test_modifiers_combination |
|
50 | def test_modifiers_combination | |
51 | MODIFIERS.each do |m1, tag1| |
|
51 | MODIFIERS.each do |m1, tag1| | |
52 | MODIFIERS.each do |m2, tag2| |
|
52 | MODIFIERS.each do |m2, tag2| | |
53 | next if m1 == m2 |
|
53 | next if m1 == m2 | |
54 | text = "#{m2}#{m1}Phrase modifiers#{m1}#{m2}" |
|
54 | text = "#{m2}#{m1}Phrase modifiers#{m1}#{m2}" | |
55 | html = "<#{tag2}><#{tag1}>Phrase modifiers</#{tag1}></#{tag2}>" |
|
55 | html = "<#{tag2}><#{tag1}>Phrase modifiers</#{tag1}></#{tag2}>" | |
56 | assert_html_output text => html |
|
56 | assert_html_output text => html | |
57 | end |
|
57 | end | |
58 | end |
|
58 | end | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def test_inline_code |
|
61 | def test_inline_code | |
62 | assert_html_output( |
|
62 | assert_html_output( | |
63 | 'this is @some code@' => 'this is <code>some code</code>', |
|
63 | 'this is @some code@' => 'this is <code>some code</code>', | |
64 | '@<Location /redmine>@' => '<code><Location /redmine></code>' |
|
64 | '@<Location /redmine>@' => '<code><Location /redmine></code>' | |
65 | ) |
|
65 | ) | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | def test_escaping |
|
68 | def test_escaping | |
69 | assert_html_output( |
|
69 | assert_html_output( | |
70 | 'this is a <script>' => 'this is a <script>' |
|
70 | 'this is a <script>' => 'this is a <script>' | |
71 | ) |
|
71 | ) | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def test_use_of_backslashes_followed_by_numbers_in_headers |
|
74 | def test_use_of_backslashes_followed_by_numbers_in_headers | |
75 | assert_html_output({ |
|
75 | assert_html_output({ | |
76 | 'h1. 2009\02\09' => '<h1>2009\02\09</h1>' |
|
76 | 'h1. 2009\02\09' => '<h1>2009\02\09</h1>' | |
77 | }, false) |
|
77 | }, false) | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | def test_double_dashes_should_not_strikethrough |
|
80 | def test_double_dashes_should_not_strikethrough | |
81 | assert_html_output( |
|
81 | assert_html_output( | |
82 | 'double -- dashes -- test' => 'double -- dashes -- test', |
|
82 | 'double -- dashes -- test' => 'double -- dashes -- test', | |
83 | 'double -- *dashes* -- test' => 'double -- <strong>dashes</strong> -- test' |
|
83 | 'double -- *dashes* -- test' => 'double -- <strong>dashes</strong> -- test' | |
84 | ) |
|
84 | ) | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | def test_acronyms |
|
87 | def test_acronyms | |
88 | assert_html_output( |
|
88 | assert_html_output( | |
89 | 'this is an acronym: GPL(General Public License)' => 'this is an acronym: <acronym title="General Public License">GPL</acronym>', |
|
89 | 'this is an acronym: GPL(General Public License)' => 'this is an acronym: <acronym title="General Public License">GPL</acronym>', | |
90 | '2 letters JP(Jean-Philippe) acronym' => '2 letters <acronym title="Jean-Philippe">JP</acronym> acronym', |
|
90 | '2 letters JP(Jean-Philippe) acronym' => '2 letters <acronym title="Jean-Philippe">JP</acronym> acronym', | |
91 | 'GPL(This is a double-quoted "title")' => '<acronym title="This is a double-quoted "title"">GPL</acronym>' |
|
91 | 'GPL(This is a double-quoted "title")' => '<acronym title="This is a double-quoted "title"">GPL</acronym>' | |
92 | ) |
|
92 | ) | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | def test_blockquote |
|
95 | def test_blockquote | |
96 | # orig raw text |
|
96 | # orig raw text | |
97 | raw = <<-RAW |
|
97 | raw = <<-RAW | |
98 | John said: |
|
98 | John said: | |
99 | > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. |
|
99 | > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. | |
100 | > Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. |
|
100 | > Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. | |
101 | > * Donec odio lorem, |
|
101 | > * Donec odio lorem, | |
102 | > * sagittis ac, |
|
102 | > * sagittis ac, | |
103 | > * malesuada in, |
|
103 | > * malesuada in, | |
104 | > * adipiscing eu, dolor. |
|
104 | > * adipiscing eu, dolor. | |
105 | > |
|
105 | > | |
106 | > >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus. |
|
106 | > >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus. | |
107 | > Proin a tellus. Nam vel neque. |
|
107 | > Proin a tellus. Nam vel neque. | |
108 |
|
108 | |||
109 | He's right. |
|
109 | He's right. | |
110 | RAW |
|
110 | RAW | |
111 |
|
111 | |||
112 | # expected html |
|
112 | # expected html | |
113 | expected = <<-EXPECTED |
|
113 | expected = <<-EXPECTED | |
114 | <p>John said:</p> |
|
114 | <p>John said:</p> | |
115 | <blockquote> |
|
115 | <blockquote> | |
116 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.<br /> |
|
116 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.<br /> | |
117 | Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. |
|
117 | Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. | |
118 | <ul> |
|
118 | <ul> | |
119 | <li>Donec odio lorem,</li> |
|
119 | <li>Donec odio lorem,</li> | |
120 | <li>sagittis ac,</li> |
|
120 | <li>sagittis ac,</li> | |
121 | <li>malesuada in,</li> |
|
121 | <li>malesuada in,</li> | |
122 | <li>adipiscing eu, dolor.</li> |
|
122 | <li>adipiscing eu, dolor.</li> | |
123 | </ul> |
|
123 | </ul> | |
124 | <blockquote> |
|
124 | <blockquote> | |
125 | <p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p> |
|
125 | <p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p> | |
126 | </blockquote> |
|
126 | </blockquote> | |
127 | <p>Proin a tellus. Nam vel neque.</p> |
|
127 | <p>Proin a tellus. Nam vel neque.</p> | |
128 | </blockquote> |
|
128 | </blockquote> | |
129 | <p>He's right.</p> |
|
129 | <p>He's right.</p> | |
130 | EXPECTED |
|
130 | EXPECTED | |
131 |
|
131 | |||
132 | assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '') |
|
132 | assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '') | |
133 | end |
|
133 | end | |
134 |
|
134 | |||
135 | def test_table |
|
135 | def test_table | |
136 | raw = <<-RAW |
|
136 | raw = <<-RAW | |
137 | This is a table with empty cells: |
|
137 | This is a table with empty cells: | |
138 |
|
138 | |||
139 | |cell11|cell12|| |
|
139 | |cell11|cell12|| | |
140 | |cell21||cell23| |
|
140 | |cell21||cell23| | |
141 | |cell31|cell32|cell33| |
|
141 | |cell31|cell32|cell33| | |
142 | RAW |
|
142 | RAW | |
143 |
|
143 | |||
144 | expected = <<-EXPECTED |
|
144 | expected = <<-EXPECTED | |
145 | <p>This is a table with empty cells:</p> |
|
145 | <p>This is a table with empty cells:</p> | |
146 |
|
146 | |||
147 | <table> |
|
147 | <table> | |
148 | <tr><td>cell11</td><td>cell12</td><td></td></tr> |
|
148 | <tr><td>cell11</td><td>cell12</td><td></td></tr> | |
149 | <tr><td>cell21</td><td></td><td>cell23</td></tr> |
|
149 | <tr><td>cell21</td><td></td><td>cell23</td></tr> | |
150 | <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr> |
|
150 | <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr> | |
151 | </table> |
|
151 | </table> | |
152 | EXPECTED |
|
152 | EXPECTED | |
153 |
|
153 | |||
154 | assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '') |
|
154 | assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '') | |
155 | end |
|
155 | end | |
156 |
|
156 | |||
157 | def test_table_with_line_breaks |
|
157 | def test_table_with_line_breaks | |
158 | raw = <<-RAW |
|
158 | raw = <<-RAW | |
159 | This is a table with line breaks: |
|
159 | This is a table with line breaks: | |
160 |
|
160 | |||
161 | |cell11 |
|
161 | |cell11 | |
162 | continued|cell12|| |
|
162 | continued|cell12|| | |
163 | |-cell21-||cell23 |
|
163 | |-cell21-||cell23 | |
164 | cell23 line2 |
|
164 | cell23 line2 | |
165 | cell23 *line3*| |
|
165 | cell23 *line3*| | |
166 | |cell31|cell32 |
|
166 | |cell31|cell32 | |
167 | cell32 line2|cell33| |
|
167 | cell32 line2|cell33| | |
168 |
|
168 | |||
169 | RAW |
|
169 | RAW | |
170 |
|
170 | |||
171 | expected = <<-EXPECTED |
|
171 | expected = <<-EXPECTED | |
172 | <p>This is a table with line breaks:</p> |
|
172 | <p>This is a table with line breaks:</p> | |
173 |
|
173 | |||
174 | <table> |
|
174 | <table> | |
175 | <tr> |
|
175 | <tr> | |
176 | <td>cell11<br />continued</td> |
|
176 | <td>cell11<br />continued</td> | |
177 | <td>cell12</td> |
|
177 | <td>cell12</td> | |
178 | <td></td> |
|
178 | <td></td> | |
179 | </tr> |
|
179 | </tr> | |
180 | <tr> |
|
180 | <tr> | |
181 | <td><del>cell21</del></td> |
|
181 | <td><del>cell21</del></td> | |
182 | <td></td> |
|
182 | <td></td> | |
183 | <td>cell23<br/>cell23 line2<br/>cell23 <strong>line3</strong></td> |
|
183 | <td>cell23<br/>cell23 line2<br/>cell23 <strong>line3</strong></td> | |
184 | </tr> |
|
184 | </tr> | |
185 | <tr> |
|
185 | <tr> | |
186 | <td>cell31</td> |
|
186 | <td>cell31</td> | |
187 | <td>cell32<br/>cell32 line2</td> |
|
187 | <td>cell32<br/>cell32 line2</td> | |
188 | <td>cell33</td> |
|
188 | <td>cell33</td> | |
189 | </tr> |
|
189 | </tr> | |
190 | </table> |
|
190 | </table> | |
191 | EXPECTED |
|
191 | EXPECTED | |
192 |
|
192 | |||
193 | assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '') |
|
193 | assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '') | |
194 | end |
|
194 | end | |
195 |
|
195 | |||
196 | def test_textile_should_not_mangle_brackets |
|
196 | def test_textile_should_not_mangle_brackets | |
197 | assert_equal '<p>[msg1][msg2]</p>', to_html('[msg1][msg2]') |
|
197 | assert_equal '<p>[msg1][msg2]</p>', to_html('[msg1][msg2]') | |
198 | end |
|
198 | end | |
199 |
|
199 | |||
200 | private |
|
200 | private | |
201 |
|
201 | |||
202 | def assert_html_output(to_test, expect_paragraph = true) |
|
202 | def assert_html_output(to_test, expect_paragraph = true) | |
203 | to_test.each do |text, expected| |
|
203 | to_test.each do |text, expected| | |
204 | assert_equal(( expect_paragraph ? "<p>#{expected}</p>" : expected ), @formatter.new(text).to_html, "Formatting the following text failed:\n===\n#{text}\n===\n") |
|
204 | assert_equal(( expect_paragraph ? "<p>#{expected}</p>" : expected ), @formatter.new(text).to_html, "Formatting the following text failed:\n===\n#{text}\n===\n") | |
205 | end |
|
205 | end | |
206 | end |
|
206 | end | |
207 |
|
207 | |||
208 | def to_html(text) |
|
208 | def to_html(text) | |
209 | @formatter.new(text).to_html |
|
209 | @formatter.new(text).to_html | |
210 | end |
|
210 | end | |
211 | end |
|
211 | end |
General Comments 0
You need to be logged in to leave comments.
Login now