raf 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +674 -0
- data/Gemfile.lock +20 -0
- data/History.rdoc +2 -0
- data/LICENSE.txt +11 -17
- data/README.rdoc +2 -13
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/bin/raf2html +18 -0
- data/lib/default.css +116 -0
- data/lib/parserutility.rb +18 -0
- data/lib/raf2html.rb +167 -0
- data/lib/raf2html_element.rb +195 -0
- data/lib/rafblockparser.output +670 -0
- data/lib/rafblockparser.ry +356 -0
- data/lib/rafblockparser.tab.rb +717 -0
- data/lib/rafelement.rb +219 -0
- data/lib/rafinlineparser.output +1804 -0
- data/lib/rafinlineparser.ry +451 -0
- data/lib/rafinlineparser.tab.rb +1117 -0
- data/raf.gemspec +118 -0
- data/test/test_descblock.rb +88 -0
- data/test/test_emphasis.rb +76 -0
- data/test/test_erb.rb +23 -0
- data/test/test_footnote.rb +38 -0
- data/test/test_headline.rb +43 -0
- data/test/test_headline_and_itemlist.rb +40 -0
- data/test/test_helper.rb +2 -0
- data/test/test_image.rb +81 -0
- data/test/test_italic.rb +76 -0
- data/test/test_itemlistblock.rb +151 -0
- data/test/test_numlistblock.rb +342 -0
- data/test/test_paragraph.rb +76 -0
- data/test/test_quoteblock.rb +109 -0
- data/test/test_reference.rb +47 -0
- data/test/test_ruby.rb +66 -0
- data/test/test_strike.rb +76 -0
- data/test/test_tableblock.rb +63 -0
- data/test/test_verb.rb +86 -0
- data/test/ts_block.rb +9 -0
- data/test/ts_inline.rb +8 -0
- data/test/ts_rafparser.rb +4 -0
- metadata +67 -12
- data/lib/raf.rb +0 -0
- data/test/test_raf.rb +0 -7
@@ -0,0 +1,151 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), "../lib")
|
3
|
+
require 'test_helper'
|
4
|
+
require 'rafblockparser.tab'
|
5
|
+
|
6
|
+
class TestRafItemListBlock < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@raf = Raf::BlockParser.new
|
9
|
+
@itemlist = ListString.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_list_is_list
|
13
|
+
nodes = @raf.parse(@itemlist.single)
|
14
|
+
assert_kind_of Raf::ItemList, nodes[0]
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_list_is_plain_text_block
|
18
|
+
nodes = @raf.parse(@itemlist.single)
|
19
|
+
assert_kind_of Raf::ItemList, nodes[0]
|
20
|
+
assert_equal [Raf::PlainTextBlock], nodes[0].contents.map {|n| n.class }
|
21
|
+
assert_equal "<ItemList><ItemListItem>aaa</ItemListItem></ItemList>", nodes[0].apply
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_list_multi_line
|
25
|
+
nodes = @raf.parse(@itemlist.multi)
|
26
|
+
assert_kind_of Raf::ItemList, nodes[0]
|
27
|
+
assert_equal [Raf::PlainTextBlock, Raf::PlainTextBlock], nodes[0].contents.map {|n| n.class }
|
28
|
+
assert_equal "<ItemList><ItemListItem>aaa</ItemListItem><ItemListItem>bbb</ItemListItem></ItemList>", nodes[0].apply
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_list_nest
|
32
|
+
nodes = @raf.parse(@itemlist.nest)
|
33
|
+
assert_kind_of Raf::ItemList, nodes[0]
|
34
|
+
assert_equal [Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Symbol], nodes[0].contents.map {|n| n.class }
|
35
|
+
assert_equal "<ItemList><ItemListItem>aaa</ItemListItem><INDENT/><ItemListItem>bbb</ItemListItem><DEDENT/></ItemList>", nodes[0].apply
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_list_nest_and_unnest
|
39
|
+
nodes = @raf.parse(@itemlist.nest_and_unnest_multi_line)
|
40
|
+
assert_kind_of Raf::ItemList, nodes[0]
|
41
|
+
assert_equal [Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Symbol, Symbol, Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock], nodes[0].contents.map {|n| n.class }
|
42
|
+
assert_equal "<ItemList><ItemListItem>aaa</ItemListItem><INDENT/><ItemListItem>bbb</ItemListItem><ItemListItem>ccc</ItemListItem><INDENT/><ItemListItem>ddd</ItemListItem><ItemListItem>eee</ItemListItem><INDENT/><ItemListItem>fff</ItemListItem><DEDENT/><DEDENT/><ItemListItem>ggg</ItemListItem><DEDENT/><ItemListItem>hhh</ItemListItem></ItemList>", nodes[0].apply
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_list_with_inline_element
|
46
|
+
nodes = @raf.parse(@itemlist.inline_element)
|
47
|
+
assert_kind_of Raf::ItemList, nodes[0]
|
48
|
+
assert_equal [Raf::PlainTextBlock, Raf::PlainTextBlock, Raf::PlainTextBlock], nodes[0].contents.map {|n| n.class }
|
49
|
+
assert_kind_of Raf::Emphasis, nodes[0].contents[0].contents[1]
|
50
|
+
assert_equal "<ItemList><ItemListItem>aaa<Emphasis>AAA</Emphasis></ItemListItem><ItemListItem>bbb</ItemListItem><ItemListItem><Italic>ccc</Italic></ItemListItem></ItemList>", nodes[0].apply
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_list_multi_block
|
54
|
+
nodes = @raf.parse(@itemlist.multi_block)
|
55
|
+
assert_equal 3, nodes.size # [itemblock, whiteline, itemblock]
|
56
|
+
assert_kind_of Raf::ItemList, nodes[0]
|
57
|
+
assert_kind_of Raf::ItemList, nodes[2]
|
58
|
+
assert_equal [Raf::PlainTextBlock,Raf::PlainTextBlock], nodes[0].contents.map {|n| n.class }
|
59
|
+
assert_equal [Raf::PlainTextBlock,Raf::PlainTextBlock], nodes[2].contents.map {|n| n.class }
|
60
|
+
assert_equal "<ItemList><ItemListItem>aaa</ItemListItem><ItemListItem>bbb</ItemListItem></ItemList>", nodes[0].apply
|
61
|
+
assert_equal "<ItemList><ItemListItem>ccc</ItemListItem><ItemListItem>ddd</ItemListItem></ItemList>", nodes[2].apply
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_list_with_br
|
65
|
+
nodes = @raf.parse(@itemlist.with_br)
|
66
|
+
assert_equal "<ItemList><ItemListItem>aaa\nbbb</ItemListItem></ItemList>", nodes[0].apply
|
67
|
+
assert_equal "<ItemList><ItemListItem>aaa</ItemListItem></ItemList>", nodes[2].apply
|
68
|
+
assert_equal "bbb", nodes[4].apply
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_list_and_quote
|
72
|
+
nodes = @raf.parse(@itemlist.and_quote)
|
73
|
+
assert_kind_of Raf::ItemList, nodes[0]
|
74
|
+
assert_kind_of Raf::WhiteLine, nodes[1]
|
75
|
+
assert_kind_of Raf::Quote, nodes[2]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class ListString
|
80
|
+
def single
|
81
|
+
"* aaa"
|
82
|
+
end
|
83
|
+
|
84
|
+
def multi
|
85
|
+
<<EOL
|
86
|
+
* aaa
|
87
|
+
* bbb
|
88
|
+
EOL
|
89
|
+
end
|
90
|
+
|
91
|
+
def nest
|
92
|
+
<<EOL
|
93
|
+
* aaa
|
94
|
+
* bbb
|
95
|
+
EOL
|
96
|
+
end
|
97
|
+
|
98
|
+
def nest_and_unnest_multi_line
|
99
|
+
<<EOL
|
100
|
+
* aaa
|
101
|
+
* bbb
|
102
|
+
* ccc
|
103
|
+
* ddd
|
104
|
+
* eee
|
105
|
+
* fff
|
106
|
+
* ggg
|
107
|
+
* hhh
|
108
|
+
EOL
|
109
|
+
end
|
110
|
+
|
111
|
+
def inline_element
|
112
|
+
<<EOL
|
113
|
+
* aaa((*AAA*))
|
114
|
+
* bbb
|
115
|
+
* ((_ccc_))
|
116
|
+
EOL
|
117
|
+
end
|
118
|
+
|
119
|
+
def multi_block
|
120
|
+
<<EOL
|
121
|
+
* aaa
|
122
|
+
* bbb
|
123
|
+
|
124
|
+
* ccc
|
125
|
+
* ddd
|
126
|
+
EOL
|
127
|
+
end
|
128
|
+
|
129
|
+
def and_quote
|
130
|
+
<<EOL
|
131
|
+
* aaa
|
132
|
+
* bbb
|
133
|
+
|
134
|
+
ccc
|
135
|
+
ddd
|
136
|
+
EOL
|
137
|
+
end
|
138
|
+
|
139
|
+
# 空行がなればリスト、あれば引用
|
140
|
+
def with_br
|
141
|
+
<<EOL
|
142
|
+
* aaa
|
143
|
+
bbb
|
144
|
+
|
145
|
+
* aaa
|
146
|
+
|
147
|
+
bbb
|
148
|
+
EOL
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
@@ -0,0 +1,342 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), "../lib")
|
3
|
+
require 'test_helper'
|
4
|
+
require 'rafblockparser.tab'
|
5
|
+
|
6
|
+
class TestRafNumListBlock < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@raf = Raf::BlockParser.new
|
9
|
+
@numlist1 = NumlistString1.new
|
10
|
+
@numlist2 = NumlistString2.new
|
11
|
+
@numlistmix = NumlistStringMix.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_numlist_is_numlist
|
15
|
+
res1 = @raf.parse(@numlist1.single)
|
16
|
+
assert_kind_of Raf::NumList, res1[0]
|
17
|
+
|
18
|
+
res2 = @raf.parse(@numlist2.single)
|
19
|
+
assert_kind_of Raf::NumList, res2[0]
|
20
|
+
|
21
|
+
res3 = @raf.parse(@numlistmix.single)
|
22
|
+
assert_kind_of Raf::NumList, res3[0]
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_numlist_is_plain_text_block
|
26
|
+
res1 = @raf.parse(@numlist1.single)
|
27
|
+
assert_kind_of Raf::NumList, res1[0]
|
28
|
+
assert_equal [Raf::PlainTextBlock], res1[0].contents.map {|n| n.class }
|
29
|
+
assert_equal "<NumList><NumListItem>1. aaa</NumListItem></NumList>", res1[0].apply
|
30
|
+
|
31
|
+
res2 = @raf.parse(@numlist2.single)
|
32
|
+
assert_kind_of Raf::NumList, res2[0]
|
33
|
+
assert_equal [Raf::PlainTextBlock], res2[0].contents.map {|n| n.class }
|
34
|
+
assert_equal "<NumList><NumListItem>1. aaa</NumListItem></NumList>", res2[0].apply
|
35
|
+
|
36
|
+
res3 = @raf.parse(@numlistmix.single)
|
37
|
+
assert_kind_of Raf::NumList, res3[0]
|
38
|
+
assert_equal [Raf::PlainTextBlock], res3[0].contents.map {|n| n.class }
|
39
|
+
assert_equal "<NumList><NumListItem>1. aaa</NumListItem></NumList>", res3[0].apply
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_numlist_multi_line
|
43
|
+
res1 = @raf.parse(@numlist1.multi)
|
44
|
+
assert_kind_of Raf::NumList, res1[0]
|
45
|
+
assert_equal [Raf::PlainTextBlock, Raf::PlainTextBlock], res1[0].contents.map {|n| n.class }
|
46
|
+
assert_equal "<NumList><NumListItem>1. aaa</NumListItem><NumListItem>2. bbb</NumListItem></NumList>", res1[0].apply
|
47
|
+
|
48
|
+
res2 = @raf.parse(@numlist2.multi)
|
49
|
+
assert_kind_of Raf::NumList, res2[0]
|
50
|
+
assert_equal [Raf::PlainTextBlock, Raf::PlainTextBlock], res2[0].contents.map {|n| n.class }
|
51
|
+
assert_equal "<NumList><NumListItem>1. aaa</NumListItem><NumListItem>2. bbb</NumListItem></NumList>", res2[0].apply
|
52
|
+
|
53
|
+
res3 = @raf.parse(@numlistmix.multi)
|
54
|
+
assert_kind_of Raf::NumList, res3[0]
|
55
|
+
assert_equal [Raf::PlainTextBlock, Raf::PlainTextBlock], res3[0].contents.map {|n| n.class }
|
56
|
+
assert_equal "<NumList><NumListItem>1. aaa</NumListItem><NumListItem>2. bbb</NumListItem></NumList>", res3[0].apply
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_numlist_nest
|
60
|
+
res1 = @raf.parse(@numlist1.nest)
|
61
|
+
assert_kind_of Raf::NumList, res1[0]
|
62
|
+
assert_equal [Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Symbol], res1[0].contents.map {|n| n.class }
|
63
|
+
assert_equal "<NumList><NumListItem>1. aaa</NumListItem><INDENT/><NumListItem>2. bbb</NumListItem><DEDENT/></NumList>", res1[0].apply
|
64
|
+
|
65
|
+
res2 = @raf.parse(@numlist2.nest)
|
66
|
+
assert_kind_of Raf::NumList, res2[0]
|
67
|
+
assert_equal [Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Symbol], res2[0].contents.map {|n| n.class }
|
68
|
+
assert_equal "<NumList><NumListItem>1. aaa</NumListItem><INDENT/><NumListItem>2. bbb</NumListItem><DEDENT/></NumList>", res2[0].apply
|
69
|
+
|
70
|
+
res3 = @raf.parse(@numlistmix.nest)
|
71
|
+
assert_kind_of Raf::NumList, res3[0]
|
72
|
+
assert_equal [Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Symbol], res3[0].contents.map {|n| n.class }
|
73
|
+
assert_equal "<NumList><NumListItem>1. aaa</NumListItem><INDENT/><NumListItem>2. bbb</NumListItem><DEDENT/></NumList>", res3[0].apply
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_numlist_nest_and_unnest
|
77
|
+
res1 = @raf.parse(@numlist1.nest_and_unnest_multi_line)
|
78
|
+
assert_kind_of Raf::NumList, res1[0]
|
79
|
+
assert_equal [Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Symbol, Symbol, Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock], res1[0].contents.map {|n| n.class }
|
80
|
+
assert_equal "<NumList><NumListItem>1. aaa</NumListItem><INDENT/><NumListItem>2. bbb</NumListItem><NumListItem>3. ccc</NumListItem><INDENT/><NumListItem>4. ddd</NumListItem><NumListItem>5. eee</NumListItem><INDENT/><NumListItem>6. fff</NumListItem><DEDENT/><DEDENT/><NumListItem>7. ggg</NumListItem><DEDENT/><NumListItem>8. hhh</NumListItem></NumList>", res1[0].apply
|
81
|
+
|
82
|
+
res2 = @raf.parse(@numlist2.nest_and_unnest_multi_line)
|
83
|
+
assert_kind_of Raf::NumList, res2[0]
|
84
|
+
assert_equal [Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Symbol, Symbol, Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock], res2[0].contents.map {|n| n.class }
|
85
|
+
assert_equal "<NumList><NumListItem>1. aaa</NumListItem><INDENT/><NumListItem>2. bbb</NumListItem><NumListItem>3. ccc</NumListItem><INDENT/><NumListItem>4. ddd</NumListItem><NumListItem>5. eee</NumListItem><INDENT/><NumListItem>6. fff</NumListItem><DEDENT/><DEDENT/><NumListItem>7. ggg</NumListItem><DEDENT/><NumListItem>8. hhh</NumListItem></NumList>", res2[0].apply
|
86
|
+
|
87
|
+
res3 = @raf.parse(@numlistmix.nest_and_unnest_multi_line)
|
88
|
+
assert_kind_of Raf::NumList, res3[0]
|
89
|
+
assert_equal [Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock, Symbol, Symbol, Raf::PlainTextBlock, Symbol, Raf::PlainTextBlock], res3[0].contents.map {|n| n.class }
|
90
|
+
assert_equal "<NumList><NumListItem>1. aaa</NumListItem><INDENT/><NumListItem>2. bbb</NumListItem><NumListItem>3. ccc</NumListItem><INDENT/><NumListItem>4. ddd</NumListItem><NumListItem>5. eee</NumListItem><INDENT/><NumListItem>6. fff</NumListItem><DEDENT/><DEDENT/><NumListItem>7. ggg</NumListItem><DEDENT/><NumListItem>8. hhh</NumListItem></NumList>", res3[0].apply
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_numlist_with_inline_element
|
94
|
+
res1 = @raf.parse(@numlist1.inline_element)
|
95
|
+
assert_kind_of Raf::NumList, res1[0]
|
96
|
+
assert_equal [Raf::PlainTextBlock, Raf::PlainTextBlock, Raf::PlainTextBlock], res1[0].contents.map {|n| n.class }
|
97
|
+
assert_kind_of Raf::Emphasis, res1[0].contents[0].contents[1]
|
98
|
+
assert_equal "<NumList><NumListItem>1. aaa<Emphasis>AAA</Emphasis></NumListItem><NumListItem>2. bbb</NumListItem><NumListItem>3. <Italic>ccc</Italic></NumListItem></NumList>", res1[0].apply
|
99
|
+
|
100
|
+
res2 = @raf.parse(@numlist2.inline_element)
|
101
|
+
assert_kind_of Raf::NumList, res2[0]
|
102
|
+
assert_equal [Raf::PlainTextBlock, Raf::PlainTextBlock, Raf::PlainTextBlock], res2[0].contents.map {|n| n.class }
|
103
|
+
assert_kind_of Raf::Emphasis, res2[0].contents[0].contents[1]
|
104
|
+
assert_equal "<NumList><NumListItem>1. aaa<Emphasis>AAA</Emphasis></NumListItem><NumListItem>2. bbb</NumListItem><NumListItem>3. <Italic>ccc</Italic></NumListItem></NumList>", res2[0].apply
|
105
|
+
|
106
|
+
res3 = @raf.parse(@numlistmix.inline_element)
|
107
|
+
assert_kind_of Raf::NumList, res3[0]
|
108
|
+
assert_equal [Raf::PlainTextBlock, Raf::PlainTextBlock, Raf::PlainTextBlock], res3[0].contents.map {|n| n.class }
|
109
|
+
assert_kind_of Raf::Emphasis, res3[0].contents[0].contents[1]
|
110
|
+
assert_equal "<NumList><NumListItem>1. aaa<Emphasis>AAA</Emphasis></NumListItem><NumListItem>2. bbb</NumListItem><NumListItem>3. <Italic>ccc</Italic></NumListItem></NumList>", res3[0].apply
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_numlist_multi_block
|
114
|
+
res1 = @raf.parse(@numlist1.multi_block)
|
115
|
+
assert_equal 3, res1.size # [itemblock, whiteline, itemblock]
|
116
|
+
assert_kind_of Raf::NumList, res1[0]
|
117
|
+
assert_kind_of Raf::NumList, res1[2]
|
118
|
+
assert_equal [Raf::PlainTextBlock,Raf::PlainTextBlock], res1[0].contents.map {|n| n.class }
|
119
|
+
assert_equal [Raf::PlainTextBlock,Raf::PlainTextBlock], res1[2].contents.map {|n| n.class }
|
120
|
+
assert_equal "<NumList><NumListItem>1. aaa</NumListItem><NumListItem>2. bbb</NumListItem></NumList>", res1[0].apply
|
121
|
+
assert_equal "<NumList><NumListItem>1. ccc</NumListItem><NumListItem>2. ddd</NumListItem></NumList>", res1[2].apply
|
122
|
+
|
123
|
+
res2 = @raf.parse(@numlist2.multi_block)
|
124
|
+
assert_equal 3, res2.size # [itemblock, whiteline, itemblock]
|
125
|
+
assert_kind_of Raf::NumList, res2[0]
|
126
|
+
assert_kind_of Raf::NumList, res2[2]
|
127
|
+
assert_equal [Raf::PlainTextBlock,Raf::PlainTextBlock], res2[0].contents.map {|n| n.class }
|
128
|
+
assert_equal [Raf::PlainTextBlock,Raf::PlainTextBlock], res2[2].contents.map {|n| n.class }
|
129
|
+
assert_equal "<NumList><NumListItem>1. aaa</NumListItem><NumListItem>2. bbb</NumListItem></NumList>", res2[0].apply
|
130
|
+
assert_equal "<NumList><NumListItem>1. ccc</NumListItem><NumListItem>2. ddd</NumListItem></NumList>", res2[2].apply
|
131
|
+
|
132
|
+
res3 = @raf.parse(@numlistmix.multi_block)
|
133
|
+
assert_equal 3, res3.size # [itemblock, whiteline, itemblock]
|
134
|
+
assert_kind_of Raf::NumList, res3[0]
|
135
|
+
assert_kind_of Raf::NumList, res3[2]
|
136
|
+
assert_equal [Raf::PlainTextBlock,Raf::PlainTextBlock], res3[0].contents.map {|n| n.class }
|
137
|
+
assert_equal [Raf::PlainTextBlock,Raf::PlainTextBlock], res3[2].contents.map {|n| n.class }
|
138
|
+
assert_equal "<NumList><NumListItem>1. aaa</NumListItem><NumListItem>2. bbb</NumListItem></NumList>", res3[0].apply
|
139
|
+
assert_equal "<NumList><NumListItem>1. ccc</NumListItem><NumListItem>2. ddd</NumListItem></NumList>", res3[2].apply
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_numlist_and_quote
|
143
|
+
res1 = @raf.parse(@numlist1.and_quote)
|
144
|
+
assert_kind_of Raf::NumList, res1[0]
|
145
|
+
assert_kind_of Raf::WhiteLine, res1[1]
|
146
|
+
assert_kind_of Raf::Quote, res1[2]
|
147
|
+
|
148
|
+
res2 = @raf.parse(@numlist2.and_quote)
|
149
|
+
assert_kind_of Raf::NumList, res2[0]
|
150
|
+
assert_kind_of Raf::WhiteLine, res2[1]
|
151
|
+
assert_kind_of Raf::Quote, res2[2]
|
152
|
+
|
153
|
+
res3 = @raf.parse(@numlistmix.and_quote)
|
154
|
+
assert_kind_of Raf::NumList, res3[0]
|
155
|
+
assert_kind_of Raf::WhiteLine, res3[1]
|
156
|
+
assert_kind_of Raf::Quote, res3[2]
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class NumlistString1
|
161
|
+
def single
|
162
|
+
"(1) aaa"
|
163
|
+
end
|
164
|
+
|
165
|
+
def multi
|
166
|
+
<<EOL
|
167
|
+
(1) aaa
|
168
|
+
(2) bbb
|
169
|
+
EOL
|
170
|
+
end
|
171
|
+
|
172
|
+
def nest
|
173
|
+
<<EOL
|
174
|
+
(1) aaa
|
175
|
+
(1) bbb
|
176
|
+
EOL
|
177
|
+
end
|
178
|
+
|
179
|
+
def nest_and_unnest_multi_line
|
180
|
+
<<EOL
|
181
|
+
(1) aaa
|
182
|
+
(2) bbb
|
183
|
+
(3) ccc
|
184
|
+
(4) ddd
|
185
|
+
(5) eee
|
186
|
+
(6) fff
|
187
|
+
(7) ggg
|
188
|
+
(8) hhh
|
189
|
+
EOL
|
190
|
+
end
|
191
|
+
|
192
|
+
def inline_element
|
193
|
+
<<EOL
|
194
|
+
(1) aaa((*AAA*))
|
195
|
+
(2) bbb
|
196
|
+
(3) ((_ccc_))
|
197
|
+
EOL
|
198
|
+
end
|
199
|
+
|
200
|
+
def multi_block
|
201
|
+
<<EOL
|
202
|
+
(1) aaa
|
203
|
+
(2) bbb
|
204
|
+
|
205
|
+
(3) ccc
|
206
|
+
(4) ddd
|
207
|
+
EOL
|
208
|
+
end
|
209
|
+
|
210
|
+
def and_quote
|
211
|
+
<<EOL
|
212
|
+
(1) aaa
|
213
|
+
(2) bbb
|
214
|
+
|
215
|
+
ccc
|
216
|
+
ddd
|
217
|
+
EOL
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
class NumlistString2
|
223
|
+
def single
|
224
|
+
"1. aaa"
|
225
|
+
end
|
226
|
+
|
227
|
+
def multi
|
228
|
+
<<EOL
|
229
|
+
1. aaa
|
230
|
+
2. bbb
|
231
|
+
EOL
|
232
|
+
end
|
233
|
+
|
234
|
+
def nest
|
235
|
+
<<EOL
|
236
|
+
1. aaa
|
237
|
+
1. bbb
|
238
|
+
EOL
|
239
|
+
end
|
240
|
+
|
241
|
+
def nest_and_unnest_multi_line
|
242
|
+
<<EOL
|
243
|
+
1. aaa
|
244
|
+
2. bbb
|
245
|
+
3. ccc
|
246
|
+
4. ddd
|
247
|
+
5. eee
|
248
|
+
6. fff
|
249
|
+
7. ggg
|
250
|
+
8. hhh
|
251
|
+
EOL
|
252
|
+
end
|
253
|
+
|
254
|
+
def inline_element
|
255
|
+
<<EOL
|
256
|
+
1. aaa((*AAA*))
|
257
|
+
2. bbb
|
258
|
+
3. ((_ccc_))
|
259
|
+
EOL
|
260
|
+
end
|
261
|
+
|
262
|
+
def multi_block
|
263
|
+
<<EOL
|
264
|
+
1. aaa
|
265
|
+
2. bbb
|
266
|
+
|
267
|
+
3. ccc
|
268
|
+
4. ddd
|
269
|
+
EOL
|
270
|
+
end
|
271
|
+
|
272
|
+
def and_quote
|
273
|
+
<<EOL
|
274
|
+
1. aaa
|
275
|
+
2. bbb
|
276
|
+
|
277
|
+
ccc
|
278
|
+
ddd
|
279
|
+
EOL
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
class NumlistStringMix
|
284
|
+
def single
|
285
|
+
"1. aaa"
|
286
|
+
end
|
287
|
+
|
288
|
+
def multi
|
289
|
+
<<EOL
|
290
|
+
(1) aaa
|
291
|
+
2. bbb
|
292
|
+
EOL
|
293
|
+
end
|
294
|
+
|
295
|
+
def nest
|
296
|
+
<<EOL
|
297
|
+
(1) aaa
|
298
|
+
2. bbb
|
299
|
+
EOL
|
300
|
+
end
|
301
|
+
|
302
|
+
def nest_and_unnest_multi_line
|
303
|
+
<<EOL
|
304
|
+
1. aaa
|
305
|
+
(2) bbb
|
306
|
+
3. ccc
|
307
|
+
(4) ddd
|
308
|
+
(5) eee
|
309
|
+
6. fff
|
310
|
+
7. ggg
|
311
|
+
(8) hhh
|
312
|
+
EOL
|
313
|
+
end
|
314
|
+
|
315
|
+
def inline_element
|
316
|
+
<<EOL
|
317
|
+
1. aaa((*AAA*))
|
318
|
+
(2) bbb
|
319
|
+
3. ((_ccc_))
|
320
|
+
EOL
|
321
|
+
end
|
322
|
+
|
323
|
+
def multi_block
|
324
|
+
<<EOL
|
325
|
+
1. aaa
|
326
|
+
2. bbb
|
327
|
+
|
328
|
+
(3) ccc
|
329
|
+
4. ddd
|
330
|
+
EOL
|
331
|
+
end
|
332
|
+
|
333
|
+
def and_quote
|
334
|
+
<<EOL
|
335
|
+
1. aaa
|
336
|
+
(2) bbb
|
337
|
+
|
338
|
+
ccc
|
339
|
+
ddd
|
340
|
+
EOL
|
341
|
+
end
|
342
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), "../lib")
|
3
|
+
require 'test_helper'
|
4
|
+
require 'rafblockparser.tab'
|
5
|
+
|
6
|
+
class TestRafBlockParser < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@raf = Raf::BlockParser.new
|
9
|
+
@single_line_str = "aaa"
|
10
|
+
@multi_line_str = <<EOL
|
11
|
+
aaa bbb ccc
|
12
|
+
ddd eee fff
|
13
|
+
EOL
|
14
|
+
@multi_block_str = <<EOL
|
15
|
+
aaa bbb ccc
|
16
|
+
ddd eee fff
|
17
|
+
|
18
|
+
ggg hhh iii
|
19
|
+
jjj kkk lll
|
20
|
+
EOL
|
21
|
+
|
22
|
+
@single_line_with_inline_elements_str = <<EOL
|
23
|
+
aaa ((*bbb*)) ((*ccc*))
|
24
|
+
EOL
|
25
|
+
|
26
|
+
@one_space = <<EOL
|
27
|
+
aaa
|
28
|
+
EOL
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_paragraph_is_paragraph
|
32
|
+
nodes = @raf.parse(@single_line_str)
|
33
|
+
assert_kind_of Raf::Paragraph, nodes[0]
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_paragraph_single_line_node_is_plain_text
|
37
|
+
nodes = @raf.parse(@single_line_str)
|
38
|
+
nodes.each do |node|
|
39
|
+
assert_kind_of Raf::Plain, node.contents.first
|
40
|
+
assert_kind_of String, node.apply
|
41
|
+
assert_equal node.apply, @single_line_str
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_paragraph_multi_line
|
46
|
+
nodes = @raf.parse(@multi_line_str)
|
47
|
+
assert_kind_of String, nodes.first.apply
|
48
|
+
assert_equal nodes.first.apply, @multi_line_str
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_paragraph_multi_block
|
52
|
+
nodes = @raf.parse(@multi_block_str)
|
53
|
+
assert_equal 3, nodes.size # textblock, whiteline, textblock
|
54
|
+
assert_kind_of Raf::Plain, nodes[0].contents[0]
|
55
|
+
assert_kind_of String, nodes[0].apply
|
56
|
+
assert_kind_of Raf::WhiteLine, nodes[1]
|
57
|
+
assert_kind_of String, nodes[1].apply
|
58
|
+
assert_kind_of Raf::Plain, nodes[2].contents[0]
|
59
|
+
assert_kind_of String, nodes[2].apply
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_paragraph_with_inline_elements
|
63
|
+
# nodes = plain emphasis plain(space) emphasis
|
64
|
+
nodes = @raf.parse(@single_line_with_inline_elements_str)
|
65
|
+
assert_kind_of Raf::Emphasis, nodes[0].contents[1]
|
66
|
+
assert_kind_of Raf::Emphasis, nodes[0].contents[3]
|
67
|
+
|
68
|
+
assert_equal "aaa <Emphasis>bbb</Emphasis> <Emphasis>ccc</Emphasis>\n", nodes[0].apply
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_paragraph_one_space
|
72
|
+
res = @raf.parse(@one_space)
|
73
|
+
assert_kind_of Raf::Paragraph, res[0]
|
74
|
+
assert_equal " aaa\n", res[0].apply
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), "../lib")
|
3
|
+
require 'test_helper'
|
4
|
+
require 'rafblockparser.tab'
|
5
|
+
|
6
|
+
class TestRafQuoteBlock < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@raf = Raf::BlockParser.new
|
10
|
+
@quote = QuoteString.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_quote_is_quote
|
14
|
+
nodes = @raf.parse(@quote.single)
|
15
|
+
assert_kind_of Raf::Quote, nodes[0]
|
16
|
+
assert_equal delete_indent(@quote.single), nodes[0].apply
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_quote_multi
|
20
|
+
nodes = @raf.parse(@quote.multi)
|
21
|
+
assert_equal nodes.size, 1, "ホワイトリストがあっても1ブロック" # [quote]
|
22
|
+
assert_kind_of Raf::Quote, nodes[0]
|
23
|
+
assert_equal delete_indent(@quote.multi), nodes[0].apply
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_quote_inline_element
|
27
|
+
nodes = @raf.parse(@quote.inline_element)
|
28
|
+
assert_kind_of Raf::Quote, nodes[0]
|
29
|
+
# インラインエレメントは変換しないでそのまま
|
30
|
+
assert_equal delete_indent(@quote.inline_element), nodes[0].apply
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_quote_multi_indent
|
34
|
+
nodes = @raf.parse(@quote.multi_indent)
|
35
|
+
assert_kind_of Raf::Quote, nodes[0]
|
36
|
+
# インデントを無視する
|
37
|
+
assert_equal "aaa\n bbb\n ccc\n ddd\nfff", nodes[0].apply
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_quote_space
|
41
|
+
res1 = @raf.parse(@quote.space)
|
42
|
+
assert_kind_of Raf::Quote, res1[0]
|
43
|
+
assert_equal "aaa\nbbb",res1[0].apply
|
44
|
+
|
45
|
+
res2 = @raf.parse(@quote.space2)
|
46
|
+
assert_kind_of Raf::Quote, res2[0]
|
47
|
+
assert_equal "aaa\nbbb",res2[0].apply
|
48
|
+
end
|
49
|
+
|
50
|
+
def delete_indent(str)
|
51
|
+
str.map {|s| s.sub(/^ /, "") }.to_s.strip
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
class QuoteString
|
57
|
+
def single
|
58
|
+
<<EOL
|
59
|
+
aaa
|
60
|
+
bbb
|
61
|
+
EOL
|
62
|
+
end
|
63
|
+
|
64
|
+
def multi
|
65
|
+
<<EOL
|
66
|
+
aaa
|
67
|
+
bbb
|
68
|
+
|
69
|
+
ccc
|
70
|
+
ddd
|
71
|
+
EOL
|
72
|
+
end
|
73
|
+
|
74
|
+
def inline_element
|
75
|
+
<<EOL
|
76
|
+
((*aaa*))
|
77
|
+
((_bbb_))
|
78
|
+
EOL
|
79
|
+
end
|
80
|
+
|
81
|
+
def multi_indent
|
82
|
+
<<EOL
|
83
|
+
aaa
|
84
|
+
bbb
|
85
|
+
ccc
|
86
|
+
ddd
|
87
|
+
fff
|
88
|
+
EOL
|
89
|
+
end
|
90
|
+
|
91
|
+
def space
|
92
|
+
<<EOL
|
93
|
+
aaa
|
94
|
+
bbb
|
95
|
+
|
96
|
+
ccc
|
97
|
+
EOL
|
98
|
+
end
|
99
|
+
|
100
|
+
def space2
|
101
|
+
<<EOL
|
102
|
+
aaa
|
103
|
+
bbb
|
104
|
+
|
105
|
+
|
106
|
+
ccc
|
107
|
+
EOL
|
108
|
+
end
|
109
|
+
end
|