# frozen_string_literal: true require 'test_helper' class TestDocNode < Minitest::Test def setup @doc = CommonMarker.render_doc('Hi *there*. This has __many nodes__!') @first_child = @doc.first_child @last_child = @doc.last_child @link = CommonMarker.render_doc('[GitHub](https://www.github.com)').first_child.first_child @image = CommonMarker.render_doc('![alt text](https://github.com/favicon.ico "Favicon")') @image = @image.first_child.first_child @header = CommonMarker.render_doc('### Header Three').first_child @ul_list = CommonMarker.render_doc("* Bullet\n*Bullet").first_child @ol_list = CommonMarker.render_doc("1. One\n2. Two").first_child @fence = CommonMarker.render_doc("``` ruby\nputs 'wow'\n```").first_child end def test_get_type assert_equal @doc.type, :document end def test_get_type_string assert_equal @doc.type_string, 'document' end def test_get_first_child assert_equal @first_child.type, :paragraph end def test_get_next assert_equal @first_child.first_child.next.type, :emph end def test_insert_before paragraph = Node.new(:paragraph) assert_equal @first_child.insert_before(paragraph), true assert_match "
\nHi there.", @doc.to_html end def test_insert_after paragraph = Node.new(:paragraph) assert_equal @first_child.insert_after(paragraph), true assert_match "many nodes!
\n\n", @doc.to_html end def test_prepend_child code = Node.new(:code) assert_equal @first_child.prepend_child(code), true assert_match 'Hi there.', @doc.to_html
end
def test_append_child
strong = Node.new(:strong)
assert_equal @first_child.append_child(strong), true
assert_match "!