1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Import RDoc 3

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2010-12-20 03:22:49 +00:00
parent d7effd506f
commit 2ef9c50c6e
106 changed files with 8878 additions and 4179 deletions

View file

@ -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