Sha256: c7fe147845ace9487843748debd296b8973b0e98d4396f091e776c4f5442623a

Contents?: true

Size: 1.2 KB

Versions: 60

Compression:

Stored size: 1.2 KB

Contents

require 'test_helper'

class TestNode < Minitest::Test
  # These tests are somewhat fragile. It would be better to allocate lots
  # of memory after a GC run to make sure that potentially freed memory
  # isn't valid by accident.

  def test_drop_parent_reference
    doc = CommonMarker.render_doc('Hi *there*')
    text = doc.first_child.last_child.first_child
    doc = nil
    GC.start
    # Test that doc has not been freed.
    assert_equal "there", text.string_content
  end

  def test_drop_child_reference
    doc = CommonMarker.render_doc('Hi *there*')
    text = doc.first_child.last_child.first_child
    text = nil
    GC.start
    # Test that the cached child object is still valid.
    text = doc.first_child.last_child.first_child
    assert_equal "there", text.string_content
  end

  def test_remove_parent
    doc = CommonMarker.render_doc('Hi *there*')
    para = doc.first_child
    para.delete
    doc = nil
    para = nil
    # TODO: Test that the `para` node was actually freed after unlinking.
  end

  def test_add_parent
    doc = Node.new(:document)
    hrule = Node.new(:hrule)
    doc.append_child(hrule)
    # If the hrule node was erroneously freed, this would result in a double
    # free.
  end
end

Version data entries

60 entries across 60 versions & 2 rubygems

Version Path
commonmarker-0.16.6 test/test_gc.rb
commonmarker-0.16.5 test/test_gc.rb
commonmarker-0.16.4 test/test_gc.rb
commonmarker-0.16.1 test/test_gc.rb
commonmarker-0.16.2 test/test_gc.rb
commonmarker-0.16.3 test/test_gc.rb
commonmarker-0.16.0 test/test_gc.rb
commonmarker-0.15.0 test/test_gc.rb
commonmarker-0.14.15 test/test_gc.rb
commonmarker-0.14.14 test/test_gc.rb
commonmarker-0.14.13 test/test_gc.rb
commonmarker-0.14.12 test/test_gc.rb
commonmarker-0.14.11 test/test_gc.rb
commonmarker-0.14.9 test/test_gc.rb
commonmarker-0.14.8 test/test_gc.rb
commonmarker-0.14.7 test/test_gc.rb
commonmarker-0.14.6 test/test_gc.rb
commonmarker-0.14.5 test/test_gc.rb
commonmarker-0.14.4 test/test_gc.rb
commonmarker-0.14.3 test/test_gc.rb