80 |
80 |
assert_equal '<p>This is a <a href="/issues">link</a></p>', @formatter.new(text).to_html.strip
|
81 |
81 |
end
|
82 |
82 |
|
|
83 |
STR_WITH_PRE = [
|
|
84 |
# 0
|
|
85 |
"# Title
|
|
86 |
|
|
87 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.",
|
|
88 |
# 1
|
|
89 |
"## Heading 2
|
|
90 |
|
|
91 |
~~~ruby
|
|
92 |
def foo
|
|
93 |
end
|
|
94 |
~~~
|
|
95 |
|
|
96 |
Morbi facilisis accumsan orci non pharetra.
|
|
97 |
|
|
98 |
```
|
|
99 |
Pre Content:
|
|
100 |
|
|
101 |
## Inside pre
|
|
102 |
|
|
103 |
<tag> inside pre block
|
|
104 |
|
|
105 |
Morbi facilisis accumsan orci non pharetra.
|
|
106 |
```",
|
|
107 |
# 2
|
|
108 |
"### Heading 3
|
|
109 |
|
|
110 |
Nulla nunc nisi, egestas in ornare vel, posuere ac libero."]
|
|
111 |
|
|
112 |
def test_get_section_should_ignore_pre_content
|
|
113 |
text = STR_WITH_PRE.join("\n\n")
|
|
114 |
|
|
115 |
assert_section_with_hash STR_WITH_PRE[1..2].join("\n\n"), text, 2
|
|
116 |
assert_section_with_hash STR_WITH_PRE[2], text, 3
|
|
117 |
end
|
|
118 |
|
|
119 |
def test_update_section_should_not_escape_pre_content_outside_section
|
|
120 |
text = STR_WITH_PRE.join("\n\n")
|
|
121 |
replacement = "New text"
|
|
122 |
|
|
123 |
assert_equal [STR_WITH_PRE[0..1], "New text"].flatten.join("\n\n"),
|
|
124 |
@formatter.new(text).update_section(3, replacement)
|
|
125 |
end
|
|
126 |
|
|
127 |
private
|
|
128 |
|
|
129 |
def assert_section_with_hash(expected, text, index)
|
|
130 |
result = @formatter.new(text).get_section(index)
|
|
131 |
|
|
132 |
assert_kind_of Array, result
|
|
133 |
assert_equal 2, result.size
|
|
134 |
assert_equal expected, result.first, "section content did not match"
|
|
135 |
assert_equal Digest::MD5.hexdigest(expected), result.last, "section hash did not match"
|
|
136 |
end
|
|
137 |
|
83 |
138 |
end
|
84 |
139 |
end
|