1require File.expand_path '../xref_test_case', __FILE__ 2 3class TestRDocMarkupToHtmlCrossref < XrefTestCase 4 5 def setup 6 super 7 8 @options.hyperlink_all = true 9 10 @to = RDoc::Markup::ToHtmlCrossref.new @options, 'index.html', @c1 11 end 12 13 def test_convert_CROSSREF 14 result = @to.convert 'C1' 15 16 assert_equal para("<a href=\"C1.html\">C1</a>"), result 17 end 18 19 def test_convert_CROSSREF_label 20 result = @to.convert 'C1@foo' 21 assert_equal para("<a href=\"C1.html#label-foo\">foo at C1</a>"), result 22 23 result = @to.convert 'C1#m@foo' 24 assert_equal para("<a href=\"C1.html#method-i-m-label-foo\">foo at C1#m</a>"), 25 result 26 end 27 28 def test_convert_CROSSREF_label_period 29 result = @to.convert 'C1@foo.' 30 assert_equal para("<a href=\"C1.html#label-foo\">foo at C1</a>."), result 31 end 32 33 def test_convert_CROSSREF_label_space 34 result = @to.convert 'C1@foo+bar' 35 assert_equal para("<a href=\"C1.html#label-foo+bar\">foo bar at C1</a>"), 36 result 37 end 38 39 def test_convert_RDOCLINK_rdoc_ref 40 result = @to.convert 'rdoc-ref:C1' 41 42 assert_equal para("<a href=\"C1.html\">C1</a>"), result 43 end 44 45 def test_convert_RDOCLINK_rdoc_ref_method 46 result = @to.convert 'rdoc-ref:C1#m' 47 48 assert_equal para("<a href=\"C1.html#method-i-m\">#m</a>"), result 49 end 50 51 def test_convert_RDOCLINK_rdoc_ref_method_label 52 result = @to.convert 'rdoc-ref:C1#m@foo' 53 54 assert_equal para("<a href=\"C1.html#method-i-m-label-foo\">foo at C1#m</a>"), 55 result, 'rdoc-ref:C1#m@foo' 56 end 57 58 def test_convert_RDOCLINK_rdoc_ref_method_percent 59 m = @c1.add_method RDoc::AnyMethod.new nil, '%' 60 m.singleton = false 61 62 result = @to.convert 'rdoc-ref:C1#%' 63 64 assert_equal para("<a href=\"C1.html#method-i-25\">#%</a>"), result 65 66 m.singleton = true 67 68 result = @to.convert 'rdoc-ref:C1::%' 69 70 assert_equal para("<a href=\"C1.html#method-c-25\">::%</a>"), result 71 end 72 73 def test_convert_RDOCLINK_rdoc_ref_method_percent_label 74 m = @c1.add_method RDoc::AnyMethod.new nil, '%' 75 m.singleton = false 76 77 result = @to.convert 'rdoc-ref:C1#%@f' 78 79 assert_equal para("<a href=\"C1.html#method-i-25-label-f\">f at C1#%</a>"), 80 result 81 82 m.singleton = true 83 84 result = @to.convert 'rdoc-ref:C1::%@f' 85 86 assert_equal para("<a href=\"C1.html#method-c-25-label-f\">f at C1::%</a>"), 87 result 88 end 89 90 def test_convert_RDOCLINK_rdoc_ref_label 91 result = @to.convert 'rdoc-ref:C1@foo' 92 93 assert_equal para("<a href=\"C1.html#label-foo\">foo at C1</a>"), result, 94 'rdoc-ref:C1@foo' 95 end 96 97 def test_gen_url 98 assert_equal '<a href="C1.html">Some class</a>', 99 @to.gen_url('rdoc-ref:C1', 'Some class') 100 101 assert_equal '<a href="http://example">HTTP example</a>', 102 @to.gen_url('http://example', 'HTTP example') 103 end 104 105 def test_handle_special_CROSSREF 106 assert_equal "<a href=\"C2/C3.html\">C2::C3</a>", SPECIAL('C2::C3') 107 end 108 109 def test_handle_special_CROSSREF_label 110 assert_equal "<a href=\"C1.html#method-i-m-label-foo\">foo at C1#m</a>", 111 SPECIAL('C1#m@foo') 112 end 113 114 def test_handle_special_CROSSREF_show_hash_false 115 @to.show_hash = false 116 117 assert_equal "<a href=\"C1.html#method-i-m\">m</a>", 118 SPECIAL('#m') 119 end 120 121 def test_handle_special_HYPERLINK_rdoc 122 readme = @store.add_file 'README.txt' 123 readme.parser = RDoc::Parser::Simple 124 125 @to = RDoc::Markup::ToHtmlCrossref.new @options, 'C2.html', @c2 126 127 link = @to.handle_special_HYPERLINK hyper 'C2::C3' 128 129 assert_equal '<a href="C2/C3.html">C2::C3</a>', link 130 131 link = @to.handle_special_HYPERLINK hyper 'C4' 132 133 assert_equal '<a href="C4.html">C4</a>', link 134 135 link = @to.handle_special_HYPERLINK hyper 'README.txt' 136 137 assert_equal '<a href="README_txt.html">README.txt</a>', link 138 end 139 140 def test_handle_special_TIDYLINK_rdoc 141 readme = @store.add_file 'README.txt' 142 readme.parser = RDoc::Parser::Simple 143 144 @to = RDoc::Markup::ToHtmlCrossref.new @options, 'C2.html', @c2 145 146 link = @to.handle_special_TIDYLINK tidy 'C2::C3' 147 148 assert_equal '<a href="C2/C3.html">tidy</a>', link 149 150 link = @to.handle_special_TIDYLINK tidy 'C4' 151 152 assert_equal '<a href="C4.html">tidy</a>', link 153 154 link = @to.handle_special_TIDYLINK tidy 'C1#m' 155 156 assert_equal '<a href="C1.html#method-i-m">tidy</a>', link 157 158 link = @to.handle_special_TIDYLINK tidy 'README.txt' 159 160 assert_equal '<a href="README_txt.html">tidy</a>', link 161 end 162 163 def test_handle_special_TIDYLINK_label 164 link = @to.handle_special_TIDYLINK tidy 'C1#m@foo' 165 166 assert_equal "<a href=\"C1.html#method-i-m-label-foo\">tidy</a>", 167 link, 'C1#m@foo' 168 end 169 170 def test_to_html_CROSSREF_email 171 @options.hyperlink_all = false 172 173 @to = RDoc::Markup::ToHtmlCrossref.new @options, 'index.html', @c1 174 175 result = @to.to_html 'first.last@example.com' 176 177 assert_equal 'first.last@example.com', result 178 end 179 180 def test_to_html_CROSSREF_email_hyperlink_all 181 result = @to.to_html 'first.last@example.com' 182 183 assert_equal 'first.last@example.com', result 184 end 185 186 def test_link 187 assert_equal 'n', @to.link('n', 'n') 188 189 assert_equal '<a href="C1.html#method-c-m">::m</a>', @to.link('m', 'm') 190 end 191 192 def test_link_class_method_full 193 assert_equal '<a href="Parent.html#method-c-m">Parent.m</a>', 194 @to.link('Parent::m', 'Parent::m') 195 end 196 197 def para text 198 "\n<p>#{text}</p>\n" 199 end 200 201 def SPECIAL text 202 @to.handle_special_CROSSREF special text 203 end 204 205 def hyper reference 206 RDoc::Markup::Special.new 0, "rdoc-ref:#{reference}" 207 end 208 209 def special text 210 RDoc::Markup::Special.new 0, text 211 end 212 213 def tidy reference 214 RDoc::Markup::Special.new 0, "{tidy}[rdoc-ref:#{reference}]" 215 end 216 217end 218 219