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
@@ -0,0 +1,33 @@
1
+ require 'test/unit'
2
+
3
+ require 'rd/inline-element'
4
+ require 'rd/document-struct'
5
+ require 'dummy'
6
+
7
+ include RD
8
+
9
+ DummyStruct.define_relationship(NonterminalInline, DummyElement)
10
+
11
+ class TestNonterminalInline < Test::Unit::TestCase
12
+ def test_children
13
+ el = NonterminalInline.new
14
+ assert_equal([], el.children)
15
+ el.children.push 1
16
+ assert_equal([1], el.children)
17
+ end
18
+
19
+ def test_to_label
20
+ one = NonterminalInline.new
21
+ one.add_child_under_document_struct(DummyElement.new, DummyStruct)
22
+ assert_equal("label", one.to_label)
23
+
24
+ two = NonterminalInline.new
25
+ two.add_child_under_document_struct(DummyElement.new, DummyStruct)
26
+ two.add_child_under_document_struct(DummyElement.new, DummyStruct)
27
+ assert_equal("label label", two.to_label)
28
+
29
+ zero = NonterminalInline.new
30
+ assert_equal("", zero.to_label)
31
+ end
32
+ end
33
+
@@ -0,0 +1,48 @@
1
+ require 'test/unit'
2
+
3
+ require 'temp-dir'
4
+
5
+ require 'rd/output-format-visitor'
6
+ require 'rd/tree'
7
+ require 'rd/element'
8
+ require 'rd/block-element'
9
+ require 'rd/inline-element'
10
+ require 'rd/rd-struct'
11
+
12
+ include RD
13
+
14
+ class TestOFVisitor < Test::Unit::TestCase
15
+ def setup
16
+ end
17
+
18
+ def test_initialize
19
+ vis = OutputFormatVisitor.new
20
+ assert_equal([], vis.include_suffix)
21
+ vis = SampleVisitor.new
22
+ assert_equal(["html"], vis.include_suffix)
23
+ end
24
+
25
+ def test_apply_to_include
26
+ tree = Tree.new_with_document_struct(DocumentStructure::RD,
27
+ ["test/data/sub", "test/data/"])
28
+ de = DocumentElement.new
29
+ # test/data/includee1.html
30
+ inc1 = Include.new("includee1")
31
+ # test/data/includee2.html, test/data/sub/includee2.html
32
+ inc2 = Include.new("includee2")
33
+ # test/data/includee3.nothtml
34
+ inc3 = Include.new("includee3")
35
+ tree.root = de
36
+ de.add_child(inc1)
37
+ de.add_child(inc2)
38
+ de.add_child(inc3)
39
+ vis = SampleVisitor.new
40
+ assert_equal("includee1.html", vis.apply_to_Include(inc1))
41
+ assert_equal("sub/includee2.html", vis.apply_to_Include(inc2))
42
+ assert_equal(nil, vis.apply_to_Include(inc3))
43
+ end
44
+ end
45
+
46
+ class SampleVisitor < OutputFormatVisitor
47
+ INCLUDE_SUFFIX = ["html"]
48
+ end
@@ -0,0 +1,41 @@
1
+ require 'test/unit'
2
+
3
+ require 'rd/rdblockparser.tab'
4
+ require 'rd/rd-struct'
5
+
6
+ include RD
7
+
8
+ class TestParserUtil < Test::Unit::TestCase
9
+ def setup
10
+ @p = RDParser.new
11
+ @tree = tree = Tree.new_with_document_struct(DocumentStructure::RD)
12
+ @p.instance_eval do
13
+ @tree = tree
14
+ end
15
+ end
16
+
17
+ def test_tree
18
+ obj = Object.new
19
+ obj.extend(ParserUtility)
20
+
21
+ assert_raises(NotImplementedError) do
22
+ obj.tree
23
+ end
24
+ end
25
+
26
+ def test_add_children_to_element
27
+ headline = Headline.new(1)
28
+ string_element = StringElement.new "string"
29
+ emphasis = Emphasis.new
30
+ @p.add_children_to_element(headline, string_element, emphasis)
31
+ assert_equal([string_element, emphasis], headline.children)
32
+
33
+ textblock = TextBlock.new
34
+ @p.add_children_to_element(textblock, emphasis, string_element)
35
+ assert_equal([emphasis, string_element], textblock.children)
36
+
37
+ textblock_empty = TextBlock.new
38
+ @p.add_children_to_element(textblock_empty)
39
+ assert_equal([], textblock_empty.children)
40
+ end
41
+ end
@@ -0,0 +1,156 @@
1
+ require 'test/unit'
2
+
3
+ require 'temp-dir'
4
+
5
+ require 'rd/rbl-file'
6
+ require 'rd/block-element'
7
+ require 'rd/inline-element'
8
+ require 'rd/rd-struct'
9
+ require 'rd/reference-resolver'
10
+
11
+ include RD
12
+
13
+ class TestRBLFile < Test::Unit::TestCase
14
+
15
+ def setup
16
+ tr_head2 = Tree.new_with_document_struct(DocumentStructure::RD)
17
+ de_head2 = DocumentElement.new
18
+ tr_head2.root = de_head2
19
+ hl1_head2, hl2_head2 = nil
20
+
21
+ de_head2.build do
22
+ hl1_head2 = new Headline, 1 do
23
+ new StringElement, "label1"
24
+ end
25
+ new TextBlock
26
+ hl2_head2 = new Headline, 2 do
27
+ new StringElement, "label2"
28
+ end
29
+ end
30
+
31
+ @resolv_head2 = ReferenceResolver.new(tr_head2, "label:")
32
+
33
+ tr_desc = Tree.new_with_document_struct(DocumentStructure::RD)
34
+ de_desc = DocumentElement.new
35
+ tr_desc.root = de_desc
36
+ hl1_desc, dt1_desc = nil
37
+ de_desc.build do
38
+ hl1_desc = new(Headline, 1) do
39
+ new StringElement, "label1"
40
+ end
41
+ new DescList do
42
+ new DescListItem do
43
+ dt1_desc = make_term do
44
+ new StringElement, "label2"
45
+ end
46
+ end
47
+ end
48
+ end
49
+ @resolv_desc = ReferenceResolver.new(tr_desc, "Label-")
50
+
51
+ tr_empty = Tree.new_with_document_struct(DocumentStructure::RD)
52
+ de_empty = DocumentElement.new
53
+ tr_empty.root = de_empty
54
+ @resolv_empty = ReferenceResolver.new(tr_empty, "LABEL")
55
+
56
+ tr_arr = Tree.new_with_document_struct(DocumentStructure::RD)
57
+ de_arr = DocumentElement.new
58
+ tr_arr.root = de_arr
59
+
60
+ de_arr.build do
61
+ new Headline, 1 do
62
+ new StringElement, "a => b"
63
+ end
64
+ end
65
+
66
+ @resolv_arr = ReferenceResolver.new(tr_arr, "label:")
67
+
68
+ @rbl_head2 = RBLFile.new("test-head2")
69
+ @rbl_desc = RBLFile.new("test-desc")
70
+ @rbl_empty = RBLFile.new("test-empty")
71
+ @rbl_arr = RBLFile.new("test-arr")
72
+ end
73
+
74
+ def test_labels_to_string
75
+ res = "label1 => label:0\nlabel2 => label:1"
76
+ assert_equal(res, RBLFile.labels_to_string(@resolv_head2))
77
+
78
+ res2 = "label1 => Label-0\nlabel2 => Label-1"
79
+ assert_equal(res2, RBLFile.labels_to_string(@resolv_desc))
80
+
81
+ res_empty = ""
82
+ assert_equal(res_empty, RBLFile.labels_to_string(@resolv_empty))
83
+
84
+ res_arr = "a => b => label:0"
85
+ assert_equal(res_arr, RBLFile.labels_to_string(@resolv_arr))
86
+ end
87
+
88
+ def test_string_to_labels
89
+ rbl = RBLFile.new("test-head2")
90
+ src_head2 = "label1 => label:0\nlabel2 => label:1"
91
+ res_head2 = [["label1", "label:0"], ["label2", "label:1"]]
92
+ assert_equal(res_head2, rbl.string_to_labels(src_head2))
93
+
94
+ src_head2 = "label1 =>label:0\nlabel2=> label:1"
95
+ res_head2 = [["label1", "label:0"], ["label2", "label:1"]]
96
+ assert_equal(res_head2, rbl.string_to_labels(src_head2))
97
+
98
+ src_desc = "label1 => Label-0\nlabel2 => Label-1"
99
+ res_desc = [["label1", "Label-0"], ["label2", "Label-1"]]
100
+ assert_equal(res_desc, rbl.string_to_labels(src_desc))
101
+
102
+ src_empty = ""
103
+ res_empty = []
104
+ assert_equal(res_empty, @rbl_empty.string_to_labels(src_empty))
105
+
106
+ src_arr = "a => b => label:0"
107
+ res_arr = [["a => b", "label:0"]]
108
+ assert_equal(res_arr, @rbl_arr.string_to_labels(src_arr))
109
+ end
110
+
111
+ def test_rbl_file_path
112
+ assert_equal("test-head2.rbl", RBLFile.rbl_file_path("test-head2.rd"))
113
+ assert_equal("test-head2.rbl", RBLFile.rbl_file_path("test-head2.rb"))
114
+ assert_equal("test-desc.rbl", RBLFile.rbl_file_path("test-desc"))
115
+ end
116
+
117
+ def test_s_create_rbl_file
118
+ in_temp_dir do
119
+ begin
120
+ RBLFile.create_rbl_file("test-head2.rd", @resolv_head2)
121
+ assert(File.exist?("test-head2.rbl"))
122
+ ensure
123
+ remove_file("test-head2.rbl")
124
+ end
125
+ end
126
+ end
127
+
128
+ def test_load_rbl_file
129
+ in_temp_dir do
130
+ spath = [Dir.pwd]
131
+ begin
132
+ RBLFile.create_rbl_file("test-head2.rd", @resolv_head2)
133
+
134
+ rbl_rd = RBLFile.new("test-head2.rd")
135
+ rbl_rd.load_rbl_file(spath)
136
+ res = [["label1", "label:0"], ["label2", "label:1"]]
137
+ assert_equal(res, rbl_rd.labels)
138
+
139
+ rbl_no = RBLFile.new("test-head2")
140
+ rbl_no.load_rbl_file(spath)
141
+ assert_equal(res, rbl_no.labels)
142
+ ensure
143
+ remove_file("test-head2.rbl")
144
+ end
145
+ end
146
+ end
147
+
148
+ def test_refer
149
+ spath = ["test/data"]
150
+ rbl = RBLFile.new("label")
151
+ rbl.load_rbl_file(spath)
152
+ assert_equal("label:0", rbl.refer("label1"))
153
+ assert_equal("label:1", rbl.refer("label2"))
154
+ assert_equal(nil, rbl.refer("label3"))
155
+ end
156
+ end
@@ -0,0 +1,43 @@
1
+ require 'test/unit'
2
+
3
+ require 'rd/rbl-suite'
4
+ require 'rd/rbl-file'
5
+
6
+ include RD
7
+
8
+ class TestRBLSuite < Test::Unit::TestCase
9
+
10
+ def setup
11
+ @suite = RBLSuite.new(["test/data"])
12
+ end
13
+
14
+ def test_get_rbl_file
15
+ assert_equal([], @suite.rbl_files)
16
+ rbl = @suite.get_rbl_file("label.rd")
17
+ assert_equal(rbl, @suite.get_rbl_file("label.rd"))
18
+ assert_equal(1, @suite.rbl_files.size)
19
+ end
20
+
21
+ def test_add_rbl_file
22
+ assert_equal([], @suite.rbl_files)
23
+ rbl = @suite.add_rbl_file("label.rd")
24
+ assert_kind_of(RBLFile, rbl)
25
+ assert_equal(1, @suite.rbl_files.size)
26
+ assert_equal("label", @suite.rbl_files[0].filename)
27
+ assert_equal(rbl, @suite.rbl_files[0])
28
+
29
+ assert_nothing_raised do
30
+ @suite.add_rbl_file("not-exist-label.rd")
31
+ end
32
+ end
33
+
34
+ def test_refer
35
+ assert_equal(["label", "label:0"], @suite.refer("label1", "label.rd"))
36
+ assert_equal(["label2", "Label-0"], @suite.refer("label1", "label2.rd"))
37
+ assert_equal(["label", "label:0"], @suite.refer("label1", "label"))
38
+ assert_equal(["label", "label:1"], @suite.refer("label2", "label.rd"))
39
+ assert_equal(["label", nil], @suite.refer("label3", "label.rd"))
40
+ fns = @suite.rbl_files.collect{|i| i.filename }
41
+ assert_equal(["label", "label2"], fns)
42
+ end
43
+ end
@@ -0,0 +1,496 @@
1
+ require 'test/unit'
2
+
3
+ require 'rd/rd2html-lib'
4
+ require 'rd/tree'
5
+ require 'rd/element'
6
+ require 'rd/block-element'
7
+ require 'rd/list'
8
+ require 'rd/desclist'
9
+ require 'rd/methodlist'
10
+ require 'rd/inline-element'
11
+ require 'rd/rd-struct'
12
+
13
+ include RD
14
+
15
+ class TestRD2HTMLVisitor < Test::Unit::TestCase
16
+
17
+ def setup
18
+ @vis = RD2HTMLVisitor.new
19
+ @vis.class.module_eval {
20
+ public :xml_decl
21
+ public :forward_links, :backward_links
22
+ public :document_title
23
+ public :html_content_type
24
+ public :html_title
25
+ public :html_open_tag
26
+ public :link_to_css
27
+ public :prepare_footnotes
28
+ public :make_foottext
29
+ }
30
+ @ch1 = ["a"]
31
+ @ch2 = ["a", "b"]
32
+ @ch3 = ["a\n"]
33
+ @ch0 = []
34
+
35
+ @tr_fn = Tree.new_with_document_struct(DocumentStructure::RD)
36
+ @tr_fn.root = DocumentElement.new
37
+ fn1, fn2 = nil
38
+ @tr_fn.root.build do
39
+ new TextBlock do
40
+ fn1 = new Footnote do
41
+ new StringElement, "footnote 1"
42
+ end
43
+ fn2 = new Footnote do
44
+ new StringElement, "footnote 2"
45
+ end
46
+ end
47
+ end
48
+ @fn1_fn = fn1
49
+ @fn2_fn = fn2
50
+
51
+ @tr2_fn = Tree.new_with_document_struct(DocumentStructure::RD)
52
+ @tr2_fn.root = DocumentElement.new
53
+ @tr2_fn.root.build do
54
+ new Headline, 1
55
+ new TextBlock do
56
+ new StringElement, "string"
57
+ end
58
+ end
59
+ end
60
+
61
+ def test_xml_decl
62
+ vis_with_charset = RD2HTMLVisitor.new
63
+ vis_with_charset.charset = "CharSet"
64
+ assert_equal(%|<?xml version="1.0" encoding="CharSet" ?>|,
65
+ vis_with_charset.xml_decl)
66
+ vis_no_charset = RD2HTMLVisitor.new
67
+ assert_equal(%|<?xml version="1.0" ?>|,
68
+ vis_no_charset.xml_decl)
69
+ end
70
+
71
+ def test_html_open_tag
72
+ vis_with_lang = RD2HTMLVisitor.new
73
+ vis_with_lang.lang = "Language"
74
+ assert_equal(%|<html xmlns="http://www.w3.org/1999/xhtml" lang="Language"|+
75
+ %| xml:lang="Language">|, vis_with_lang.html_open_tag)
76
+
77
+ vis_no_lang = RD2HTMLVisitor.new
78
+ assert_equal(%|<html xmlns="http://www.w3.org/1999/xhtml">|,
79
+ vis_no_lang.html_open_tag)
80
+ end
81
+
82
+ def test_html_title
83
+ vis_with_title = RD2HTMLVisitor.new
84
+ vis_with_title.title = "Title"
85
+ assert_equal("<title>Title</title>", vis_with_title.html_title)
86
+
87
+ vis_no_title = RD2HTMLVisitor.new
88
+ assert_equal("<title>Untitled</title>", vis_no_title.html_title)
89
+ end
90
+
91
+ def test_html_content_type
92
+ vis_with_charset = RD2HTMLVisitor.new
93
+ vis_with_charset.charset = "CharSet"
94
+ assert_equal(%|<meta http-equiv="Content-type" | +
95
+ %|content="text/html; charset=CharSet" | +
96
+ "/>", vis_with_charset.html_content_type)
97
+ vis_no_charset = RD2HTMLVisitor.new
98
+ assert_equal(nil, vis_no_charset.html_content_type)
99
+ end
100
+
101
+ def test_link_to_css
102
+ vis_with_css = RD2HTMLVisitor.new
103
+ vis_with_css.css = "CSS.css"
104
+ assert_equal(%|<link href="CSS.css" type="text/css" rel="stylesheet"| +
105
+ " />", vis_with_css.link_to_css)
106
+ vis_no_css = RD2HTMLVisitor.new
107
+ assert_equal(nil, vis_no_css.link_to_css)
108
+ end
109
+
110
+ def test_forward_links
111
+ vis_rel1 = RD2HTMLVisitor.new
112
+ vis_rel1.html_link_rel["rel1"] = "REL1"
113
+ assert_equal('<link href="REL1" rel="rel1" />', vis_rel1.forward_links)
114
+
115
+ vis_rel2 = vis_rel1
116
+ vis_rel2.html_link_rel["rel2"] = "REL2"
117
+ assert_equal('<link href="REL1" rel="rel1" />' + "\n" +
118
+ '<link href="REL2" rel="rel2" />', vis_rel2.forward_links)
119
+
120
+ vis_no_rel = RD2HTMLVisitor.new
121
+ assert_equal(nil, vis_no_rel.forward_links)
122
+ end
123
+
124
+ def test_backward_links
125
+ vis_rev1 = RD2HTMLVisitor.new
126
+ vis_rev1.html_link_rev["rev1"] = "REV1"
127
+ assert_equal('<link href="REV1" rev="rev1" />', vis_rev1.backward_links)
128
+
129
+ vis_rev2 = vis_rev1
130
+ vis_rev2.html_link_rev["rev2"] = "REV2"
131
+ assert_equal('<link href="REV1" rev="rev1" />' + "\n" +
132
+ '<link href="REV2" rev="rev2" />', vis_rev2.backward_links)
133
+
134
+ vis_no_rev = RD2HTMLVisitor.new
135
+ assert_equal(nil, vis_no_rev.backward_links)
136
+ end
137
+
138
+
139
+ def test_document_title
140
+ vis_titled = RD2HTMLVisitor.new
141
+ vis_titled.title = "Title"
142
+ assert_equal("Title", vis_titled.document_title)
143
+
144
+ vis_with_filename = RD2HTMLVisitor.new
145
+ vis_with_filename.filename = "FileName"
146
+ assert_equal("FileName", vis_with_filename.document_title)
147
+
148
+ vis_untitled = RD2HTMLVisitor.new
149
+ assert_equal("Untitled", vis_untitled.document_title)
150
+ end
151
+
152
+ def test_apply_to_Headline
153
+ tr = Tree.new_with_document_struct(DocumentStructure::RD)
154
+ tr.root = DocumentElement.new
155
+ hl1, hl2 = nil
156
+ tr.root.build do
157
+ hl1 = new Headline, 1 do
158
+ new StringElement, "headline 1"
159
+ end
160
+ hl2 = new Headline, 2 do
161
+ new StringElement, "headline 2"
162
+ end
163
+ end
164
+ @vis.prepare_labels(tr, "label:")
165
+
166
+ assert_equal(expect_for_hl1(@ch1), @vis.apply_to_Headline(hl1, @ch1))
167
+ assert_equal(expect_for_hl1(@ch2), @vis.apply_to_Headline(hl1, @ch2))
168
+ assert_equal(expect_for_hl1(@ch0), @vis.apply_to_Headline(hl1, @ch0))
169
+ assert_equal(expect_for_hl2(@ch1), @vis.apply_to_Headline(hl2, @ch1))
170
+ assert_equal(expect_for_hl2(@ch2), @vis.apply_to_Headline(hl2, @ch2))
171
+ assert_equal(expect_for_hl2(@ch0), @vis.apply_to_Headline(hl2, @ch0))
172
+ end
173
+
174
+ def expect_for_hl1(children)
175
+ %|<h1><a name="label:0" id="label:0">#{children.join('')}</a></h1><!-- RDLabel: "headline 1" -->|
176
+ end
177
+
178
+ def expect_for_hl2(children)
179
+ %|<h2><a name="label:1" id="label:1">#{children.join('')}</a></h2><!-- RDLabel: "headline 2" -->|
180
+ end
181
+
182
+ def test_apply_to_TextBlock
183
+ tb = TextBlock.new
184
+ assert_equal("<p>a</p>", @vis.apply_to_TextBlock(tb, @ch1))
185
+ assert_equal("<p>ab</p>", @vis.apply_to_TextBlock(tb, @ch2))
186
+ assert_equal("<p>a</p>", @vis.apply_to_TextBlock(tb, @ch3))
187
+ assert_equal("<p></p>", @vis.apply_to_TextBlock(tb, @ch0))
188
+
189
+ tb_in_list = TextBlock.new
190
+ li = ItemListItem.new
191
+ li.add_child_under_document_struct(tb_in_list, DocumentStructure::RD)
192
+ assert_equal("a", @vis.apply_to_TextBlock(tb_in_list, @ch1))
193
+ assert_equal("ab", @vis.apply_to_TextBlock(tb_in_list, @ch2))
194
+ assert_equal("a", @vis.apply_to_TextBlock(tb_in_list, @ch3))
195
+ assert_equal("", @vis.apply_to_TextBlock(tb_in_list, @ch0))
196
+
197
+ tb1_in_list2 = TextBlock.new
198
+ tb2_in_list2 = TextBlock.new
199
+ li2 = ItemListItem.new
200
+ li2.add_children_under_document_struct([tb1_in_list2, tb2_in_list2],
201
+ DocumentStructure::RD)
202
+ assert_equal("<p>a</p>", @vis.apply_to_TextBlock(tb1_in_list2, @ch1))
203
+ assert_equal("<p>ab</p>", @vis.apply_to_TextBlock(tb1_in_list2, @ch2))
204
+ assert_equal("<p>a</p>", @vis.apply_to_TextBlock(tb1_in_list2, @ch3))
205
+ assert_equal("<p></p>", @vis.apply_to_TextBlock(tb1_in_list2, @ch0))
206
+ end
207
+
208
+ def test_apply_to_Verbatim
209
+ verb1 = Verbatim.new "aaa"
210
+ assert_equal("<pre>aaa</pre>", @vis.apply_to_Verbatim(verb1))
211
+ verb2 = Verbatim.new "aaa\n"
212
+ assert_equal("<pre>aaa</pre>", @vis.apply_to_Verbatim(verb2))
213
+ verb3 = Verbatim.new "aaa\nbbb"
214
+ assert_equal("<pre>aaa\nbbb</pre>", @vis.apply_to_Verbatim(verb3))
215
+ verb_empty = Verbatim.new ""
216
+ assert_equal("<pre></pre>", @vis.apply_to_Verbatim(verb_empty))
217
+ verb_amp = Verbatim.new "&"
218
+ assert_equal("<pre>&amp;</pre>", @vis.apply_to_Verbatim(verb_amp))
219
+ verb_lt = Verbatim.new "<"
220
+ assert_equal("<pre>&lt;</pre>", @vis.apply_to_Verbatim(verb_lt))
221
+ verb_gt = Verbatim.new ">"
222
+ assert_equal("<pre>&gt;</pre>", @vis.apply_to_Verbatim(verb_gt))
223
+
224
+ verb3 = Verbatim.new ["aaa\n", "bbb"]
225
+ assert_equal("<pre>aaa\nbbb</pre>", @vis.apply_to_Verbatim(verb3))
226
+ end
227
+
228
+ def test_apply_to_ItemList
229
+ list = ItemList.new
230
+ assert_equal("<ul>\na\n</ul>", @vis.apply_to_ItemList(list, @ch1))
231
+ assert_equal("<ul>\na\nb\n</ul>", @vis.apply_to_ItemList(list, @ch2))
232
+ assert_equal("<ul>\na\n</ul>", @vis.apply_to_ItemList(list, @ch3))
233
+ assert_equal("<ul>\n\n</ul>", @vis.apply_to_ItemList(list, @ch0))
234
+ end
235
+
236
+ def test_apply_to_EnumList
237
+ list = EnumList.new
238
+ assert_equal("<ol>\na\n</ol>", @vis.apply_to_EnumList(list, @ch1))
239
+ assert_equal("<ol>\na\nb\n</ol>", @vis.apply_to_EnumList(list, @ch2))
240
+ assert_equal("<ol>\na\n</ol>", @vis.apply_to_EnumList(list, @ch3))
241
+ assert_equal("<ol>\n\n</ol>", @vis.apply_to_EnumList(list, @ch0))
242
+ end
243
+
244
+ def test_apply_to_DescList
245
+ list = DescList.new
246
+ assert_equal("<dl>\na\n</dl>", @vis.apply_to_DescList(list, @ch1))
247
+ assert_equal("<dl>\na\nb\n</dl>", @vis.apply_to_DescList(list, @ch2))
248
+ assert_equal("<dl>\na\n</dl>", @vis.apply_to_DescList(list, @ch3))
249
+ assert_equal("<dl>\n\n</dl>", @vis.apply_to_DescList(list, @ch0))
250
+ end
251
+
252
+ def test_apply_to_MethodList
253
+ list = MethodList.new
254
+ assert_equal("<dl>\na\n</dl>", @vis.apply_to_MethodList(list, @ch1))
255
+ assert_equal("<dl>\na\nb\n</dl>", @vis.apply_to_MethodList(list, @ch2))
256
+ assert_equal("<dl>\na\n</dl>", @vis.apply_to_MethodList(list, @ch3))
257
+ assert_equal("<dl>\n\n</dl>", @vis.apply_to_MethodList(list, @ch0))
258
+ end
259
+
260
+ def test_apply_to_ItemListItem
261
+ item = ItemListItem.new
262
+ assert_equal("<li>a</li>", @vis.apply_to_ItemListItem(item, @ch1))
263
+ assert_equal("<li>a\nb</li>", @vis.apply_to_ItemListItem(item, @ch2))
264
+ assert_equal("<li>a</li>", @vis.apply_to_ItemListItem(item, @ch3))
265
+ assert_equal("<li></li>", @vis.apply_to_ItemListItem(item, @ch0))
266
+ end
267
+
268
+ def test_apply_to_EnumListItem
269
+ item = EnumListItem.new
270
+ assert_equal("<li>a</li>", @vis.apply_to_EnumListItem(item, @ch1))
271
+ assert_equal("<li>a\nb</li>", @vis.apply_to_EnumListItem(item, @ch2))
272
+ assert_equal("<li>a</li>", @vis.apply_to_EnumListItem(item, @ch3))
273
+ assert_equal("<li></li>", @vis.apply_to_EnumListItem(item, @ch0))
274
+ end
275
+
276
+ def test_apply_to_DescListItem
277
+ tr = Tree.new_with_document_struct(DocumentStructure::RD)
278
+ tr.root = DocumentElement.new
279
+ di1, di2 = nil
280
+ tr.root.build do
281
+ new DescList do
282
+ di1 = new DescListItem do
283
+ make_term do
284
+ new StringElement, "desclist 1"
285
+ end
286
+ end
287
+ di2 = new DescListItem do
288
+ make_term do
289
+ new StringElement, "desclist 2"
290
+ end
291
+ end
292
+ end
293
+ end
294
+
295
+ @vis.prepare_labels(tr, "label:")
296
+
297
+ assert_equal(expect_for_di1_with_child("term1", @ch1),
298
+ @vis.apply_to_DescListItem(di1, ["term1"], @ch1))
299
+ assert_equal(expect_for_di1_with_child("term1term2", @ch1),
300
+ @vis.apply_to_DescListItem(di1, ["term1", "term2"], @ch1))
301
+ assert_equal(expect_for_di1_with_child("term1", @ch2),
302
+ @vis.apply_to_DescListItem(di1, ["term1"], @ch2))
303
+ assert_equal(expect_for_di1_with_child("term1", @ch3),
304
+ @vis.apply_to_DescListItem(di1, ["term1"], @ch3))
305
+ assert_equal(expect_for_di1_no_child("term1"),
306
+ @vis.apply_to_DescListItem(di1, ["term1"], @ch0))
307
+ assert_equal(expect_for_di1_no_child("term1term2"),
308
+ @vis.apply_to_DescListItem(di1, ["term1", "term2"], @ch0))
309
+ assert_equal(expect_for_di2_with_child("term1", @ch1),
310
+ @vis.apply_to_DescListItem(di2, ["term1"], @ch1))
311
+ assert_equal(expect_for_di2_no_child("term1"),
312
+ @vis.apply_to_DescListItem(di2, ["term1"], @ch0))
313
+
314
+ end
315
+
316
+ def expect_for_di1_with_child(term, children)
317
+ %|<dt><a name="label:0" id="label:0">#{term}</a></dt><!-- RDLabel: "desclist 1" -->\n| +
318
+ %|<dd>\n#{children.join("\n").chomp}\n</dd>|
319
+ end
320
+
321
+ def expect_for_di1_no_child(term)
322
+ %|<dt><a name="label:0" id="label:0">#{term}</a></dt><!-- RDLabel: "desclist 1" -->|
323
+ end
324
+
325
+ def expect_for_di2_with_child(term, children)
326
+ %|<dt><a name="label:1" id="label:1">#{term}</a></dt><!-- RDLabel: "desclist 2" -->\n| +
327
+ %|<dd>\n#{children.join("\n").chomp}\n</dd>|
328
+ end
329
+
330
+ def expect_for_di2_no_child(term)
331
+ %|<dt><a name="label:1" id="label:1">#{term}</a></dt><!-- RDLabel: "desclist 2" -->|
332
+ end
333
+
334
+ # MethodListItem ...
335
+
336
+ def check_apply_to_NonterminalInline(type, tag)
337
+ element = type.new
338
+ name = type.to_s.sub(/RD::/, "")
339
+
340
+ assert_equal("<#{tag}>a</#{tag}>",
341
+ @vis.send("apply_to_#{name}", element, @ch1))
342
+ assert_equal("<#{tag}>ab</#{tag}>",
343
+ @vis.send("apply_to_#{name}", element, @ch2))
344
+ assert_equal("<#{tag}>a\n</#{tag}>",
345
+ @vis.send("apply_to_#{name}", element, @ch3))
346
+ assert_equal("<#{tag}></#{tag}>",
347
+ @vis.send("apply_to_#{name}", element, @ch0))
348
+ end
349
+
350
+ def test_apply_to_Emphasis
351
+ check_apply_to_NonterminalInline(Emphasis, "em")
352
+ end
353
+
354
+ def test_apply_to_Code
355
+ check_apply_to_NonterminalInline(Code, "code")
356
+ end
357
+
358
+ def test_apply_to_Var
359
+ check_apply_to_NonterminalInline(Var, "var")
360
+ end
361
+
362
+ def test_apply_to_Keyboard
363
+ check_apply_to_NonterminalInline(Keyboard, "kbd")
364
+ end
365
+
366
+ def test_apply_to_StringElement
367
+ se1 = StringElement.new "a"
368
+ assert_equal("a", @vis.apply_to_StringElement(se1))
369
+ se2 = StringElement.new "a\nb"
370
+ assert_equal("a\nb", @vis.apply_to_StringElement(se2))
371
+ se_empty = StringElement.new ""
372
+ assert_equal("", @vis.apply_to_StringElement(se_empty))
373
+ se_ws = StringElement.new " "
374
+ assert_equal(" ", @vis.apply_to_StringElement(se_ws))
375
+ se_lt = StringElement.new "<"
376
+ assert_equal("&lt;", @vis.apply_to_StringElement(se_lt))
377
+ se_gt = StringElement.new ">"
378
+ assert_equal("&gt;", @vis.apply_to_StringElement(se_gt))
379
+ se_amp = StringElement.new "&"
380
+ assert_equal("&amp;", @vis.apply_to_StringElement(se_amp))
381
+ end
382
+
383
+ def test_apply_to_Verb
384
+ verb1 = Verb.new "a"
385
+ assert_equal("a", @vis.apply_to_Verb(verb1))
386
+ verb2 = Verb.new "a\nb"
387
+ assert_equal("a\nb", @vis.apply_to_Verb(verb2))
388
+ verb_empty = Verb.new ""
389
+ assert_equal("", @vis.apply_to_Verb(verb_empty))
390
+ verb_ws = Verb.new " "
391
+ assert_equal(" ", @vis.apply_to_Verb(verb_ws))
392
+ verb_lt = Verb.new "<"
393
+ assert_equal("&lt;", @vis.apply_to_Verb(verb_lt))
394
+ verb_gt = Verb.new ">"
395
+ assert_equal("&gt;", @vis.apply_to_Verb(verb_gt))
396
+ verb_amp = Verb.new "&"
397
+ assert_equal("&amp;", @vis.apply_to_Verb(verb_amp))
398
+ end
399
+
400
+ def test_apply_to_Footnote
401
+ @vis.prepare_footnotes(@tr_fn)
402
+ assert_equal([], @vis.foottexts)
403
+
404
+ assert_equal(expect_for_footnote(1),
405
+ @vis.apply_to_Footnote(@fn1_fn, ["footnote 1"]))
406
+ assert_equal([["footnote 1"]], @vis.foottexts)
407
+
408
+ assert_equal(expect_for_footnote(2),
409
+ @vis.apply_to_Footnote(@fn2_fn, ["footnote", " 2"]))
410
+ assert_equal([["footnote 1"], ["footnote", " 2"]], @vis.foottexts)
411
+
412
+ @vis.prepare_footnotes(@tr2_fn)
413
+ assert_raises(ArgumentError) do
414
+ @vis.apply_to_Footnote(@fn2_fn, [])
415
+ end
416
+ end
417
+
418
+ def expect_for_footnote(num)
419
+ %Q|<a name="footmark-#{num}" id="footmark-#{num}" href="#foottext-#{num}">|+
420
+ %Q|<sup><small>*#{num}</small></sup></a>|
421
+ end
422
+
423
+ def test_get_footnote_num
424
+ @vis.prepare_footnotes(@tr_fn)
425
+ assert_equal(1, @vis.get_footnote_num(@fn1_fn))
426
+ assert_equal(2, @vis.get_footnote_num(@fn2_fn))
427
+ assert_equal(nil, @vis.get_footnote_num(Footnote.new))
428
+ @vis.prepare_footnotes(@tr2_fn)
429
+ assert_equal(nil, @vis.get_footnote_num(@fn1_fn))
430
+
431
+ assert_raises(ArgumentError) do
432
+ @vis.get_footnote_num(Headline.new(1))
433
+ end
434
+ end
435
+
436
+ def test_prepare_footnotes
437
+ @vis.prepare_footnotes(@tr_fn)
438
+ assert_equal([@fn1_fn, @fn2_fn], @vis.footnotes)
439
+
440
+ @vis.prepare_footnotes(@tr2_fn)
441
+ assert_equal([], @vis.footnotes)
442
+ end
443
+
444
+ def test_add_foottext
445
+ @vis.prepare_footnotes(@tr_fn)
446
+ assert_equal([], @vis.foottexts)
447
+ @vis.add_foottext(@vis.get_footnote_num(@fn1_fn), ["footnote 1"])
448
+ assert_equal([["footnote 1"]], @vis.foottexts)
449
+ @vis.add_foottext(@vis.get_footnote_num(@fn2_fn), ["footnote", "2"])
450
+ assert_equal([["footnote 1"], ["footnote", "2"]], @vis.foottexts)
451
+ assert_raises(ArgumentError) do
452
+ @vis.add_foottext(3, "footnote 3")
453
+ end
454
+ end
455
+
456
+ def test_apply_to_Foottext
457
+ @vis.prepare_footnotes(@tr_fn)
458
+
459
+ exp1 = %|<a name="foottext-1" id="foottext-1" href="#footmark-1">| +
460
+ %|<sup><small>*1</small></sup></a>| +
461
+ %|<small>footnote 1</small><br />|
462
+ assert_equal(exp1, @vis.apply_to_Foottext(@fn1_fn, ["footnote 1"]))
463
+ exp2 = %|<a name="foottext-2" id="foottext-2" href="#footmark-2">| +
464
+ %|<sup><small>*2</small></sup></a>| +
465
+ %|<small>footnote 2</small><br />|
466
+ assert_equal(exp2, @vis.apply_to_Foottext(@fn2_fn, ["footnote", " 2"]))
467
+
468
+ @vis.prepare_footnotes(@tr2_fn)
469
+ assert_raises(ArgumentError) do
470
+ @vis.apply_to_Foottext(@fn1_fn, ["footnote 1"])
471
+ end
472
+ end
473
+
474
+ def test_make_foottext
475
+ @vis.prepare_footnotes(@tr_fn)
476
+ ft1 = ["footnote 1"]
477
+ ft2 = ["footnote", " 2"]
478
+ @vis.add_foottext(@vis.get_footnote_num(@fn1_fn), ft1)
479
+ @vis.add_foottext(@vis.get_footnote_num(@fn2_fn), ft2)
480
+ exp1 = @vis.apply_to_Foottext(@fn1_fn, ft1)
481
+ exp2 = @vis.apply_to_Foottext(@fn2_fn, ft2)
482
+ assert_equal(%|<hr />\n<p class="foottext">\n#{exp1}\n#{exp2}\n</p>|, @vis.make_foottext)
483
+
484
+ @vis.prepare_footnotes(@tr2_fn)
485
+ assert_equal(nil, @vis.make_foottext)
486
+ end
487
+
488
+ def test_hyphen_escape
489
+ assert_equal("&shy;&shy;", @vis.hyphen_escape("--"))
490
+ assert_equal("-", @vis.hyphen_escape("-"))
491
+ assert_equal("&shy;&shy;-", @vis.hyphen_escape("---"))
492
+ assert_equal("- -", @vis.hyphen_escape("- -"))
493
+ assert_equal("aa&shy;&shy;bb", @vis.hyphen_escape("aa--bb"))
494
+ assert_equal("", @vis.hyphen_escape(""))
495
+ end
496
+ end