rdtool 0.6.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/COPYING.txt +674 -0
  2. data/Gemfile +9 -0
  3. data/HISTORY +284 -0
  4. data/LICENSE.txt +58 -0
  5. data/MANIFEST +89 -0
  6. data/README.html +44 -0
  7. data/README.ja.html +46 -0
  8. data/README.rd +52 -0
  9. data/README.rd.ja +54 -0
  10. data/Rakefile +29 -0
  11. data/TODO +15 -0
  12. data/VERSION +1 -0
  13. data/bin/rd2 +281 -0
  14. data/bin/rdswap.rb +207 -0
  15. data/doc/rd-draft.rd +479 -0
  16. data/doc/rd-draft.rd.ja +487 -0
  17. data/lib/rd/block-element.rb +114 -0
  18. data/lib/rd/complex-list-item.rb +65 -0
  19. data/lib/rd/desclist.rb +55 -0
  20. data/lib/rd/document-struct.rb +46 -0
  21. data/lib/rd/dot.rd2rc +18 -0
  22. data/lib/rd/element.rb +160 -0
  23. data/lib/rd/filter.rb +255 -0
  24. data/lib/rd/inline-element.rb +233 -0
  25. data/lib/rd/labeled-element.rb +14 -0
  26. data/lib/rd/list.rb +57 -0
  27. data/lib/rd/loose-struct.rb +11 -0
  28. data/lib/rd/methodlist.rb +57 -0
  29. data/lib/rd/output-format-visitor.rb +28 -0
  30. data/lib/rd/package.rb +4 -0
  31. data/lib/rd/parser-util.rb +14 -0
  32. data/lib/rd/post-install +1 -0
  33. data/lib/rd/rbl-file.rb +69 -0
  34. data/lib/rd/rbl-suite.rb +37 -0
  35. data/lib/rd/rd-struct.rb +86 -0
  36. data/lib/rd/rd2html-lib.rb +490 -0
  37. data/lib/rd/rd2html-opt.rb +67 -0
  38. data/lib/rd/rd2man-lib.rb +241 -0
  39. data/lib/rd/rd2rdo-lib.rb +19 -0
  40. data/lib/rd/rd2rmi-lib.rb +32 -0
  41. data/lib/rd/rdblockparser.ry +518 -0
  42. data/lib/rd/rdblockparser.tab.rb +1050 -0
  43. data/lib/rd/rdfmt.rb +15 -0
  44. data/lib/rd/rdinlineparser.ry +503 -0
  45. data/lib/rd/rdinlineparser.tab.rb +1243 -0
  46. data/lib/rd/rdvisitor.rb +214 -0
  47. data/lib/rd/reference-resolver.rb +114 -0
  48. data/lib/rd/search-file.rb +14 -0
  49. data/lib/rd/tree.rb +103 -0
  50. data/lib/rd/version.rb +39 -0
  51. data/lib/rd/visitor.rb +86 -0
  52. data/makerdtool.rb +75 -0
  53. data/setup.rb +1596 -0
  54. data/test.rb +33 -0
  55. data/test/data/includee1.html +1 -0
  56. data/test/data/includee2.html +1 -0
  57. data/test/data/includee3.nothtml +1 -0
  58. data/test/data/includee4.xhtml +0 -0
  59. data/test/data/label.rbl +2 -0
  60. data/test/data/label2.rbl +2 -0
  61. data/test/data/sub/includee2.html +1 -0
  62. data/test/data/sub/includee4.html +0 -0
  63. data/test/dummy-observer.rb +6 -0
  64. data/test/dummy.rb +33 -0
  65. data/test/temp-dir.rb +19 -0
  66. data/test/test-block-parser.rb +46 -0
  67. data/test/test-desclist-item.rb +219 -0
  68. data/test/test-document-element.rb +46 -0
  69. data/test/test-document-struct.rb +66 -0
  70. data/test/test-element.rb +46 -0
  71. data/test/test-headline.rb +80 -0
  72. data/test/test-inline-parser.rb +46 -0
  73. data/test/test-list-item.rb +54 -0
  74. data/test/test-list.rb +53 -0
  75. data/test/test-methodlist-item.rb +73 -0
  76. data/test/test-nonterminal-element.rb +170 -0
  77. data/test/test-nonterminal-inline.rb +33 -0
  78. data/test/test-output-format-visitor.rb +48 -0
  79. data/test/test-parser-util.rb +41 -0
  80. data/test/test-rbl-file.rb +156 -0
  81. data/test/test-rbl-suite.rb +43 -0
  82. data/test/test-rd2html-lib.rb +496 -0
  83. data/test/test-rdtree.rb +17 -0
  84. data/test/test-rdvisitor.rb +29 -0
  85. data/test/test-reference-resolver.rb +202 -0
  86. data/test/test-reference.rb +132 -0
  87. data/test/test-search-file.rb +22 -0
  88. data/test/test-terminal-inline.rb +41 -0
  89. data/test/test-textblock.rb +44 -0
  90. data/test/test-tree.rb +82 -0
  91. data/test/test-version.rb +57 -0
  92. data/test/test-visitor.rb +230 -0
  93. data/utils/rd-mode.el +425 -0
  94. metadata +203 -0
data/test.rb ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $VERBOSE = true
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "test"))
6
+
7
+ load 'test/test-block-parser.rb'
8
+ load 'test/test-desclist-item.rb'
9
+ load 'test/test-document-element.rb'
10
+ load 'test/test-document-struct.rb'
11
+ load 'test/test-element.rb'
12
+ load 'test/test-headline.rb'
13
+ load 'test/test-inline-parser.rb'
14
+ load 'test/test-list-item.rb'
15
+ load 'test/test-list.rb'
16
+ load 'test/test-methodlist-item.rb'
17
+ load 'test/test-nonterminal-element.rb'
18
+ load 'test/test-nonterminal-inline.rb'
19
+ load 'test/test-output-format-visitor.rb'
20
+ load 'test/test-parser-util.rb'
21
+ load 'test/test-rbl-file.rb'
22
+ load 'test/test-rbl-suite.rb'
23
+ load 'test/test-rd2html-lib.rb'
24
+ load 'test/test-rdtree.rb'
25
+ load 'test/test-rdvisitor.rb'
26
+ load 'test/test-reference-resolver.rb'
27
+ load 'test/test-reference.rb'
28
+ load 'test/test-search-file.rb'
29
+ load 'test/test-terminal-inline.rb'
30
+ load 'test/test-textblock.rb'
31
+ load 'test/test-tree.rb'
32
+ load 'test/test-version.rb'
33
+ load 'test/test-visitor.rb'
@@ -0,0 +1 @@
1
+ includee1.html
@@ -0,0 +1 @@
1
+ includee2.html
@@ -0,0 +1 @@
1
+ includee3.nothtml
File without changes
@@ -0,0 +1,2 @@
1
+ label1 => label:0
2
+ label2 => label:1
@@ -0,0 +1,2 @@
1
+ label1 => Label-0
2
+ label2 => Label-1
@@ -0,0 +1 @@
1
+ sub/includee2.html
File without changes
@@ -0,0 +1,6 @@
1
+ class DummyObserver
2
+ attr_reader :args
3
+ def update(*args)
4
+ @args = args
5
+ end
6
+ end
data/test/dummy.rb ADDED
@@ -0,0 +1,33 @@
1
+ require "rd/element"
2
+ require "rd/document-struct"
3
+ require "rd/visitor"
4
+
5
+ module RD
6
+ class DummyElement < Element
7
+ attr_accessor :parent
8
+
9
+ def children
10
+ []
11
+ end
12
+
13
+ def each_element
14
+ yield(self)
15
+ end
16
+
17
+ def accept(visitor)
18
+ "dummy"
19
+ end
20
+
21
+ def to_label
22
+ " label "
23
+ end
24
+ end
25
+
26
+ DummyStruct = DocumentStructure.new
27
+ end
28
+
29
+ class DummyVisitor < RD::Visitor
30
+ def method_missing(method, *args)
31
+ [method.to_s, args]
32
+ end
33
+ end
data/test/temp-dir.rb ADDED
@@ -0,0 +1,19 @@
1
+
2
+ def in_temp_dir
3
+ tmpdir = "test-tmp.#$$"
4
+ pwd = Dir.pwd
5
+ Dir.mkdir(tmpdir)
6
+ Dir.chdir(tmpdir)
7
+ begin
8
+ yield
9
+ ensure
10
+ Dir.chdir(pwd)
11
+ Dir.rmdir(tmpdir)
12
+ end
13
+ end
14
+
15
+ def remove_file(file)
16
+ if File.exist? file
17
+ File.unlink(file)
18
+ end
19
+ end
@@ -0,0 +1,46 @@
1
+ require 'test/unit'
2
+
3
+ require 'rd/rdblockparser.tab'
4
+ require 'rd/rd-struct'
5
+
6
+ include RD
7
+
8
+ class TestBlockParser < Test::Unit::TestCase
9
+ def setup
10
+ @p = RDParser.new
11
+ @p.class.module_eval {
12
+ public :cut_off,:set_term_to_element
13
+ }
14
+ @p.instance_eval do
15
+ @tree = Tree.new_with_document_struct(DocumentStructure::RD)
16
+ end
17
+ end
18
+
19
+ def test_cut_off
20
+ assert_equal(["aaaa"], @p.cut_off(["aaaa"]))
21
+ assert_equal(["aaaa\n"], @p.cut_off(["aaaa\n"]))
22
+ assert_equal(["aaaa\n"], @p.cut_off([" aaaa\n"]))
23
+ assert_equal(["aaaa\n", "bbbb\n"], @p.cut_off([" aaaa\n", " bbbb\n"]))
24
+ assert_equal(["aaaa\n", " bbbb\n"], @p.cut_off(["aaaa\n", " bbbb\n"]))
25
+ assert_equal(["aaaa\n", " bbbb\n"], @p.cut_off([" aaaa\n", " bbbb\n"]))
26
+ assert_equal(["aaaa\n", " bbbb\n", " cccc\n"],
27
+ @p.cut_off([" aaaa\n", " bbbb\n", " cccc\n"]))
28
+ assert_equal(["aaaa\n", " bbbb\n", " cccc\n"],
29
+ @p.cut_off([" aaaa\n", " bbbb\n", " cccc\n"]))
30
+ assert_raises(RuntimeError) do
31
+ @p.cut_off([" aaaa\n", "bbbb\n"])
32
+ end
33
+ end
34
+
35
+ def test_set_term_to_element
36
+ desclist = DescListItem.new
37
+ term = DescListItem::Term.new
38
+ @p.set_term_to_element(desclist, term)
39
+ assert_equal(term, desclist.term)
40
+
41
+ methodlist = MethodListItem.new
42
+ term = MethodListItem::Term.new "string"
43
+ @p.set_term_to_element(methodlist, term)
44
+ assert_equal(term, methodlist.term)
45
+ end
46
+ end
@@ -0,0 +1,219 @@
1
+ require 'test/unit'
2
+
3
+ require 'rd/desclist'
4
+ require 'rd/rd-struct'
5
+
6
+ include RD
7
+
8
+ class TestDescListItem < Test::Unit::TestCase
9
+ def setup
10
+ @flat = DescListItem.new
11
+ @t1 = DescListItem::Term.new
12
+ @flat.set_term_under_document_struct(@t1, DocumentStructure::RD)
13
+ @c1 = TextBlock.new
14
+ @c2 = ItemList.new
15
+ @flat.add_children_under_document_struct([@c1, @c2],
16
+ DocumentStructure::RD)
17
+
18
+ @nest = DescListItem.new
19
+ @t2 = DescListItem::Term.new
20
+ @t21 = StringElement.new ""
21
+ @t2.add_child_under_document_struct(@t21, DocumentStructure::RD)
22
+ @nest.set_term_under_document_struct(@t2, DocumentStructure::RD)
23
+ @d1 = TextBlock.new
24
+ @d11 = StringElement.new ""
25
+ @d1.add_child_under_document_struct(@d11, DocumentStructure::RD)
26
+ @nest.add_children_under_document_struct([@d1],
27
+ DocumentStructure::RD)
28
+ end
29
+
30
+ def test_set_term_under_docment_struct
31
+ t = DescListItem::Term.new
32
+ i = DescListItem.new
33
+ i.set_term_under_document_struct(t, DocumentStructure::RD)
34
+ assert_equal(t, i.term)
35
+ assert_equal(i, t.parent)
36
+
37
+ assert_raises(ArgumentError) do
38
+ t = StringElement.new ""
39
+ DescListItem.new.set_term_under_document_struct(t, DocumentStructure::RD)
40
+ end
41
+ end
42
+
43
+ def test_assign_term
44
+ desclist = DescListItem.new
45
+ term = DescListItem::Term.new
46
+ desclist.assign_term(term)
47
+ assert_equal(term, desclist.term)
48
+ assert_equal(desclist, term.parent)
49
+ end
50
+
51
+ def test_set_term_without_document_strcut
52
+ desclist = DescListItem.new
53
+ term = DescListItem::Term.new
54
+ desclist.set_term_without_document_struct(term)
55
+ assert_equal(term, desclist.term)
56
+ assert_equal(desclist, term.parent)
57
+
58
+ not_term = StringElement.new "not term"
59
+ desclist.set_term_without_document_struct(not_term)
60
+ assert_equal(not_term, desclist.term)
61
+ assert_equal(desclist, not_term.parent)
62
+ end
63
+
64
+ def test_each_block_in_description
65
+ exp = [@c1, @c2]
66
+ i = 0
67
+ @flat.each_block_in_description do |b|
68
+ assert_equal(exp[i], b)
69
+ i += 1
70
+ end
71
+
72
+ exp = [@d1]
73
+ i = 0
74
+ @nest.each_block_in_description do |b|
75
+ assert_equal(exp[i], b)
76
+ i += 1
77
+ end
78
+ end
79
+
80
+ def test_each_element
81
+ exp = [@flat, @t1, @c1, @c2]
82
+ i = 0
83
+ @flat.each_element do |b|
84
+ assert_equal(exp[i], b)
85
+ i += 1
86
+ end
87
+
88
+ exp = [@nest, @t2, @t21, @d1, @d11]
89
+ i = 0
90
+ @nest.each_element do |b|
91
+ assert_equal(exp[i], b)
92
+ i += 1
93
+ end
94
+ end
95
+
96
+ def test_make_term
97
+ tr = Tree.new_with_document_struct(DocumentStructure::RD)
98
+ de = DocumentElement.new
99
+ tr.root = de
100
+ di, dt = nil
101
+ de.build do
102
+ new DescList do
103
+ di = new DescListItem do
104
+ dt = make_term do
105
+ new StringElement, "string"
106
+ end
107
+ end
108
+ end
109
+ end
110
+ assert_equal("<RD::DescListItem>\n <RD::DescListItem::Term>\n" +
111
+ " <RD::StringElement>", di.inspect)
112
+ assert_equal(di.term, dt)
113
+
114
+ tr = Tree.new_with_document_struct(DocumentStructure::RD)
115
+ de = DocumentElement.new
116
+ tr.root = de
117
+ di, dt = nil
118
+ de.build do
119
+ new DescList do
120
+ di = new DescListItem do
121
+ dt = make_term
122
+ end
123
+ end
124
+ end
125
+ assert_equal(di.term, dt)
126
+ end
127
+
128
+ def test_inspect
129
+ di = DescListItem.new
130
+ dt = DescListItem::Term.new
131
+ se = StringElement.new "string"
132
+ tb = TextBlock.new
133
+ di.set_term_under_document_struct(dt, DocumentStructure::RD)
134
+ di.add_child_under_document_struct(tb, DocumentStructure::RD)
135
+ dt.add_child_under_document_struct(se, DocumentStructure::RD)
136
+ assert_equal("<RD::DescListItem>\n <RD::DescListItem::Term>\n" +
137
+ " <RD::StringElement>\n <RD::TextBlock>", di.inspect)
138
+
139
+ di_no_desc = DescListItem.new
140
+ dt_no_desc = DescListItem::Term.new
141
+ di_no_desc.set_term_under_document_struct(dt_no_desc,
142
+ DocumentStructure::RD)
143
+ assert_equal("<RD::DescListItem>\n <RD::DescListItem::Term>",
144
+ di_no_desc.inspect)
145
+
146
+ di_no_term = DescListItem.new
147
+ di_no_term.add_child_under_document_struct(TextBlock.new,
148
+ DocumentStructure::RD)
149
+ assert_equal("<RD::DescListItem>\n <RD::TextBlock>",
150
+ di_no_term.inspect)
151
+ assert_equal("<RD::DescListItem>", DescListItem.new.inspect)
152
+ end
153
+ end
154
+
155
+ class TestDescListItemTerm < Test::Unit::TestCase
156
+ def setup
157
+ @flat = DescListItem::Term.new
158
+ @c1 = StringElement.new "aaa"
159
+ @c2 = Emphasis.new
160
+ @c3 = StringElement.new " bbb"
161
+ @flat.add_children_under_document_struct([@c1, @c2, @c3],
162
+ DocumentStructure::RD)
163
+
164
+ @nest = DescListItem::Term.new
165
+ @d1 = StringElement.new "aaa"
166
+ @d2 = Emphasis.new
167
+ @d21 = StringElement.new " bbb"
168
+ @d2.add_child_under_document_struct(@d21, DocumentStructure::RD)
169
+ @nest.add_children_under_document_struct([@d1, @d2],
170
+ DocumentStructure::RD)
171
+ @empty = DescListItem::Term.new
172
+ end
173
+
174
+ def test_each_child
175
+ exp = [@c1, @c2, @c3]
176
+ i = 0
177
+ @flat.each_child do |b|
178
+ assert_equal(exp[i], b)
179
+ i += 1
180
+ end
181
+
182
+ exp = [@d1, @d2]
183
+ i = 0
184
+ @nest.each_child do |b|
185
+ assert_equal(exp[i], b)
186
+ i += 1
187
+ end
188
+ end
189
+
190
+ def test_each_element
191
+ exp = [@flat, @c1, @c2, @c3]
192
+ i = 0
193
+ @flat.each_element do |b|
194
+ assert_equal(exp[i], b)
195
+ i += 1
196
+ end
197
+
198
+ exp = [@nest, @d1, @d2, @d21]
199
+ i = 0
200
+ @nest.each_element do |b|
201
+ assert_equal(exp[i], b)
202
+ i += 1
203
+ end
204
+
205
+ exp = [@empty]
206
+ i = 0
207
+ @empty.each_element do |b|
208
+ assert_equal(exp[i], b)
209
+ i += 1
210
+ end
211
+ end
212
+
213
+ def test_to_label
214
+ assert_equal("aaa bbb", @flat.to_label)
215
+ assert_equal("aaabbb", @nest.to_label)
216
+ assert_equal("", @empty.to_label)
217
+ end
218
+ end
219
+
@@ -0,0 +1,46 @@
1
+ require 'test/unit'
2
+
3
+ require 'rd/element'
4
+ require 'rd/rd-struct'
5
+
6
+ include RD
7
+
8
+ class TestDocumentElement < Test::Unit::TestCase
9
+ def setup
10
+ @p = DocumentElement.new
11
+ @c1 = Headline.new(1)
12
+ @c2 = TextBlock.new
13
+ @c3 = ItemList.new
14
+ @c31 = ItemListItem.new
15
+ @c311 = TextBlock.new
16
+ @c31.add_child_under_document_struct(@c311, DocumentStructure::RD)
17
+ @c3.add_child_under_document_struct(@c31, DocumentStructure::RD)
18
+ @p.add_children_under_document_struct([@c1, @c2, @c3],
19
+ DocumentStructure::RD)
20
+ end
21
+
22
+ def test_s_new
23
+ assert(DocumentElement.new)
24
+ end
25
+
26
+ def test_blocks
27
+ assert_equal([@c1, @c2, @c3], @p.blocks)
28
+ end
29
+
30
+ def test_each_block
31
+ i = 1
32
+ @p.each_block do |b|
33
+ assert_equal(eval("@c#{i}"), b)
34
+ i += 1
35
+ end
36
+ end
37
+
38
+ def test_each_element
39
+ exp = [@p, @c1, @c2, @c3, @c31, @c311]
40
+ i = 0
41
+ @p.each_element do |b|
42
+ assert_equal(exp[i], b)
43
+ i += 1
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,66 @@
1
+ require 'test/unit'
2
+
3
+ require 'rd/document-struct.rb'
4
+ require 'rd/rdfmt'
5
+
6
+ class TestDocumentStructure < Test::Unit::TestCase
7
+ include RD
8
+
9
+ def test_each_relationship
10
+ a = DocumentStructure.new
11
+ r1 = ElementRelationship.new(TextBlock, InlineElement)
12
+ r2 = ElementRelationship.new(DocumentElement, BlockElement)
13
+ r3 = ElementRelationship.new(ListItem, BlockElement)
14
+ r4 = ElementRelationship.new(ItemList, ItemListItem)
15
+ exp = [r1, r2, r3, r4]
16
+
17
+ a.add_relationships(*exp)
18
+
19
+ a.each_relationship do |i|
20
+ assert(exp.include?(i))
21
+ exp.delete(i)
22
+ end
23
+ assert_equal([], exp)
24
+ end
25
+
26
+ def test_is_valid?
27
+ a = DocumentStructure.new
28
+ r1 = ElementRelationship.new(TextBlock, InlineElement)
29
+ r2 = ElementRelationship.new(DocumentElement, BlockElement)
30
+ r3 = ElementRelationship.new(ListItem, BlockElement)
31
+ r4 = ElementRelationship.new(ItemList, ItemListItem)
32
+ a.add_relationships(r1, r2, r3, r4)
33
+
34
+ assert(a.is_valid?(TextBlock.new, Emphasis.new))
35
+ assert(a.is_valid?(DocumentElement.new, TextBlock.new))
36
+ assert(a.is_valid?(ItemList.new, ItemListItem.new))
37
+ assert_false(a.is_valid?(TextBlock.new, Headline.new(1)))
38
+ assert_false(a.is_valid?(ItemList.new, TextBlock.new))
39
+ end
40
+ end
41
+
42
+ class TestElementRelationship < Test::Unit::TestCase
43
+ include RD
44
+
45
+ def test_match?
46
+ a = ElementRelationship.new(TextBlock, InlineElement)
47
+ assert(a.match?(TextBlock.new, Emphasis.new))
48
+ assert_false(a.match?(TextBlock.new, Headline.new(1)))
49
+
50
+ a = ElementRelationship.new(InlineElement, InlineElement)
51
+ assert(a.match?(Emphasis.new, Code.new))
52
+ assert_false(a.match?(Emphasis.new, Headline.new(1)))
53
+
54
+ a = ElementRelationship.new(DocumentElement, BlockElement)
55
+ assert(a.match?(DocumentElement.new, Headline.new(1)))
56
+ assert_false(a.match?(DocumentElement.new, Emphasis.new))
57
+
58
+ a = ElementRelationship.new(ItemList, ItemListItem)
59
+ assert(a.match?(ItemList.new, ItemListItem.new))
60
+ assert_false(a.match?(ItemList.new, TextBlock.new))
61
+ end
62
+ end
63
+
64
+ def assert_false(cond)
65
+ assert_equal(false, cond)
66
+ end