Sha256: 93e9801af292da5ef100f8ca2567ce8ad5e44ccaaf8ad9b4b8dc6a6fcde3555d

Contents?: true

Size: 1.85 KB

Versions: 45

Compression:

Stored size: 1.85 KB

Contents

require "helper"

module Nokogiri
  module XML
    class TestNamespace < Nokogiri::TestCase
      def setup
        super
        @xml = Nokogiri::XML <<-eoxml
          <root xmlns="http://tenderlovemaking.com/" xmlns:foo="bar">
            <awesome/>
          </root>
        eoxml
      end

      def test_built_nodes_keep_namespace_decls
        doc = Document.new
        e   = Node.new 'element', doc
        c   = Node.new 'child', doc
        c.default_namespace = 'woop:de:doo'

        assert c.namespace, 'has a namespace'
        e.add_child c
        assert c.namespace, 'has a namespace'

        doc.add_child e
        assert c.namespace, 'has a namespace'
      end

      def test_inspect
        ns = @xml.root.namespace
        assert_equal "#<#{ns.class.name}:#{sprintf("0x%x", ns.object_id)} href=#{ns.href.inspect}>", ns.inspect
      end

      def test_namespace_is_in_node_cache
        node = @xml.root.namespace
        assert @xml.instance_variable_get(:@node_cache).include?(node)
      end

      def test_namespace_node_prefix
        namespaces = @xml.root.namespace_definitions
        assert_equal [nil, 'foo'], namespaces.map { |x| x.prefix }
      end

      def test_namespace_node_href
        namespaces = @xml.root.namespace_definitions
        assert_equal [
          'http://tenderlovemaking.com/',
          'bar'
        ], namespaces.map { |x| x.href }
      end

      def test_equality
        namespaces = @xml.root.namespace_definitions
        assert_equal namespaces, @xml.root.namespace_definitions
      end

      def test_add_definition
        @xml.root.add_namespace_definition('baz', 'bar')
        assert_equal 3, @xml.root.namespace_definitions.length
      end

      def test_add_definition_return
        ns = @xml.root.add_namespace_definition('baz', 'bar')
        assert_equal 'baz', ns.prefix
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 7 rubygems

Version Path
caring-nokogiri-1.4.1.pre1 test/xml/test_namespace.rb
nokogiri-1.4.0-java test/xml/test_namespace.rb
nokogiri-1.4.0-x86-mswin32 test/xml/test_namespace.rb
nokogiri-1.4.0-x86-mingw32 test/xml/test_namespace.rb
nokogiri-1.4.0 test/xml/test_namespace.rb