Sha256: 1d013f6fd4776723f969081b432fc7a3e40e13084241ec7d8a0f238cc74380f8

Contents?: true

Size: 956 Bytes

Versions: 2

Compression:

Stored size: 956 Bytes

Contents

require "libxml"
require "test/unit"

class TC_XML_XPath < Test::Unit::TestCase
  def setup()
    xp = XML::Parser.new()
    str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
    assert_equal(str, xp.string = str)
    doc = xp.parse
    assert_instance_of(XML::Document, doc)
    @xpt = doc.find('/ruby_array/fixnum')
    assert_instance_of(XML::XPath::Object, @xpt)
  end

  def teardown()
    @xpt = nil
  end

  def test_libxml_xpath_set()
    set = @xpt.set
    assert_instance_of(XML::Node::Set, set)
  end

  def test_ary()
    assert_equal(2,@xpt.length)
    assert_equal("one",@xpt.first.content)
    assert_equal("one",@xpt[0].content)
    assert_equal("two",@xpt[1].content)
    assert_equal("two",@xpt[-1].content)
    assert_equal(nil,@xpt[-3])
    assert_equal(nil,@xpt[2])

    @xpt.inject(%w(one two).reverse) {|m,v|
      assert_equal(m.pop,v.content)
      m
    }
  end
end # TC_XML_Document

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
libxml-ruby-0.5.3 test/tc_xml_xpath.rb
libxml-ruby-0.5.4 test/tc_xml_xpath.rb