File: test_node_copy.rb

package info (click to toggle)
ruby-libxml 5.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,800 kB
  • sloc: xml: 18,263; ansic: 7,669; ruby: 5,809; makefile: 6
file content (40 lines) | stat: -rw-r--r-- 902 bytes parent folder | download | duplicates (4)
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
# encoding: UTF-8

require_relative './test_helper'

# see mailing list archive
# [libxml-devel] Segmentation fault when add the cloned/copied node
# 2007/11/27 20:51

class TestNodeCopy < Minitest::Test
  def setup
    str = <<-STR
      <html><body>
        <div class="textarea" id="t1" style="STATIC">foo</div>
        <div class="textarea" id="t2" style="STATIC">bar</div>
      </body></html>
    STR

    doc = LibXML::XML::Parser.string(str).parse

    xpath = "//div"
    @div1 = doc.find(xpath).to_a[0]
    @div2 = doc.find(xpath).to_a[1]
  end

  def test_libxml_node_copy_not_segv
    @div2.each do |child|
      c = child.copy(false)
      @div1 << c
    end
    assert @div1.to_s =~ /foo/
  end

  def test_libxml_node_clone_not_segv
    @div2.each do |child|
      c = child.clone
      @div1 << c
    end
    assert @div1.to_s =~ /foo/
  end
end