Module: MaRuKu::Tests
- Included in:
- Maruku
- Defined in:
- lib/maruku/tests/new_parser.rb
Constant Summary collapse
- AccIta8 =
5 accented letters in italian, encoded as UTF-8
"\303\240\303\250\303\254\303\262\303\271"
- AccIta1 =
Same letters, written in ISO-8859-1 (one byte per letter)
"\340\350\354\362\371"
- Maruku8 =
The word MA-RU-KU, written in katakana using UTF-8
"\343\203\236\343\203\253\343\202\257"
- PAD =
40
Instance Method Summary collapse
- #describe_difference(input, expected, output) ⇒ Object
- #print_status(comment, status, verbose_text = nil) ⇒ Object
- #test_span_parser(verbose, break_on_first_error, quiet) ⇒ Object
Instance Method Details
#describe_difference(input, expected, output) ⇒ Object
357 358 359 360 361 |
# File 'lib/maruku/tests/new_parser.rb', line 357 def describe_difference(input, expected, output) "\nInput:\n #{input.inspect}" + "\nExpected:\n #{expected.inspect}" + "\nOutput:\n #{output.inspect}\n" end |
#print_status(comment, status, verbose_text = nil) ⇒ Object
346 347 348 349 350 351 352 353 354 |
# File 'lib/maruku/tests/new_parser.rb', line 346 def print_status(comment, status, verbose_text=nil) if comment.size < PAD comment = comment + (" "*(PAD-comment.size)) end puts "- #{comment} #{status}" if @verbose and verbose_text puts verbose_text end end |
#test_span_parser(verbose, break_on_first_error, quiet) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/maruku/tests/new_parser.rb', line 35 def test_span_parser(verbose, break_on_first_error, quiet) good_cases = [ ["", [], 'Empty string gives empty list'], ["a", ["a"], 'Easy char'], [" a", ["a"], 'First space in the paragraph is ignored'], ["a\n \n", ["a"], 'Last spaces in the paragraphs are ignored'], [' ', [], 'One char => nothing'], [' ', [], 'Two chars => nothing'], ['a b', ['a b'], 'Spaces are compressed'], ['a b', ['a b'], 'Newlines are spaces'], ["a\nb", ['a b'], 'Newlines are spaces'], ["a\n b", ['a b'], 'Compress newlines 1'], ["a \nb", ['a b'], 'Compress newlines 2'], [" \nb", ['b'], 'Compress newlines 3'], ["\nb", ['b'], 'Compress newlines 4'], ["b\n", ['b'], 'Compress newlines 5'], ["\n", [], 'Compress newlines 6'], ["\n\n\n", [], 'Compress newlines 7'], [nil, :throw, "Should throw on nil input"], # Code blocks ["`" , :throw, 'Unclosed single ticks'], ["``" , :throw, 'Unclosed double ticks'], ["`a`" , [md_code('a')], 'Simple inline code'], ["`` ` ``" , [md_code('`')], ], ["`` \\` ``" , [md_code('\\`')], ], ["``a``" , [md_code('a')], ], ["`` a ``" , [md_code('a')], ], # Newlines ["a \n", ['a',md_el(:linebreak)], 'Two spaces give br.'], ["a \n", ['a'], 'Newlines 2'], [" \n", [md_el(:linebreak)], 'Newlines 3'], [" \n \n", [md_el(:linebreak),md_el(:linebreak)],'Newlines 3'], [" \na \n", [md_el(:linebreak),'a',md_el(:linebreak)],'Newlines 3'], # Inline HTML ["a < b", ['a < b'], '< can be on itself'], ["<hr>", [md_html('<hr />')], 'HR will be sanitized'], ["<hr/>", [md_html('<hr />')], 'Closed tag is ok'], ["<hr />", [md_html('<hr />')], 'Closed tag is ok 2'], ["<hr/>a", [md_html('<hr />'),'a'], 'Closed tag is ok 2'], ["<em></em>a", [md_html('<em></em>'),'a'], 'Inline HTML 1'], ["<em>e</em>a", [md_html('<em>e</em>'),'a'], 'Inline HTML 2'], ["a<em>e</em>b", ['a',md_html('<em>e</em>'),'b'], 'Inline HTML 3'], ["<em>e</em>a<em>f</em>", [md_html('<em>e</em>'),'a',md_html('<em>f</em>')], 'Inline HTML 4'], ["<em>e</em><em>f</em>a", [md_html('<em>e</em>'),md_html('<em>f</em>'),'a'], 'Inline HTML 5'], ["<img src='a' />", [md_html("<img src='a' />")], 'Attributes'], ["<img src='a'/>"], # emphasis ["**", :throw, 'Unclosed double **'], ["\\*", ['*'], 'Escaping of *'], ["a *b* ", ['a ', md_em('b')], 'Emphasis 1'], ["a *b*", ['a ', md_em('b')], 'Emphasis 2'], ["a * b", ['a * b'], 'Emphasis 3'], ["a * b*", :throw, 'Unclosed emphasis'], # same with underscore ["__", :throw, 'Unclosed double __'], ["\\_", ['_'], 'Escaping of _'], ["a _b_ ", ['a ', md_em('b')], 'Emphasis 4'], ["a _b_", ['a ', md_em('b')], 'Emphasis 5'], ["a _ b", ['a _ b'], 'Emphasis 6'], ["a _ b_", :throw, 'Unclosed emphasis'], ["_b_", [md_em('b')], 'Emphasis 7'], ["_b_ _c_", [md_em('b'),' ',md_em('c')], 'Emphasis 8'], ["_b__c_", [md_em('b'),md_em('c')], 'Emphasis 9'], # underscores in word ["mod_ruby", ['mod_ruby'], 'Word with underscore'], # strong ["**a*", :throw, 'Unclosed double ** 2'], ["\\**a*", ['*', md_em('a')], 'Escaping of *'], ["a **b** ", ['a ', md_strong('b')], 'Emphasis 1'], ["a **b**", ['a ', md_strong('b')], 'Emphasis 2'], ["a ** b", ['a ** b'], 'Emphasis 3'], ["a ** b**", :throw, 'Unclosed emphasis'], ["**b****c**", [md_strong('b'),md_strong('c')], 'Emphasis 9'], # strong (with underscore) ["__a_", :throw, 'Unclosed double __ 2'], # ["\\__a_", ['_', md_em('a')], 'Escaping of _'], ["a __b__ ", ['a ', md_strong('b')], 'Emphasis 1'], ["a __b__", ['a ', md_strong('b')], 'Emphasis 2'], ["a __ b", ['a __ b'], 'Emphasis 3'], ["a __ b__", :throw, 'Unclosed emphasis'], ["__b____c__", [md_strong('b'),md_strong('c')], 'Emphasis 9'], # extra strong ["***a**", :throw, 'Unclosed triple *** '], ["\\***a**", ['*', md_strong('a')], 'Escaping of *'], ["a ***b*** ", ['a ', md_emstrong('b')], 'Strong elements'], ["a ***b***", ['a ', md_emstrong('b')]], ["a *** b", ['a *** b']], ["a ** * b", ['a ** * b']], ["***b******c***", [md_emstrong('b'),md_emstrong('c')]], ["a *** b***", :throw, 'Unclosed emphasis'], # same with underscores ["___a__", :throw, 'Unclosed triple *** '], # ["\\___a__", ['_', md_strong('a')], 'Escaping of _'], ["a ___b___ ", ['a ', md_emstrong('b')], 'Strong elements'], ["a ___b___", ['a ', md_emstrong('b')]], ["a ___ b", ['a ___ b']], ["a __ _ b", ['a __ _ b']], ["___b______c___", [md_emstrong('b'),md_emstrong('c')]], ["a ___ b___", :throw, 'Unclosed emphasis'], # mixing is bad ["*a_", :throw, 'Mixing is bad'], ["_a*", :throw], ["**a__", :throw], ["__a**", :throw], ["___a***", :throw], ["***a___", :throw], # links of the form [text][ref] ["\\[a]", ["[a]"], 'Escaping 1'], ["\\[a\\]", ["[a]"], 'Escaping 2'], # This is valid in the new Markdown version # ["[a]", ["a"], 'Not a link'], ["[a]", [ md_link(["a"],'a')], 'Empty link'], ["[a][]", ], ["[a][]b", [ md_link(["a"],'a'),'b'], 'Empty link'], ["[a\\]][]", [ md_link(["a]"],'a')], 'Escape inside link (throw ?] away)'], ["[a", :throw, 'Link not closed'], ["[a][", :throw, 'Ref not closed'], # links of the form [text](url) ["\\[a](b)", ["[a](b)"], 'Links'], ["[a](url)c", [md_im_link(['a'],'url'),'c'], 'url'], ["[a]( url )c" ], ["[a] ( url )c" ], ["[a] ( url)c" ], ["[a](ur:/l/ 'Title')", [md_im_link(['a'],'ur:/l/','Title')], 'url and title'], ["[a] ( ur:/l/ \"Title\")" ], ["[a] ( ur:/l/ \"Title\")" ], ["[a]( ur:/l/ Title)", :throw, "Must quote title" ], ["[a](url 'Tit\\\"l\\\\e')", [md_im_link(['a'],'url','Tit"l\\e')], 'url and title escaped'], ["[a] ( url \"Tit\\\"l\\\\e\")" ], ["[a] ( url \"Tit\\\"l\\\\e\" )" ], ['[a] ( url "Tit\\"l\\\\e" )' ], ["[a]()", [md_im_link(['a'],'')], 'No URL is OK'], ["[a](\"Title\")", :throw, "No url specified" ], ["[a](url \"Title)", :throw, "Unclosed quotes" ], ["[a](url \"Title\\\")", :throw], ["[a](url \"Title\" ", :throw], ["[a](url \'Title\")", :throw, "Mixing is bad" ], ["[a](url \"Title\')"], ["[a](/url)", [md_im_link(['a'],'/url')], 'Funny chars in url'], ["[a](#url)", [md_im_link(['a'],'#url')]], ["[a](</script?foo=1&bar=2>)", [md_im_link(['a'],'/script?foo=1&bar=2')]], # Images ["\\", ['!', md_im_link(['a'],'url') ], 'Escaping images'], ["", [md_im_image(['a'],'url')], 'Image no title'], ["" ], ["![a] ( url )" ], ["![a] ( url)" ], ["", [md_im_image(['a'],'url','ti"tle')], 'Image with title'], ['' ], ["" ], ["![a] ('url )" ], ["![a][imref]", [md_image(['a'],'imref')], 'Image with ref'], ["![a][ imref]"], ["![a][ imref ]"], ["![a][\timref\t]"], ['<http://example.com/?foo=1&bar=2>', [md_url('http://example.com/?foo=1&bar=2')], 'Immediate link'], ['a<http://example.com/?foo=1&bar=2>b', ['a',md_url('http://example.com/?foo=1&bar=2'),'b'] ], ['<[email protected]>', [md_email('[email protected]')], 'Email address'], ['<mailto:[email protected]>'], ["Developmen <http://rubyforge.org/projects/maruku/>", ["Developmen ", md_url("http://rubyforge.org/projects/maruku/")]], ["a<!-- -->b", ['a',md_html('<!-- -->'),'b'], 'HTML Comment'], ["a<!--", :throw, 'Bad HTML Comment'], ["a<!-- ", :throw, 'Bad HTML Comment'], ["<?xml <?!--!`3 ?>", [md_xml_instr('xml','<?!--!`3')], 'XML processing instruction'], ["<? <?!--!`3 ?>", [md_xml_instr('','<?!--!`3')] ], ["<? ", :throw, 'Bad Server directive'], ["a <b", :throw, 'Bad HTML 1'], ["<b", :throw, 'Bad HTML 2'], ["<b!", :throw, 'Bad HTML 3'], ['`<div>`, `<table>`, `<pre>`, `<p>`', [md_code('<div>'),', ',md_code('<table>'),', ', md_code('<pre>'),', ',md_code('<p>')], 'Multiple HTLM tags'], ["&andrea", ["&andrea"], 'Parsing of entities'], # no escaping is allowed # ["\\&andrea;", ["&andrea;"]], ["l&andrea;", ["l", md_entity('andrea')] ], ["&&andrea;", ["&", md_entity('andrea')] ], ["&123;;&",[md_entity('123'),';',md_entity('amp')]], ["a\nThe [syntax page] [s] provides", ['a The ', md_link(['syntax page'],'s'), ' provides'], 'Regression'], ['', [md_im_image(['a'],'url','ti"tle')], "Image with quotes"], ['' ], ['[bar](/url/ "Title with "quotes" inside")', [md_im_link(["bar"],'/url/', 'Title with "quotes" inside')], "Link with quotes"], # We dropped this idea # ['$20,000 and $30,000', ['$20,000 and $30,000'], 'Math: spaces'], ['$20,000$', [md_inline_math('20,000')]], # ['$ 20,000$', ['$ 20,000$']], # ['$20,000 $ $20,000$', ['$20,000 $ ', md_inline_math('20,000')]], ["#{Maruku8}", [Maruku8], "Reading UTF-8"], # ["#{AccIta1}", [AccIta8], "Converting ISO-8859-1 to UTF-8", # {:encoding => 'iso-8859-1'}], ] good_cases = unit_tests_for_attribute_lists + good_cases count = 1; last_comment=""; last_expected=:throw good_cases.each do |t| if not t[1] t[1] = last_expected else last_expected = t[1] end if not t[2] t[2] = last_comment + " #{count+=1}" else last_comment = t[2]; count=1 end end @verbose = verbose m = Maruku.new m.attributes[:on_error] = :raise Globals[:debug_keep_ials] = true num_ok = 0 good_cases.each do |input, expected, comment| output = nil begin output = m.parse_span_better(input) #lines = Maruku.split_lines input #output = m.parse_lines_as_span(lines) rescue Exception => e if not expected == :throw ex = e.inspect+ "\n"+ e.backtrace.join("\n") s = comment+describe_difference(input, expected, output) print_status(comment,'CRASHED :-(', ex+s) raise e if @break_on_first_error else quiet || print_status(comment,'OK') num_ok += 1 end end if not expected == :throw if not (expected == output) s = comment+describe_difference(input, expected, output) print_status(comment, 'FAILED', s) break if break_on_first_error else num_ok += 1 quiet || print_status(comment, 'OK') end else # I expected a raise if output s = comment+describe_difference(input, expected, output) print_status(comment, 'FAILED (no throw)', s) break if break_on_first_error end end end # do if num_ok != good_cases.size return false else return true end end |