2 require "rdoc/markup/inline"
4 class TestRDocMarkupAttributeManager < Test::Unit::TestCase
7 @am = RDoc::Markup::AttributeManager.new
9 @bold_on = @am.changed_attribute_by_name([], [:BOLD])
10 @bold_off = @am.changed_attribute_by_name([:BOLD], [])
12 @tt_on = @am.changed_attribute_by_name([], [:TT])
13 @tt_off = @am.changed_attribute_by_name([:TT], [])
15 @em_on = @am.changed_attribute_by_name([], [:EM])
16 @em_off = @am.changed_attribute_by_name([:EM], [])
18 @bold_em_on = @am.changed_attribute_by_name([], [:BOLD] | [:EM])
19 @bold_em_off = @am.changed_attribute_by_name([:BOLD] | [:EM], [])
21 @em_then_bold = @am.changed_attribute_by_name([:EM], [:EM] | [:BOLD])
23 @em_to_bold = @am.changed_attribute_by_name([:EM], [:BOLD])
25 @am.add_word_pair("{", "}", :WOMBAT)
26 @wombat_on = @am.changed_attribute_by_name([], [:WOMBAT])
27 @wombat_off = @am.changed_attribute_by_name([:WOMBAT], [])
31 crossref_bitmap = RDoc::Markup::Attribute.bitmap_for(:_SPECIAL_) |
32 RDoc::Markup::Attribute.bitmap_for(:CROSSREF)
34 [ @am.changed_attribute_by_name([], [:CROSSREF, :_SPECIAL_]),
35 RDoc::Markup::Special.new(crossref_bitmap, text),
36 @am.changed_attribute_by_name([:CROSSREF, :_SPECIAL_], [])
41 assert_equal(["cat ", @wombat_on, "and", @wombat_off, " dog" ],
42 @am.flow("cat {and} dog"))
43 #assert_equal(["cat {and} dog" ], @am.flow("cat \\{and} dog"))
46 def test_add_word_pair
47 @am.add_word_pair '%', '&', 'percent and'
49 assert RDoc::Markup::AttributeManager::WORD_PAIR_MAP.include?(/(%)(\S+)(&)/)
50 assert RDoc::Markup::AttributeManager::PROTECTABLE.include?('%')
51 assert !RDoc::Markup::AttributeManager::PROTECTABLE.include?('&')
54 def test_add_word_pair_angle
55 e = assert_raise ArgumentError do
56 @am.add_word_pair '<', '>', 'angles'
59 assert_equal "Word flags may not start with '<'", e.message
62 def test_add_word_pair_matching
63 @am.add_word_pair '^', '^', 'caret'
65 assert RDoc::Markup::AttributeManager::MATCHING_WORD_PAIRS.include?('^')
66 assert RDoc::Markup::AttributeManager::PROTECTABLE.include?('^')
70 assert_equal(["cat"], @am.flow("cat"))
72 assert_equal(["cat ", @bold_on, "and", @bold_off, " dog"],
73 @am.flow("cat *and* dog"))
75 assert_equal(["cat ", @bold_on, "AND", @bold_off, " dog"],
76 @am.flow("cat *AND* dog"))
78 assert_equal(["cat ", @em_on, "And", @em_off, " dog"],
79 @am.flow("cat _And_ dog"))
81 assert_equal(["cat *and dog*"], @am.flow("cat *and dog*"))
83 assert_equal(["*cat and* dog"], @am.flow("*cat and* dog"))
85 assert_equal(["cat *and ", @bold_on, "dog", @bold_off],
86 @am.flow("cat *and *dog*"))
88 assert_equal(["cat ", @em_on, "and", @em_off, " dog"],
89 @am.flow("cat _and_ dog"))
91 assert_equal(["cat_and_dog"],
92 @am.flow("cat_and_dog"))
94 assert_equal(["cat ", @tt_on, "and", @tt_off, " dog"],
95 @am.flow("cat +and+ dog"))
97 assert_equal(["cat ", @bold_on, "a_b_c", @bold_off, " dog"],
98 @am.flow("cat *a_b_c* dog"))
100 assert_equal(["cat __ dog"],
101 @am.flow("cat __ dog"))
103 assert_equal(["cat ", @em_on, "_", @em_off, " dog"],
104 @am.flow("cat ___ dog"))
108 assert_equal [@bold_on, 'bold', @bold_off],
111 assert_equal [@bold_on, 'Bold:', @bold_off],
114 assert_equal [@bold_on, '\\bold', @bold_off],
119 assert_equal(["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off],
120 @am.flow("cat _and_ *dog*"))
122 assert_equal(["cat ", @em_on, "a__nd", @em_off, " ", @bold_on, "dog", @bold_off],
123 @am.flow("cat _a__nd_ *dog*"))
126 def test_convert_attrs
128 attrs = RDoc::Markup::AttrSpan.new str.length
130 @am.convert_attrs str, attrs
132 assert_equal "\000foo\000", str
135 attrs = RDoc::Markup::AttrSpan.new str.length
137 @am.convert_attrs str, attrs
139 assert_equal "\000:foo:\000", str
142 attrs = RDoc::Markup::AttrSpan.new str.length
144 @am.convert_attrs str, attrs
146 assert_equal "\000x-y\000", str
149 def test_html_like_em_bold
150 assert_equal ["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
151 @am.flow("cat <i>and </i><b>dog</b>")
154 def test_html_like_em_bold_SGML
155 assert_equal ["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
156 @am.flow("cat <i>and <b></i>dog</b>")
159 def test_html_like_em_bold_nested_1
160 assert_equal(["cat ", @bold_em_on, "and", @bold_em_off, " dog"],
161 @am.flow("cat <i><b>and</b></i> dog"))
164 def test_html_like_em_bold_nested_2
165 assert_equal ["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off],
166 @am.flow("cat <i>and <b>dog</b></i>")
169 def test_html_like_em_bold_nested_mixed_case
170 assert_equal ["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off],
171 @am.flow("cat <i>and <B>dog</B></I>")
174 def test_html_like_em_bold_mixed_case
175 assert_equal ["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off],
176 @am.flow("cat <i>and</i> <B>dog</b>")
179 def test_html_like_teletype
180 assert_equal ["cat ", @tt_on, "dog", @tt_off],
181 @am.flow("cat <tt>dog</Tt>")
184 def test_html_like_teletype_em_bold_SGML
185 assert_equal [@tt_on, "cat", @tt_off, " ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
186 @am.flow("<tt>cat</tt> <i>and <b></i>dog</b>")
190 assert_equal(['cat \\ dog'], @am.flow('cat \\ dog'))
192 assert_equal(["cat <tt>dog</Tt>"], @am.flow("cat \\<tt>dog</Tt>"))
194 assert_equal(["cat ", @em_on, "and", @em_off, " <B>dog</b>"],
195 @am.flow("cat <i>and</i> \\<B>dog</b>"))
197 assert_equal(["*word* or <b>text</b>"], @am.flow("\\*word* or \\<b>text</b>"))
199 assert_equal(["_cat_", @em_on, "dog", @em_off],
200 @am.flow("\\_cat_<i>dog</i>"))
204 # class names, variable names, file names, or instance variables
208 | \b\w+([_\/\.]+\w+)+[!?=]?
212 assert_equal(["cat"], @am.flow("cat"))
214 assert_equal(["cat ", crossref("#fred"), " dog"].flatten,
215 @am.flow("cat #fred dog"))
217 assert_equal([crossref("#fred"), " dog"].flatten,
218 @am.flow("#fred dog"))
220 assert_equal(["cat ", crossref("#fred")].flatten, @am.flow("cat #fred"))