diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-20 03:22:49 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-20 03:22:49 +0000 |
commit | 2ef9c50c6e405717d06362787c4549ca4f1c6485 (patch) | |
tree | ee99486567461dd5796f3d6edcc9e204187f2666 /test/rdoc/test_rdoc_markup_parser.rb | |
parent | d7effd506f5b91a636f2e6452ef1946b923007c7 (diff) | |
download | ruby-2ef9c50c6e405717d06362787c4549ca4f1c6485.tar.gz |
Import RDoc 3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rdoc/test_rdoc_markup_parser.rb')
-rw-r--r-- | test/rdoc/test_rdoc_markup_parser.rb | 244 |
1 files changed, 147 insertions, 97 deletions
diff --git a/test/rdoc/test_rdoc_markup_parser.rb b/test/rdoc/test_rdoc_markup_parser.rb index d418900116..a7951d9d01 100644 --- a/test/rdoc/test_rdoc_markup_parser.rb +++ b/test/rdoc/test_rdoc_markup_parser.rb @@ -1,8 +1,9 @@ +# coding: utf-8 + require 'pp' require 'rubygems' require 'minitest/autorun' require 'rdoc/markup' -require 'rdoc/markup/to_test' class TestRDocMarkupParser < MiniTest::Unit::TestCase @@ -53,6 +54,19 @@ class TestRDocMarkupParser < MiniTest::Unit::TestCase assert_equal expected, @RMP.parse(str).parts end + def test_parse_bullet_utf_8 + str = <<-STR +* 新しい機能 + STR + + expected = [ + @RM::List.new(:BULLET, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('新しい機能'))])] + + assert_equal expected, @RMP.parse(str).parts + end + def test_parse_bullet_verbatim_heading str = <<-STR * l1 @@ -65,7 +79,7 @@ class TestRDocMarkupParser < MiniTest::Unit::TestCase @RM::List.new(:BULLET, *[ @RM::ListItem.new(nil, @RM::Paragraph.new('l1'), - @RM::Verbatim.new(' ', 'v', "\n"))]), + @RM::Verbatim.new("v\n"))]), @RM::Heading.new(1, 'H')] assert_equal expected, @RMP.parse(str).parts @@ -183,8 +197,7 @@ the time @RM::List.new(:BULLET, *[ @RM::ListItem.new(nil, @RM::Paragraph.new('l1.1', 'text'), - @RM::Verbatim.new(' ', 'code', "\n", - ' ', 'code', "\n"), + @RM::Verbatim.new("code\n", " code\n"), @RM::Paragraph.new('text'))])), @RM::ListItem.new(nil, @RM::Paragraph.new('l2'))])] @@ -400,6 +413,68 @@ A. l4 assert_equal expected, @RMP.parse(str).parts end + def test_parse_lalpha_utf_8 + str = <<-STR +a. 新しい機能 + STR + + expected = [ + @RM::List.new(:LALPHA, *[ + @RM::ListItem.new(nil, + @RM::Paragraph.new('新しい機能'))])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_list_list_1 + str = <<-STR +10. para 1 + + [label 1] + para 1.1 + + code + + para 1.2 + STR + + expected = [ + @RM::List.new(:NUMBER, *[ + @RM::ListItem.new(nil, *[ + @RM::Paragraph.new('para 1'), + @RM::BlankLine.new, + @RM::List.new(:LABEL, *[ + @RM::ListItem.new('label 1', *[ + @RM::Paragraph.new('para 1.1'), + @RM::BlankLine.new, + @RM::Verbatim.new("code\n"), + @RM::Paragraph.new('para 1.2')])])])])] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_list_list_2 + str = <<-STR +6. para + + label 1:: text 1 + label 2:: text 2 + STR + + expected = [ + @RM::List.new(:NUMBER, *[ + @RM::ListItem.new(nil, *[ + @RM::Paragraph.new('para'), + @RM::BlankLine.new, + @RM::List.new(:NOTE, *[ + @RM::ListItem.new('label 1', + @RM::Paragraph.new('text 1')), + @RM::ListItem.new('label 2', + @RM::Paragraph.new('text 2'))])])])] + + assert_equal expected, @RMP.parse(str).parts + end + def test_parse_list_verbatim str = <<-STR * one @@ -412,8 +487,7 @@ A. l4 @RM::List.new(:BULLET, *[ @RM::ListItem.new(nil, @RM::Paragraph.new('one'), - @RM::Verbatim.new(' ', 'verb1', "\n", - ' ', 'verb2', "\n")), + @RM::Verbatim.new("verb1\n", "verb2\n")), @RM::ListItem.new(nil, @RM::Paragraph.new('two'))])] @@ -545,7 +619,7 @@ for all good men expected = [ @RM::Paragraph.new('now is the time'), - @RM::Verbatim.new(' ', 'code _line_ here', "\n"), + @RM::Verbatim.new("code _line_ here\n"), @RM::Paragraph.new('for all good men'), ] assert_equal expected, @RMP.parse(str).parts @@ -567,6 +641,12 @@ B. l2 assert_equal expected, @RMP.parse(str).parts end + def test_parse_trailing_cr + expected = [ @RM::Paragraph.new('Text') ] + # FIXME hangs the parser: + assert_equal expected, @RMP.parse("Text\r").parts + end + def test_parse_verbatim str = <<-STR now is @@ -576,7 +656,7 @@ the time expected = [ @RM::Paragraph.new('now is'), - @RM::Verbatim.new(' ', 'code', "\n"), + @RM::Verbatim.new("code\n"), @RM::Paragraph.new('the time'), ] @@ -589,7 +669,18 @@ the time STR expected = [ - @RM::Verbatim.new(' ', '*', ' ', 'blah', "\n")] + @RM::Verbatim.new("* blah\n")] + + assert_equal expected, @RMP.parse(str).parts + end + + def test_parse_verbatim_dash + str = <<-STR + - blah + STR + + expected = [ + @RM::Verbatim.new("- blah\n")] assert_equal expected, @RMP.parse(str).parts end @@ -607,9 +698,7 @@ the time expected = [ @RM::Paragraph.new('now is'), - @RM::Verbatim.new(' ', 'code', "\n", - "\n", - ' ', 'code1', "\n"), + @RM::Verbatim.new("code\n", "\n", "code1\n"), @RM::Paragraph.new('the time'), ] @@ -624,7 +713,7 @@ text expected = [ @RM::Paragraph.new('text'), - @RM::Verbatim.new(' ', '===', ' ', 'heading three', "\n")] + @RM::Verbatim.new("=== heading three\n")] assert_equal expected, @RMP.parse(str).parts end @@ -634,7 +723,7 @@ text expected = [ @RM::Paragraph.new('text'), - @RM::Verbatim.new(' ', 'code', "\n"), + @RM::Verbatim.new("code\n"), @RM::Heading.new(3, 'heading three')] assert_equal expected, @RMP.parse(str).parts @@ -646,7 +735,7 @@ text STR expected = [ - @RM::Verbatim.new(' ', '[blah]', ' ', 'blah', "\n")] + @RM::Verbatim.new("[blah] blah\n")] assert_equal expected, @RMP.parse(str).parts end @@ -657,7 +746,7 @@ text STR expected = [ - @RM::Verbatim.new(' ', 'b.', ' ', 'blah', "\n")] + @RM::Verbatim.new("b. blah\n")] assert_equal expected, @RMP.parse(str).parts end @@ -671,8 +760,7 @@ text expected = [ @RM::Paragraph.new('text'), - @RM::Verbatim.new(' ', 'code', "\n", - ' ', '===', ' ', 'heading three', "\n")] + @RM::Verbatim.new("code\n", "=== heading three\n")] assert_equal expected, @RMP.parse(str).parts end @@ -688,9 +776,7 @@ the time expected = [ @RM::Paragraph.new('now is'), - @RM::Verbatim.new(' ', 'code', "\n", - "\n", - ' ', 'code1', "\n"), + @RM::Verbatim.new("code\n", "\n", "code1\n"), @RM::Paragraph.new('the time'), ] @@ -710,11 +796,7 @@ the time expected = [ @RM::Paragraph.new('now is'), - @RM::Verbatim.new(' ', 'code', "\n", - "\n", - ' ', 'code1', "\n", - "\n", - ' ', 'code2', "\n"), + @RM::Verbatim.new("code\n", "\n", "code1\n", "\n", "code2\n"), @RM::Paragraph.new('the time'), ] @@ -731,8 +813,7 @@ the time expected = [ @RM::Paragraph.new('now is'), - @RM::Verbatim.new(' ', 'code', "\n", - ' ', 'code1', "\n"), + @RM::Verbatim.new("code\n", "code1\n"), @RM::Paragraph.new('the time'), ] @@ -749,8 +830,8 @@ for all good men expected = [ @RM::Paragraph.new('now is the time'), - @RM::Verbatim.new(' ', 'code', "\n", - ' ', 'more code', "\n"), + @RM::Verbatim.new(" code\n", + "more code\n"), @RM::Paragraph.new('for all good men'), ] @@ -763,7 +844,7 @@ for all good men STR expected = [ - @RM::Verbatim.new(' ', 'blah::', ' ', 'blah', "\n")] + @RM::Verbatim.new("blah:: blah\n")] assert_equal expected, @RMP.parse(str).parts end @@ -774,7 +855,7 @@ for all good men STR expected = [ - @RM::Verbatim.new(' ', '2.', ' ', 'blah', "\n")] + @RM::Verbatim.new("2. blah\n")] assert_equal expected, @RMP.parse(str).parts end @@ -790,8 +871,8 @@ text expected = [ @RM::Paragraph.new('text'), @RM::BlankLine.new, - @RM::Verbatim.new(' ', '---', ' ', 'lib/blah.rb.orig', "\n", - ' ', '+++', ' ', 'lib/blah.rb', "\n")] + @RM::Verbatim.new("--- lib/blah.rb.orig\n", + "+++ lib/blah.rb\n")] assert_equal expected, @RMP.parse(str).parts end @@ -806,7 +887,7 @@ text expected = [ @RM::Paragraph.new('text'), @RM::BlankLine.new, - @RM::Verbatim.new(' ', '---', '')] + @RM::Verbatim.new("---")] assert_equal expected, @RMP.parse(str).parts end @@ -823,9 +904,9 @@ the time expected = [ @RM::Paragraph.new('now is'), - @RM::Verbatim.new(' ', 'code', "\n", + @RM::Verbatim.new("code\n", "\n", - ' ', 'code1', "\n"), + "code1\n"), @RM::Paragraph.new('the time'), ] @@ -838,7 +919,7 @@ the time STR expected = [ - @RM::Verbatim.new(' ', 'B.', ' ', 'blah', "\n")] + @RM::Verbatim.new("B. blah\n")] assert_equal expected, @RMP.parse(str).parts end @@ -851,58 +932,57 @@ the time assert_equal expected, @RMP.parse('hello').parts expected = [ - @RM::Verbatim.new(' ', 'hello '), + @RM::Verbatim.new('hello '), ] - assert_equal expected, @RMP.parse(' hello ').parts + assert_equal expected, @RMP.parse(' hello ').parts expected = [ - @RM::Verbatim.new(' ', 'hello '), + @RM::Verbatim.new('hello '), ] - assert_equal expected, @RMP.parse(" hello ").parts + assert_equal expected, @RMP.parse(' hello ').parts expected = [ @RM::Paragraph.new('1'), - @RM::Verbatim.new(' ', '2', "\n", - ' ', '3'), + @RM::Verbatim.new("2\n", ' 3'), ] assert_equal expected, @RMP.parse("1\n 2\n 3").parts expected = [ - @RM::Verbatim.new(' ', '1', "\n", - ' ', '2', "\n", - ' ', '3'), + @RM::Verbatim.new("1\n", + " 2\n", + " 3"), ] assert_equal expected, @RMP.parse(" 1\n 2\n 3").parts expected = [ @RM::Paragraph.new('1'), - @RM::Verbatim.new(' ', '2', "\n", - ' ', '3', "\n"), + @RM::Verbatim.new("2\n", + " 3\n"), @RM::Paragraph.new('1'), - @RM::Verbatim.new(' ', '2'), + @RM::Verbatim.new('2'), ] assert_equal expected, @RMP.parse("1\n 2\n 3\n1\n 2").parts expected = [ - @RM::Verbatim.new(' ', '1', "\n", - ' ', '2', "\n", - ' ', '3', "\n", - ' ', '1', "\n", - ' ', '2'), + @RM::Verbatim.new("1\n", + " 2\n", + " 3\n", + "1\n", + ' 2'), ] assert_equal expected, @RMP.parse(" 1\n 2\n 3\n 1\n 2").parts expected = [ - @RM::Verbatim.new(' ', '1', "\n", - ' ', '2', "\n", + @RM::Verbatim.new("1\n", + " 2\n", "\n", - ' ', '3'), + ' 3'), ] assert_equal expected, @RMP.parse(" 1\n 2\n\n 3").parts @@ -942,8 +1022,7 @@ the time STR expected = [ - [:BULLET, :BULLET, 0, 0], - [:SPACE, 2, 0, 0], + [:BULLET, '*', 0, 0], [:TEXT, 'l1', 2, 0], [:NEWLINE, "\n", 4, 0], ] @@ -958,13 +1037,10 @@ the time STR expected = [ - [:BULLET, :BULLET, 0, 0], - [:SPACE, 2, 0, 0], + [:BULLET, '*', 0, 0], [:TEXT, 'l1', 2, 0], [:NEWLINE, "\n", 4, 0], - [:INDENT, 2, 0, 1], - [:BULLET, :BULLET, 2, 1], - [:SPACE, 2, 2, 1], + [:BULLET, '*', 2, 1], [:TEXT, 'l1.1', 4, 1], [:NEWLINE, "\n", 8, 1], ] @@ -1030,11 +1106,9 @@ the time expected = [ [:LABEL, 'cat', 0, 0], - [:SPACE, 6, 0, 0], [:TEXT, 'l1', 6, 0], [:NEWLINE, "\n", 8, 0], [:LABEL, 'dog', 0, 1], - [:SPACE, 6, 0, 1], [:TEXT, 'l1.1', 6, 1], [:NEWLINE, "\n", 10, 1], ] @@ -1050,11 +1124,8 @@ the time expected = [ [:LABEL, 'label', 0, 0], - [:SPACE, 7, 0, 0], [:NEWLINE, "\n", 7, 0], - [:INDENT, 2, 0, 1], [:NOTE, 'note', 2, 1], - [:SPACE, 6, 2, 1], [:NEWLINE, "\n", 8, 1], ] @@ -1069,11 +1140,9 @@ b. l1.1 expected = [ [:LALPHA, 'a', 0, 0], - [:SPACE, 3, 0, 0], [:TEXT, 'l1', 3, 0], [:NEWLINE, "\n", 5, 0], [:LALPHA, 'b', 0, 1], - [:SPACE, 3, 0, 1], [:TEXT, 'l1.1', 3, 1], [:NEWLINE, "\n", 7, 1], ] @@ -1089,11 +1158,9 @@ dog:: l1.1 expected = [ [:NOTE, 'cat', 0, 0], - [:SPACE, 6, 0, 0], [:TEXT, 'l1', 6, 0], [:NEWLINE, "\n", 8, 0], [:NOTE, 'dog', 0, 1], - [:SPACE, 6, 0, 1], [:TEXT, 'l1.1', 6, 1], [:NEWLINE, "\n", 10, 1], ] @@ -1109,10 +1176,8 @@ dog:: expected = [ [:NOTE, 'cat', 0, 0], - [:SPACE, 5, 0, 0], [:NEWLINE, "\n", 5, 0], [:NOTE, 'dog', 0, 1], - [:SPACE, 5, 0, 1], [:NEWLINE, "\n", 5, 1], ] @@ -1140,11 +1205,9 @@ Cat::Dog expected = [ [:NUMBER, '1', 0, 0], - [:SPACE, 3, 0, 0], [:TEXT, 'l1', 3, 0], [:NEWLINE, "\n", 5, 0], [:NUMBER, '2', 0, 1], - [:SPACE, 3, 0, 1], [:TEXT, 'l1.1', 3, 1], [:NEWLINE, "\n", 7, 1], ] @@ -1162,20 +1225,16 @@ Cat::Dog expected = [ [:NUMBER, "1", 0, 0], - [:SPACE, 3, 0, 0], [:TEXT, "blah blah blah", 3, 0], [:NEWLINE, "\n", 17, 0], - [:INDENT, 3, 0, 1], [:TEXT, "l.", 3, 1], [:NEWLINE, "\n", 5, 1], [:NUMBER, "2", 0, 2], - [:SPACE, 3, 0, 2], [:TEXT, "blah blah blah blah", 3, 2], [:NEWLINE, "\n", 22, 2], - [:INDENT, 3, 0, 3], [:TEXT, "d.", 3, 3], [:NEWLINE, "\n", 5, 3] ] @@ -1193,24 +1252,18 @@ Cat::Dog expected = [ [:NUMBER, "1", 0, 0], - [:SPACE, 3, 0, 0], [:TEXT, "blah blah blah", 3, 0], [:NEWLINE, "\n", 17, 0], - [:INDENT, 3, 0, 1], [:LALPHA, "l", 3, 1], - [:SPACE, 4, 3, 1], [:TEXT, "more stuff", 7, 1], [:NEWLINE, "\n", 17, 1], [:NUMBER, "2", 0, 2], - [:SPACE, 3, 0, 2], [:TEXT, "blah blah blah blah", 3, 2], [:NEWLINE, "\n", 22, 2], - [:INDENT, 3, 0, 3], [:LALPHA, "d", 3, 3], - [:SPACE, 3, 3, 3], [:TEXT, "other stuff", 6, 3], [:NEWLINE, "\n", 17, 3] ] @@ -1241,14 +1294,14 @@ for all def test_tokenize_rule str = <<-STR ---- +--- --- blah --- STR expected = [ [:RULE, 1, 0, 0], - [:NEWLINE, "\n", 4, 0], + [:NEWLINE, "\n", 3, 0], [:NEWLINE, "\n", 0, 1], [:TEXT, "--- blah ---", 0, 2], [:NEWLINE, "\n", 12, 2], @@ -1265,11 +1318,9 @@ B. l1.1 expected = [ [:UALPHA, 'A', 0, 0], - [:SPACE, 3, 0, 0], [:TEXT, 'l1', 3, 0], [:NEWLINE, "\n", 5, 0], [:UALPHA, 'B', 0, 1], - [:SPACE, 3, 0, 1], [:TEXT, 'l1.1', 3, 1], [:NEWLINE, "\n", 7, 1], ] @@ -1288,7 +1339,6 @@ Example heading: [:TEXT, 'Example heading:', 0, 0], [:NEWLINE, "\n", 16, 0], [:NEWLINE, "\n", 0, 1], - [:INDENT, 3, 0, 2], [:HEADER, 3, 3, 2], [:TEXT, 'heading three', 7, 2], [:NEWLINE, "\n", 20, 2], @@ -1299,17 +1349,17 @@ Example heading: # HACK move to Verbatim test case def test_verbatim_normalize - v = @RM::Verbatim.new ' ', 'foo', "\n", "\n", "\n", ' ', 'bar', "\n" + v = @RM::Verbatim.new "foo\n", "\n", "\n", "bar\n" v.normalize - assert_equal [' ', 'foo', "\n", "\n", ' ', 'bar', "\n"], v.parts + assert_equal ["foo\n", "\n", "bar\n"], v.parts - v = @RM::Verbatim.new ' ', 'foo', "\n", "\n" + v = @RM::Verbatim.new "foo\n", "\n" v.normalize - assert_equal [' ', 'foo', "\n"], v.parts + assert_equal ["foo\n"], v.parts end def test_unget |