@@ -1,81 +1,81 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2010 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.dirname(__FILE__) + '/../../../../test_helper' |
|
19 | 19 | |
|
20 | 20 | class Redmine::WikiFormatting::TextileFormatterTest < HelperTestCase |
|
21 | 21 | |
|
22 | 22 | def setup |
|
23 | 23 | @formatter = Redmine::WikiFormatting::Textile::Formatter |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | MODIFIERS = { |
|
27 | 27 | "*" => 'strong', # bold |
|
28 | 28 | "_" => 'em', # italic |
|
29 | 29 | "+" => 'ins', # underline |
|
30 | 30 | "-" => 'del', # deleted |
|
31 | 31 | "^" => 'sup', # superscript |
|
32 | 32 | "~" => 'sub' # subscript |
|
33 | 33 | } |
|
34 | 34 | |
|
35 | 35 | def test_modifiers |
|
36 | 36 | assert_html_output( |
|
37 | 37 | '*bold*' => '<strong>bold</strong>', |
|
38 | 38 | 'before *bold*' => 'before <strong>bold</strong>', |
|
39 | 39 | '*bold* after' => '<strong>bold</strong> after', |
|
40 | 40 | '*two words*' => '<strong>two words</strong>', |
|
41 | 41 | '*two*words*' => '<strong>two*words</strong>', |
|
42 | 42 | '*two * words*' => '<strong>two * words</strong>', |
|
43 | 43 | '*two* *words*' => '<strong>two</strong> <strong>words</strong>', |
|
44 | 44 | '*(two)* *(words)*' => '<strong>(two)</strong> <strong>(words)</strong>', |
|
45 | 45 | # with class |
|
46 | 46 | '*(foo)two words*' => '<strong class="foo">two words</strong>' |
|
47 | 47 | ) |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | def test_modifiers_combination |
|
51 | 51 | MODIFIERS.each do |m1, tag1| |
|
52 | 52 | MODIFIERS.each do |m2, tag2| |
|
53 | 53 | next if m1 == m2 |
|
54 | 54 | text = "#{m2}#{m1}Phrase modifiers#{m1}#{m2}" |
|
55 | 55 | html = "<#{tag2}><#{tag1}>Phrase modifiers</#{tag1}></#{tag2}>" |
|
56 | 56 | assert_html_output text => html |
|
57 | 57 | end |
|
58 | 58 | end |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | def test_inline_code |
|
62 | 62 | assert_html_output( |
|
63 | 63 | 'this is @some code@' => 'this is <code>some code</code>', |
|
64 | 64 | '@<Location /redmine>@' => '<code><Location /redmine></code>' |
|
65 | 65 | ) |
|
66 | 66 | end |
|
67 | 67 | |
|
68 | 68 | def test_escaping |
|
69 | 69 | assert_html_output( |
|
70 | 70 | 'this is a <script>' => 'this is a <script>' |
|
71 | 71 | ) |
|
72 | 72 | end |
|
73 | 73 | |
|
74 | 74 | private |
|
75 | 75 | |
|
76 | 76 | def assert_html_output(to_test) |
|
77 | 77 | to_test.each do |text, expected| |
|
78 | assert_equal "<p>#{expected}</p>", @formatter.new(text).to_html | |
|
78 | assert_equal "<p>#{expected}</p>", @formatter.new(text).to_html, "Formatting the following text failed:\n===\n#{text}\n===\n" | |
|
79 | 79 | end |
|
80 | 80 | end |
|
81 | 81 | end |
General Comments 0
You need to be logged in to leave comments.
Login now