@@ -1,16 +1,16 | |||||
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. | |
@@ -22,7 +22,7 class Redmine::WikiFormatting::TextileFormatterTest < HelperTestCase | |||||
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 | |
@@ -31,7 +31,7 class Redmine::WikiFormatting::TextileFormatterTest < HelperTestCase | |||||
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>', | |
@@ -46,7 +46,7 class Redmine::WikiFormatting::TextileFormatterTest < HelperTestCase | |||||
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| | |
@@ -57,7 +57,7 class Redmine::WikiFormatting::TextileFormatterTest < HelperTestCase | |||||
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>', | |
@@ -76,14 +76,14 class Redmine::WikiFormatting::TextileFormatterTest < HelperTestCase | |||||
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>', | |
@@ -91,7 +91,7 class Redmine::WikiFormatting::TextileFormatterTest < HelperTestCase | |||||
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 | |
@@ -108,7 +108,7 John said: | |||||
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> | |
@@ -128,10 +128,10 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. | |||||
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: | |
@@ -153,7 +153,7 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: | |
@@ -192,19 +192,19 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 |
General Comments 0
You need to be logged in to leave comments.
Login now