hparser 0.3.0 → 0.4.0
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/.gitignore +2 -0
- data/.travis.yml +11 -0
- data/ChangeLog +4 -0
- data/Gemfile +3 -0
- data/README.md +40 -0
- data/Rakefile +12 -0
- data/VERSION +1 -0
- data/hparser.gemspec +21 -0
- data/lib/hparser/block/dl.rb +4 -4
- data/lib/hparser/block/footnote_list.rb +19 -0
- data/lib/hparser/block/head.rb +2 -2
- data/lib/hparser/block/list.rb +8 -8
- data/lib/hparser/block/p.rb +4 -3
- data/lib/hparser/block/pair.rb +12 -7
- data/lib/hparser/block/quote.rb +32 -2
- data/lib/hparser/block/raw.rb +34 -0
- data/lib/hparser/block/see_more.rb +31 -0
- data/lib/hparser/block/super_pre.rb +21 -3
- data/lib/hparser/block/table.rb +4 -4
- data/lib/hparser/hatena.rb +3 -1
- data/lib/hparser/html.rb +181 -13
- data/lib/hparser/inline/comment.rb +27 -0
- data/lib/hparser/inline/footnote.rb +34 -0
- data/lib/hparser/inline/fotolife.rb +40 -0
- data/lib/hparser/inline/hatena_id.rb +7 -6
- data/lib/hparser/inline/parser.rb +3 -2
- data/lib/hparser/inline/tex.rb +27 -0
- data/lib/hparser/inline/text.rb +3 -2
- data/lib/hparser/inline/url.rb +20 -6
- data/lib/hparser/latex.rb +273 -0
- data/lib/hparser/parser.rb +17 -1
- data/lib/hparser/text.rb +42 -0
- data/lib/hparser/util/line_scanner.rb +3 -2
- data/lib/hparser.rb +1 -0
- data/test/integration_texts/error1.ok.hatena +23 -0
- data/test/test_block.rb +65 -2
- data/test/test_bruteforce.rb +48 -0
- data/test/test_dl.rb +13 -1
- data/test/test_footnote.rb +42 -0
- data/test/test_fotolife.rb +29 -0
- data/test/test_from_perl/01_module.t +559 -0
- data/test/test_from_perl/02_module_extend.t +36 -0
- data/test/test_from_perl/10_autolink.t +78 -0
- data/test/test_from_perl/11_autolink_extend.t +43 -0
- data/test/test_hatena.rb +2 -2
- data/test/test_head.rb +7 -1
- data/test/test_helper.rb +11 -0
- data/test/test_html.rb +39 -3
- data/test/test_id.rb +1 -1
- data/test/test_inline.rb +13 -1
- data/test/test_inline_html.rb +37 -2
- data/test/test_integration.rb +20 -0
- data/test/test_latex.rb +101 -0
- data/test/test_p.rb +23 -3
- data/test/test_pair.rb +22 -4
- data/test/test_quote.rb +69 -0
- data/test/test_see_more.rb +28 -0
- data/test/test_table.rb +1 -1
- data/test/test_tex.rb +24 -0
- data/test/test_text.rb +12 -2
- data/test/test_url.rb +39 -2
- metadata +141 -58
- data/README +0 -17
data/test/test_head.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'hparser/parser'
|
3
3
|
require 'hparser/block/head'
|
4
4
|
require 'hparser/inline/text'
|
@@ -28,6 +28,12 @@ class HeadTest < Test::Unit::TestCase
|
|
28
28
|
assert_equal [head(100,"aaa")],parse("#{'*'*100}aaa")
|
29
29
|
end
|
30
30
|
|
31
|
+
def test_empty_head
|
32
|
+
assert_equal [head(1, "")],parse("*")
|
33
|
+
assert_equal [head(1, "")],parse("* ")
|
34
|
+
assert_equal [head(1, "")],parse("* ")
|
35
|
+
end
|
36
|
+
|
31
37
|
def head level,str
|
32
38
|
Head.new level,[Text.new(str)]
|
33
39
|
end
|
data/test/test_helper.rb
ADDED
data/test/test_html.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'hparser/block/all'
|
3
3
|
require 'hparser/inline/all'
|
4
4
|
require 'hparser/html'
|
@@ -14,22 +14,46 @@ class HtmlTest < Test::Unit::TestCase
|
|
14
14
|
assert_equal expect,node.to_html
|
15
15
|
end
|
16
16
|
|
17
|
+
def test_blank
|
18
|
+
parser = HParser::Parser.new
|
19
|
+
assert_equal parser.parse(''), []
|
20
|
+
end
|
21
|
+
|
17
22
|
def test_head
|
23
|
+
assert_equal Head.head_level, 1
|
18
24
|
assert_html '<h1>foo</h1>',Head.new(1,[Text.new('foo')])
|
25
|
+
Head.head_level = 2
|
26
|
+
assert_html '<h2>foo</h2>',Head.new(1,[Text.new('foo')])
|
27
|
+
Head.head_level = 4
|
28
|
+
assert_html '<h4>foo</h4>',Head.new(1,[Text.new('foo')])
|
29
|
+
Head.head_level = 1
|
19
30
|
end
|
20
31
|
|
21
32
|
def test_p
|
22
33
|
assert_html '<p>foobar</p>',P.new([Text.new('foobar')])
|
23
|
-
assert_html '<
|
34
|
+
assert_html '<br />',Empty.new
|
35
|
+
assert_html '<a name="seemore"></a>',SeeMore.new(false)
|
36
|
+
assert_html '<a name="seeall"></a>',SeeMore.new(true)
|
24
37
|
end
|
25
38
|
|
26
39
|
def test_pre
|
27
40
|
assert_html '<pre>foobar</pre>',Pre.new([Text.new('foobar')])
|
28
41
|
assert_html '<pre>foobar</pre>',SuperPre.new('foobar')
|
42
|
+
assert_html "<pre>aaa\n bbb\nccc</pre>",SuperPre.new("aaa\n bbb\nccc")
|
43
|
+
spre = SuperPre.new('foobar', 'ruby<>')
|
44
|
+
assert_html '<pre class="ruby<>">foobar</pre>', spre
|
45
|
+
spre = SuperPre.new('foobar', 'ruby')
|
46
|
+
assert_html '<pre class="ruby">foobar</pre>', spre
|
47
|
+
SuperPre.class_format_prefix = 'brush: '
|
48
|
+
assert_html '<pre class="brush: ruby">foobar</pre>', spre
|
29
49
|
end
|
30
50
|
|
31
51
|
def test_quote
|
32
|
-
assert_html '<blockquote>foobar</blockquote>',Quote.new([Text.new('foobar')])
|
52
|
+
assert_html '<blockquote><p>foobar</p></blockquote>',Quote.new([P.new([Text.new('foobar')])])
|
53
|
+
assert_html '<blockquote><p>foobar</p><cite><a href="http://example.com">http://example.com</a></cite></blockquote>',
|
54
|
+
Quote.new([P.new([Text.new('foobar')])], Url.new('http://example.com'))
|
55
|
+
assert_html '<blockquote><p>foobar</p><cite><a href="http://example.com">TITLE</a></cite></blockquote>',
|
56
|
+
Quote.new([P.new([Text.new('foobar')])], Url.new('http://example.com', 'TITLE'))
|
33
57
|
end
|
34
58
|
|
35
59
|
def test_table
|
@@ -41,6 +65,10 @@ class HtmlTest < Test::Unit::TestCase
|
|
41
65
|
def test_list
|
42
66
|
assert_html '<ul><li>aaa</li><li>bbb</li></ul>',Ul.new(Li.new([Text.new('aaa')]),Li.new([Text.new('bbb')]))
|
43
67
|
assert_html '<ol><li>aaa</li><li>bbb</li></ol>',Ol.new(Li.new([Text.new('aaa')]),Li.new([Text.new('bbb')]))
|
68
|
+
assert_html '<ol><li>aaa<ul><li>bbb</li></ul></li></ol>',Ol.new(Li.new([Text.new('aaa')]),
|
69
|
+
Ul.new(Li.new([Text.new('bbb')])))
|
70
|
+
assert_html '<ul><li>aaa<ol><li>bbb</li></ol></li></ul>',Ul.new(Li.new([Text.new('aaa')]),
|
71
|
+
Ol.new(Li.new([Text.new('bbb')])))
|
44
72
|
assert_html '<ol><ul><li>aaa</li></ul><li>bbb</li></ol>',Ol.new(Ul.new(Li.new([Text.new('aaa')])),
|
45
73
|
Li.new([Text.new('bbb')]))
|
46
74
|
end
|
@@ -52,6 +80,14 @@ class HtmlTest < Test::Unit::TestCase
|
|
52
80
|
assert_html expect,Dl.new(first,second)
|
53
81
|
end
|
54
82
|
|
83
|
+
def test_footnote_list
|
84
|
+
expect = '<div class="footnote">' +
|
85
|
+
'<p class="footnote"><a href="#fn1" name="f1">*1</a>: text1</p>' +
|
86
|
+
'<p class="footnote"><a href="#fn2" name="f2">*2</a>: text2</p>' +
|
87
|
+
'</div>'
|
88
|
+
assert_html expect, FootnoteList.new([Footnote.new(1, 'text1'), Footnote.new(2, 'text2')])
|
89
|
+
end
|
90
|
+
|
55
91
|
def th str
|
56
92
|
Th.new [Text.new(str)]
|
57
93
|
end
|
data/test/test_id.rb
CHANGED
data/test/test_inline.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'hparser/inline/url'
|
3
3
|
require 'hparser/inline/text'
|
4
4
|
require 'hparser/inline/hatena_id'
|
@@ -17,5 +17,17 @@ class InlineTest < Test::Unit::TestCase
|
|
17
17
|
def test_text
|
18
18
|
assert_equal [Text.new("foo is bar")],parse("foo is bar")
|
19
19
|
assert_equal [Text.new("foo\nbar")],parse("foo\nbar")
|
20
|
+
assert_not_equal [Text.new('<a href="#"></a>id:secondlife</a>')],
|
21
|
+
parse('<a href="#"></a>id:secondlife</a>')
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_id
|
25
|
+
assert_equal [Text.new("id:_ql")],parse("id:_ql")
|
26
|
+
assert_equal [HatenaId.new("secondlife")],parse("id:secondlife")
|
27
|
+
assert_equal [HatenaId.new("secondlife", true)],parse("id:secondlife:detail")
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_comment
|
31
|
+
assert_equal [Text.new("aaa "), Comment.new(" bbb ")], parse("aaa <!-- bbb -->")
|
20
32
|
end
|
21
33
|
end
|
data/test/test_inline_html.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'hparser/inline/all'
|
3
|
+
require 'hparser/parser'
|
3
4
|
require 'hparser/html'
|
4
5
|
|
5
6
|
class HtmlInlineTest < Test::Unit::TestCase
|
@@ -11,7 +12,8 @@ class HtmlInlineTest < Test::Unit::TestCase
|
|
11
12
|
def assert_html expect,str
|
12
13
|
expect.class == String and (expect = [expect])
|
13
14
|
|
14
|
-
|
15
|
+
context = HParser::Context.new
|
16
|
+
assert_equal expect,@parser.parse(str, context).map{|x| x.to_html}
|
15
17
|
end
|
16
18
|
|
17
19
|
def assert_same str
|
@@ -21,14 +23,47 @@ class HtmlInlineTest < Test::Unit::TestCase
|
|
21
23
|
def test_text
|
22
24
|
assert_same 'foo is bar'
|
23
25
|
assert_same '<a href="http://mzp.sakura.ne.jp">link!</a>'
|
26
|
+
assert_same "<img src='http://example.com/' />"
|
27
|
+
assert_same '<img src="http://example.com/" />'
|
28
|
+
assert_same '<iframe src="http://example.com/"></iframe>'
|
29
|
+
assert_same '<a href="http://example.com/"></a>'
|
24
30
|
end
|
25
31
|
|
26
32
|
def test_id
|
27
33
|
assert_html '<a href="http://d.hatena.ne.jp/mzp/">id:mzp</a>','id:mzp'
|
34
|
+
assert_html '<a href="http://d.hatena.ne.jp/mzp/" class="hatena-id-icon">' +
|
35
|
+
'<img src="http://www.st-hatena.com/users/mz/mzp/profile_s.gif" ' +
|
36
|
+
'width="16" height="16" alt="id:mzp" class="hatena-id-icon">id:mzp</a>',
|
37
|
+
'id:mzp:detail'
|
28
38
|
end
|
29
39
|
|
30
40
|
def test_url
|
31
41
|
assert_html '<a href="http://mzp.sakura.ne.jp">http://mzp.sakura.ne.jp</a>',
|
32
42
|
'http://mzp.sakura.ne.jp'
|
43
|
+
assert_html '<a href="http://example.com/">TITLE</a>',
|
44
|
+
'[http://example.com/:title=TITLE]'
|
45
|
+
assert_html '<a href="http://example.com/">A&B</a>',
|
46
|
+
'[http://example.com/:title=A&B]'
|
47
|
+
assert_html '<a href="http://example.com/#a">TITLE</a> ' +
|
48
|
+
'<a href="http://b.hatena.ne.jp/entry/http://example.com/%23a" class="http-bookmark">' +
|
49
|
+
'<img src="http://b.hatena.ne.jp/entry/image/http://example.com/%23a" alt="" class="http-bookmark"></a>',
|
50
|
+
'[http://example.com/#a:title=TITLE:bookmark]'
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_fotolife
|
54
|
+
assert_html '<a href="http://f.hatena.ne.jp/nitoyon/20100718010346">' +
|
55
|
+
'<img src="http://f.hatena.ne.jp/images/fotolife/n/nitoyon/20100718/20100718010346.jpg"></a>',
|
56
|
+
'[f:id:nitoyon:20100718010346j:image]'
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_tex
|
60
|
+
assert_html '<img src="http://chart.apis.google.com/chart?cht=tx&chf=bg,s,00000000&chl=e%5E%7Bi%5Cpi%7D+%3D+-1"' +
|
61
|
+
' class="tex" alt="e^{i\pi} = -1">',
|
62
|
+
'[tex:e^{i\pi} = -1]'
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_footnote
|
66
|
+
assert_html '<span class="footnote"><a href="#f1" title="text" name="fn1">*1</a></span>',
|
67
|
+
'((<a href="#">text</a>))'
|
33
68
|
end
|
34
69
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'hparser/parser'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
class IntegrationTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@parser = HParser::Parser.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse str
|
11
|
+
@parser.parse str
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_parse_ok
|
15
|
+
Pathname.glob(Pathname.new(__FILE__).parent.to_s + '/integration_texts/*.ok.hatena').each do |file|
|
16
|
+
assert parse(file.read), file.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
data/test/test_latex.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'hparser/block/all'
|
3
|
+
require 'hparser/inline/all'
|
4
|
+
require 'hparser/latex'
|
5
|
+
|
6
|
+
class LatexTest < Test::Unit::TestCase
|
7
|
+
include HParser::Block
|
8
|
+
include HParser::Inline
|
9
|
+
def setup
|
10
|
+
# @parser = HParser::Parser.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def assert_latex expect,node
|
14
|
+
assert_equal expect,node.to_latex
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_blank
|
18
|
+
parser = HParser::Parser.new
|
19
|
+
assert_equal parser.parse(''), []
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_head
|
23
|
+
assert_equal Head.head_level, 1
|
24
|
+
assert_latex "\\section{foo}\n\n",Head.new(1,[Text.new('foo')])
|
25
|
+
Head.head_level = 2
|
26
|
+
assert_latex "\\subsection{foo}\n\n",Head.new(1,[Text.new('foo')])
|
27
|
+
Head.head_level = 4
|
28
|
+
assert_latex "\\paragraph{foo}\n\n",Head.new(1,[Text.new('foo')])
|
29
|
+
Head.head_level = 1
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def test_p
|
34
|
+
assert_latex "foobar\n\n",P.new([Text.new('foobar')])
|
35
|
+
assert_latex "\n\n",Empty.new
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_pre
|
39
|
+
assert_latex "\\begin{verbatim}\nfoobar\n\\end{verbatim}\n",Pre.new([Text.new('foobar')])
|
40
|
+
assert_latex "\\begin{verbatim}\nfoobar\n\\end{verbatim}\n",SuperPre.new('foobar')
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_quote
|
44
|
+
assert_latex "\\begin{quotation}\nfoobar\n\n\n\\end{quotation}\n",Quote.new([P.new([Text.new('foobar')])])
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_table
|
48
|
+
table = <<EOB
|
49
|
+
\\begin{table}
|
50
|
+
\\centering
|
51
|
+
\\begin{tabular}{ l l }
|
52
|
+
foo & bar \\\\
|
53
|
+
baz & xyzzy \\\\
|
54
|
+
\\end{tabular}
|
55
|
+
\\end{table}
|
56
|
+
EOB
|
57
|
+
assert_latex table,
|
58
|
+
Table.new([th('foo'),th('bar')],
|
59
|
+
[td('baz') ,td('xyzzy')])
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_list
|
63
|
+
assert_latex "\\begin{itemize}\n \\item aaa\n\n \\item bbb\n\n\\end{itemize}\n",Ul.new(Li.new([Text.new('aaa')]),Li.new([Text.new('bbb')]))
|
64
|
+
assert_latex "\\begin{enumerate}\n \\item aaa\n\n \\item bbb\n\n\\end{enumerate}\n",Ol.new(Li.new([Text.new('aaa')]),Li.new([Text.new('bbb')]))
|
65
|
+
# assert_latex '<ol><ul><li>aaa</li></ul><li>bbb</li></ol>',Ol.new(Ul.new(Li.new([Text.new('aaa')])),
|
66
|
+
# Li.new([Text.new('bbb')]))
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_dl
|
70
|
+
expect = <<EOB
|
71
|
+
\\begin{description}
|
72
|
+
\\item[foo] \\quad \\\\
|
73
|
+
foo is ...
|
74
|
+
\\item[bar] \\quad \\\\
|
75
|
+
bar is ...
|
76
|
+
|
77
|
+
\\end{description}
|
78
|
+
EOB
|
79
|
+
|
80
|
+
first = Dl::Item.new([Text.new('foo')],[Text.new('foo is ...')])
|
81
|
+
second = Dl::Item.new([Text.new('bar')],[Text.new('bar is ...')])
|
82
|
+
assert_latex expect,Dl.new(first,second)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_footnote
|
86
|
+
assert_latex "\\footnote{text1}", Footnote.new(1, "text1")
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_tex
|
90
|
+
assert_latex "$e^{i\pi} = -1$", Tex.new("e^{i\pi} = -1")
|
91
|
+
end
|
92
|
+
|
93
|
+
def th str
|
94
|
+
Th.new [Text.new(str)]
|
95
|
+
end
|
96
|
+
|
97
|
+
def td str
|
98
|
+
Td.new [Text.new(str)]
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
data/test/test_p.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'hparser/parser'
|
3
3
|
require 'hparser/block/p'
|
4
4
|
|
@@ -26,15 +26,35 @@ aaa
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_multi_line
|
29
|
-
assert_equal [p(
|
29
|
+
assert_equal [p("aaa"), p("bbb")], parse(<<-END)
|
30
30
|
aaa
|
31
31
|
bbb
|
32
32
|
END
|
33
33
|
|
34
|
-
assert_equal [p("aaa"),p(
|
34
|
+
assert_equal [p("aaa"), p("bbb"), Empty.new, p("aaa"), p("bbb")], parse(<<-END)
|
35
35
|
aaa
|
36
|
+
bbb
|
37
|
+
|
38
|
+
|
39
|
+
aaa
|
40
|
+
bbb
|
41
|
+
END
|
42
|
+
|
43
|
+
assert_equal [p("aaa"),Empty.new, p('bbb')], parse(<<-END)
|
44
|
+
aaa
|
45
|
+
|
36
46
|
|
37
47
|
bbb
|
48
|
+
|
49
|
+
END
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_multi_line2
|
53
|
+
assert_equal [p(" aaa"), p(" bbb"), p(" ccc")], parse(<<-END)
|
54
|
+
aaa
|
55
|
+
|
56
|
+
bbb
|
57
|
+
ccc
|
38
58
|
END
|
39
59
|
end
|
40
60
|
|
data/test/test_pair.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'hparser/parser'
|
3
3
|
require 'hparser/block/quote'
|
4
4
|
require 'hparser/block/pre'
|
@@ -18,6 +18,8 @@ class QuoteTest < Test::Unit::TestCase
|
|
18
18
|
def assert_pair(from,to,klass)
|
19
19
|
assert_equal [P.new([Text.new("#{from}aaa#{to}")])], parse("#{from}aaa#{to}")
|
20
20
|
assert_equal [klass.new([Text.new("aaa")])], parse("#{from}\naaa\n#{to}")
|
21
|
+
assert_equal [klass.new([Text.new("aaa")])], parse("#{from}\r\naaa\r\n#{to}")
|
22
|
+
assert_equal [klass.new([Text.new("aaa")])], parse("#{from}\raaa\r#{to}")
|
21
23
|
assert_equal [klass.new([Text.new("aaa\n\nbbb")])],parse(<<-"END")
|
22
24
|
#{from}
|
23
25
|
aaa
|
@@ -25,13 +27,29 @@ aaa
|
|
25
27
|
bbb
|
26
28
|
#{to}
|
27
29
|
END
|
28
|
-
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
assert_equal [klass.new([Text.new("aaa\n\nbbb")])],parse(<<-"END"), 'pair after space'
|
32
|
+
#{from}
|
33
|
+
aaa
|
34
|
+
|
35
|
+
bbb
|
36
|
+
#{to}
|
37
|
+
END
|
32
38
|
end
|
33
39
|
|
34
40
|
def test_pre
|
35
41
|
assert_pair ">|","|<",Pre
|
42
|
+
|
43
|
+
assert_equal [Pre.new([Text.new(" a ")])],parse(<<-END)
|
44
|
+
>|
|
45
|
+
a
|
46
|
+
|<
|
47
|
+
END
|
48
|
+
|
49
|
+
assert_equal [Pre.new([Text.new("a\n>|")])],parse(<<-END)
|
50
|
+
>|
|
51
|
+
a
|
52
|
+
>|
|
53
|
+
END
|
36
54
|
end
|
37
55
|
end
|
data/test/test_quote.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'hparser/parser'
|
3
|
+
require 'hparser/block/list'
|
4
|
+
|
5
|
+
class QuoteTest < Test::Unit::TestCase
|
6
|
+
include HParser::Block
|
7
|
+
include HParser::Inline
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@parser = HParser::Parser.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse str
|
14
|
+
@parser.parse str
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_quote
|
18
|
+
assert_equal [Quote.new([P.new([Text.new('a')]),P.new([Text.new('b')])])],
|
19
|
+
parse(<<-END.unindent)
|
20
|
+
>>
|
21
|
+
a
|
22
|
+
|
23
|
+
b
|
24
|
+
<<
|
25
|
+
END
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_quote_list
|
29
|
+
assert_equal [Quote.new([Ul.new(Li.new([Text.new('a')]))])],
|
30
|
+
parse(<<-END.unindent)
|
31
|
+
>>
|
32
|
+
-a
|
33
|
+
<<
|
34
|
+
END
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_quote_nesting
|
38
|
+
assert_equal [Quote.new([P.new([Text.new('a')]),
|
39
|
+
Quote.new([P.new([Text.new('b')])])
|
40
|
+
])
|
41
|
+
],
|
42
|
+
parse(<<-END.unindent)
|
43
|
+
>>
|
44
|
+
a
|
45
|
+
>>
|
46
|
+
b
|
47
|
+
<<
|
48
|
+
<<
|
49
|
+
END
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_quote_with_url
|
53
|
+
assert_equal [Quote.new([P.new([Text.new('a')])],
|
54
|
+
Url.new('http://example.com'))],
|
55
|
+
parse(<<-END.unindent)
|
56
|
+
>http://example.com>
|
57
|
+
a
|
58
|
+
<<
|
59
|
+
END
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_quote_unmatch
|
63
|
+
assert_equal [Quote.new([P.new([Text.new('a')])])],
|
64
|
+
parse(<<-END.unindent)
|
65
|
+
>>
|
66
|
+
a
|
67
|
+
END
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'hparser/parser'
|
3
|
+
require 'hparser/block/see_more'
|
4
|
+
class SeeMoreTest < Test::Unit::TestCase
|
5
|
+
include HParser::Block
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@parser = HParser::Parser.new [SeeMore]
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse str
|
12
|
+
@parser.parse str
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_new
|
16
|
+
more = SeeMore.new(false)
|
17
|
+
all = SeeMore.new(true)
|
18
|
+
assert_equal false,more.is_super
|
19
|
+
assert_equal true,all.is_super
|
20
|
+
assert_not_equal more,all
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_parse
|
24
|
+
assert_equal [SeeMore.new(false)], parse("====")
|
25
|
+
assert_equal [SeeMore.new(true)], parse("=====")
|
26
|
+
assert_not_equal [SeeMore.new(false)], parse("====a")
|
27
|
+
end
|
28
|
+
end
|
data/test/test_table.rb
CHANGED
data/test/test_tex.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'hparser/inline/parser'
|
3
|
+
require 'hparser/inline/tex'
|
4
|
+
|
5
|
+
class TexTest < Test::Unit::TestCase
|
6
|
+
include HParser::Inline
|
7
|
+
def setup
|
8
|
+
@parser = Parser.new [Tex]
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse str
|
12
|
+
@parser.parse str
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_new
|
16
|
+
tex = Tex.new("e^{i\pi} = -1")
|
17
|
+
assert_equal "e^{i\pi} = -1", tex.text
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_parse
|
21
|
+
assert_equal [Tex.new("e^{i\pi} = -1")],
|
22
|
+
parse("[tex:e^{i\pi} = -1]")
|
23
|
+
end
|
24
|
+
end
|
data/test/test_text.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'hparser'
|
3
3
|
require 'hparser/text'
|
4
4
|
|
@@ -32,7 +32,7 @@ class TextTest < Test::Unit::TestCase
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_quote
|
35
|
-
assert_text
|
35
|
+
assert_text " foobar\n bar",Quote.new([P.new([Text.new("foobar\nbar")])])
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_dl
|
@@ -62,6 +62,16 @@ END
|
|
62
62
|
Li.new([Text.new('bbb')]))
|
63
63
|
end
|
64
64
|
|
65
|
+
def test_footnote_list
|
66
|
+
assert_text "(*1) text1\n(*2) text2",
|
67
|
+
FootnoteList.new([Footnote.new(1, 'text1'),
|
68
|
+
Footnote.new(2, 'text2')])
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_footnote
|
72
|
+
assert_text "(*1)",Footnote.new(1, 'text1')
|
73
|
+
end
|
74
|
+
|
65
75
|
def th str
|
66
76
|
Th.new [Text.new(str)]
|
67
77
|
end
|
data/test/test_url.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'hparser/inline/parser'
|
3
3
|
require 'hparser/inline/url'
|
4
4
|
|
@@ -12,6 +12,28 @@ class UrlTest < Test::Unit::TestCase
|
|
12
12
|
@parser.parse str
|
13
13
|
end
|
14
14
|
|
15
|
+
def test_new
|
16
|
+
url = Url.new("http://example.com")
|
17
|
+
assert_equal "http://example.com", url.url
|
18
|
+
assert_equal "http://example.com", url.title
|
19
|
+
assert_equal false, url.bookmark
|
20
|
+
|
21
|
+
url = Url.new("http://example.com", "TITLE")
|
22
|
+
assert_equal "http://example.com", url.url
|
23
|
+
assert_equal "TITLE", url.title
|
24
|
+
assert_equal false, url.bookmark
|
25
|
+
|
26
|
+
url = Url.new("http://example.com", "")
|
27
|
+
assert_equal "http://example.com", url.url
|
28
|
+
assert_equal "(undefined)", url.title
|
29
|
+
assert_equal false, url.bookmark
|
30
|
+
|
31
|
+
url = Url.new("http://example.com", "a", true)
|
32
|
+
assert_equal "http://example.com", url.url
|
33
|
+
assert_equal "a", url.title
|
34
|
+
assert_equal true, url.bookmark
|
35
|
+
end
|
36
|
+
|
15
37
|
def test_http
|
16
38
|
assert_equal [Url.new("http://example.com")],parse("http://example.com")
|
17
39
|
end
|
@@ -19,7 +41,8 @@ class UrlTest < Test::Unit::TestCase
|
|
19
41
|
def test_text
|
20
42
|
assert_equal [Text.new("<em>"),Url.new("http://example.com"),Text.new("</em>")],
|
21
43
|
parse("<em>http://example.com</em>")
|
22
|
-
|
44
|
+
assert_equal [Text.new("<em>"),Url.new("http://example.com/?foo=bar&bar=baz"),Text.new("</em>")],
|
45
|
+
parse("<em>http://example.com/?foo=bar&bar=baz</em>")
|
23
46
|
assert_equal [Url.new("http://foo.com"),Text.new(" is dummy")],
|
24
47
|
parse("http://foo.com is dummy")
|
25
48
|
end
|
@@ -31,4 +54,18 @@ class UrlTest < Test::Unit::TestCase
|
|
31
54
|
def test_https
|
32
55
|
assert_equal [Url.new("https://example.com")],parse("https://example.com")
|
33
56
|
end
|
57
|
+
|
58
|
+
def test_bracket
|
59
|
+
assert_equal "b", Url.new("a", "b").title
|
60
|
+
assert_equal [Url.new("http://example.com", "TITLE")],parse("[http://example.com:title=TITLE]")
|
61
|
+
assert_equal [Url.new("http://example.com", "")],parse("[http://example.com:title]")
|
62
|
+
assert_equal [Url.new("http://example.com")],parse("[http://example.com]")
|
63
|
+
assert_equal [Url.new("http://example.com", "", true)],parse("[http://example.com:title:bookmark]")
|
64
|
+
assert_equal [Url.new("http://example.com", "TITLE", true)],parse("[http://example.com:title=TITLE:bookmark]")
|
65
|
+
assert_equal [Url.new("http://example.com", "a:b", true)],parse("[http://example.com:title=a:b:bookmark]")
|
66
|
+
assert_equal [Url.new("http://example.com", "a"),
|
67
|
+
Text.new("b:bookmark]")],
|
68
|
+
parse("[http://example.com:title=a]b:bookmark]")
|
69
|
+
assert_not_equal [Url.new("http://example.com", "a\n")],parse("[http://example.com:title=a\n]")
|
70
|
+
end
|
34
71
|
end
|