-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3cedf6
commit 910e937
Showing
3 changed files
with
69 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require 'test_helper' | ||
|
||
class TestNode < Minitest::Test | ||
def setup | ||
@doc = CommonMarker.render_doc('Hi *there*') | ||
end | ||
|
||
def test_walk | ||
nodes = [] | ||
@doc.walk do |node| | ||
nodes << node.type | ||
end | ||
assert_equal [:document, :paragraph, :text, :emph, :text], nodes | ||
end | ||
|
||
def test_insert_illegal | ||
assert_raises NodeError do | ||
@doc.insert_before(@doc) | ||
end | ||
end | ||
|
||
def test_to_html | ||
assert_equal "<p>Hi <em>there</em></p>\n", @doc.to_html | ||
end | ||
|
||
def test_html_renderer | ||
renderer = HtmlRenderer.new | ||
result = renderer.render(@doc) | ||
assert_equal "<p>Hi <em>there</em></p>\n", result | ||
end | ||
|
||
def test_walk_and_set_string_content | ||
@doc.walk do |node| | ||
if node.type == :text && node.string_content == 'there' | ||
node.string_content = 'world' | ||
assert_equal 'world', node.string_content | ||
end | ||
end | ||
end | ||
|
||
def test_walk_and_delete_node | ||
@doc.walk do |node| | ||
if node.type == :emph | ||
node.insert_before(node.first_child) | ||
node.delete | ||
end | ||
end | ||
assert_equal "<p>Hi there</p>\n", @doc.to_html | ||
end | ||
|
||
def test_markdown_to_html | ||
html = CommonMarker.render_html('Hi *there*') | ||
assert_equal "<p>Hi <em>there</em></p>\n", html | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'test_helper' | ||
|
||
class TestRenderer < Minitest::Test | ||
def setup | ||
@doc = CommonMarker.render_doc('Hi *there*') | ||
end | ||
|
||
def test_html_renderer | ||
renderer = HtmlRenderer.new | ||
result = renderer.render(@doc) | ||
assert_equal "<p>Hi <em>there</em></p>\n", result | ||
end | ||
end |