forked from jekyll/jekyll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_tags.rb
175 lines (139 loc) · 4.75 KB
/
test_tags.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# coding: utf-8
require 'helper'
class TestTags < Test::Unit::TestCase
def create_post(content, override = {}, converter_class = Jekyll::MarkdownConverter)
stub(Jekyll).configuration do
Jekyll::DEFAULTS.merge({'pygments' => true}).merge(override)
end
site = Site.new(Jekyll.configuration)
info = { :filters => [Jekyll::Filters], :registers => { :site => site } }
@converter = site.converters.find { |c| c.class == converter_class }
payload = { "pygments_prefix" => @converter.pygments_prefix,
"pygments_suffix" => @converter.pygments_suffix }
@result = Liquid::Template.parse(content).render(payload, info)
@result = @converter.convert(@result)
end
def fill_post(code, override = {})
content = <<CONTENT
---
title: This is a test
---
This document results in a markdown error with maruku
{% highlight text %}#{code}{% endhighlight %}
CONTENT
create_post(content, override)
end
context "language name" do
should "match only the required set of chars" do
r = Jekyll::HighlightBlock::SYNTAX
assert_match r, "ruby"
assert_match r, "c#"
assert_match r, "xml+cheetah"
assert_match r, "x.y"
assert_match r, "coffee-script"
assert_no_match r, "blah^"
assert_match r, "ruby key=val"
assert_match r, "ruby a=b c=d"
end
end
context "initialized tag" do
should "work" do
tag = Jekyll::HighlightBlock.new('highlight', 'ruby ', ["test", "{% endhighlight %}", "\n"])
assert_equal({}, tag.instance_variable_get(:@options))
tag = Jekyll::HighlightBlock.new('highlight', 'ruby linenos ', ["test", "{% endhighlight %}", "\n"])
assert_equal({'O' => "linenos=inline"}, tag.instance_variable_get(:@options))
tag = Jekyll::HighlightBlock.new('highlight', 'ruby linenos=table ', ["test", "{% endhighlight %}", "\n"])
assert_equal({'O' => "linenos=table"}, tag.instance_variable_get(:@options))
tag = Jekyll::HighlightBlock.new('highlight', 'ruby linenos=table nowrap', ["test", "{% endhighlight %}", "\n"])
assert_equal({'O' => "linenos=table,nowrap=true"}, tag.instance_variable_get(:@options))
tag = Jekyll::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl', ["test", "{% endhighlight %}", "\n"])
assert_equal({'O' => "cssclass=hl,linenos=table"}, tag.instance_variable_get(:@options))
end
end
context "post content has highlight tag" do
setup do
fill_post("test")
end
should "not cause a markdown error" do
assert_no_match /markdown\-html\-error/, @result
end
should "render markdown with pygments line handling" do
assert_match %{<pre><code class='text'>test\n</code></pre>}, @result
end
end
context "post content has highlight with file reference" do
setup do
fill_post("./jekyll.gemspec")
end
should "not embed the file" do
assert_match %{<pre><code class='text'>./jekyll.gemspec\n</code></pre>}, @result
end
end
context "post content has highlight tag with UTF character" do
setup do
fill_post("Æ")
end
should "render markdown with pygments line handling" do
assert_match %{<pre><code class='text'>Æ\n</code></pre>}, @result
end
end
context "simple post with markdown and pre tags" do
setup do
@content = <<CONTENT
---
title: Maruku vs. RDiscount
---
_FIGHT!_
{% highlight ruby %}
puts "3..2..1.."
{% endhighlight %}
*FINISH HIM*
CONTENT
end
context "using Textile" do
setup do
create_post(@content, {}, Jekyll::TextileConverter)
end
# Broken in RedCloth 4.1.9
should "not textilize highlight block" do
assert_no_match %r{3\.\.2\.\.1\.\."</span><br />}, @result
end
end
context "using Maruku" do
setup do
create_post(@content)
end
should "parse correctly" do
assert_match %r{<em>FIGHT!</em>}, @result
assert_match %r{<em>FINISH HIM</em>}, @result
end
end
context "using RDiscount" do
setup do
create_post(@content, 'markdown' => 'rdiscount')
end
should "parse correctly" do
assert_match %r{<em>FIGHT!</em>}, @result
assert_match %r{<em>FINISH HIM</em>}, @result
end
end
context "using Kramdown" do
setup do
create_post(@content, 'markdown' => 'kramdown')
end
should "parse correctly" do
assert_match %r{<em>FIGHT!</em>}, @result
assert_match %r{<em>FINISH HIM</em>}, @result
end
end
context "using Redcarpet" do
setup do
create_post(@content, 'markdown' => 'redcarpet')
end
should "parse correctly" do
assert_match %r{<em>FIGHT!</em>}, @result
assert_match %r{<em>FINISH HIM</em>}, @result
end
end
end
end