Sha256: b5205c5e4125c8375dc089695be82d46001bec136705175f8133f31cabbe2a5b

Contents?: true

Size: 1.16 KB

Versions: 301

Compression:

Stored size: 1.16 KB

Contents

require "helper"

module Nokogiri
  module XML
    class TestCDATA < Nokogiri::TestCase
      def setup
        super
        @xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
      end

      def test_cdata_node
        name = @xml.xpath('//employee[2]/name').first
        assert cdata = name.children[1]
        assert cdata.cdata?
        assert_equal '#cdata-section', cdata.name
      end

      def test_new
        node = CDATA.new(@xml, "foo")
        assert_equal "foo", node.content

        node = CDATA.new(@xml.root, "foo")
        assert_equal "foo", node.content
      end

      def test_new_with_nil
        node = CDATA.new(@xml, nil)
        assert_equal nil, node.content
      end

      def test_lots_of_new_cdata
        assert 100.times { CDATA.new(@xml, "asdfasdf") }
      end

      def test_content=
        node = CDATA.new(@xml, 'foo')
        assert_equal('foo', node.content)

        node.content = '& <foo> &amp;'
        assert_equal('& <foo> &amp;', node.content)
        assert_equal('<![CDATA[& <foo> &amp;]]>', node.to_xml)

        node.content = 'foo ]]> bar'
        assert_equal('foo ]]> bar', node.content)
      end
    end
  end
end

Version data entries

301 entries across 296 versions & 24 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/nokogiri-1.7.1/test/xml/test_cdata.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/nokogiri-1.7.1/test/xml/test_cdata.rb
tdiary-5.0.5 vendor/bundle/gems/nokogiri-1.8.0/test/xml/test_cdata.rb
nokogiri-1.8.0 test/xml/test_cdata.rb
nokogiri-1.8.0-x86-mingw32 test/xml/test_cdata.rb
nokogiri-1.8.0-x64-mingw32 test/xml/test_cdata.rb
nokogiri-1.8.0-java test/xml/test_cdata.rb
nokogiri-1.7.2 test/xml/test_cdata.rb
nokogiri-1.7.2-x86-mingw32 test/xml/test_cdata.rb
nokogiri-1.7.2-x64-mingw32 test/xml/test_cdata.rb
nokogiri-1.7.2-java test/xml/test_cdata.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/nokogiri-1.7.1/test/xml/test_cdata.rb
tdiary-5.0.4 vendor/bundle/gems/nokogiri-1.7.1/test/xml/test_cdata.rb
nokogiri-1.7.1 test/xml/test_cdata.rb
nokogiri-1.7.1-x86-mingw32 test/xml/test_cdata.rb
nokogiri-1.7.1-x64-mingw32 test/xml/test_cdata.rb
nokogiri-1.7.1-java test/xml/test_cdata.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.0.1/test/xml/test_cdata.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.0.1/test/xml/test_cdata.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.0.1/test/xml/test_cdata.rb