Sha256: 0c5e07c5d60fc12835f9a53a7518f16086a2bfce3acf21edbf5d570f1cb91ee3

Contents?: true

Size: 1.67 KB

Versions: 19

Compression:

Stored size: 1.67 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))

module Nokogiri
  module XML
    class TestRelaxNG < Nokogiri::TestCase
      def setup
        assert @schema = Nokogiri::XML::RelaxNG(File.read(ADDRESS_SCHEMA_FILE))
      end

      def test_parse_with_memory
        assert_instance_of Nokogiri::XML::RelaxNG, @schema
        assert_equal 0, @schema.errors.length
      end

      def test_new
        assert schema = Nokogiri::XML::RelaxNG.new(
          File.read(ADDRESS_SCHEMA_FILE))
        assert_instance_of Nokogiri::XML::RelaxNG, schema
      end

      def test_parse_with_io
        xsd = nil
        File.open(ADDRESS_SCHEMA_FILE, 'rb') { |f|
          assert xsd = Nokogiri::XML::RelaxNG(f)
        }
        assert_equal 0, xsd.errors.length
      end

      def test_parse_with_errors
        xml = File.read(ADDRESS_SCHEMA_FILE).sub(/name="/, 'name=')
        assert_raises(Nokogiri::XML::SyntaxError) {
          Nokogiri::XML::RelaxNG(xml)
        }
      end

      def test_validate_document
        doc = Nokogiri::XML(File.read(ADDRESS_XML_FILE))
        assert errors = @schema.validate(doc)
        assert_equal 0, errors.length
      end

      def test_validate_invalid_document
        # Empty address book is not allowed
        read_doc = '<addressBook></addressBook>'

        assert errors = @schema.validate(Nokogiri::XML(read_doc))
        assert_equal 1, errors.length
      end

      def test_valid?
        valid_doc = Nokogiri::XML(File.read(ADDRESS_XML_FILE))

        invalid_doc = Nokogiri::XML('<addressBook></addressBook>')

        assert(@schema.valid?(valid_doc))
        assert(!@schema.valid?(invalid_doc))
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
akamai_bookmarklet-0.1.2 vendor/gems/ruby/1.8/gems/nokogiri-1.3.3/test/xml/test_relax_ng.rb
akamai_bookmarklet-0.1.1 vendor/gems/ruby/1.8/gems/nokogiri-1.3.3/test/xml/test_relax_ng.rb
akamai_bookmarklet-0.1.0 vendor/gems/ruby/1.8/gems/nokogiri-1.3.3/test/xml/test_relax_ng.rb
nokogiri-1.3.3-x86-mswin32 test/xml/test_relax_ng.rb
nokogiri-1.3.3-x86-mingw32 test/xml/test_relax_ng.rb
nokogiri-1.3.3-java test/xml/test_relax_ng.rb
nokogiri-1.3.2-x86-mswin32 test/xml/test_relax_ng.rb
nokogiri-1.3.2-x86-mingw32 test/xml/test_relax_ng.rb
nokogiri-1.3.2-java test/xml/test_relax_ng.rb
nokogiri-1.3.0-x86-mingw32 test/xml/test_relax_ng.rb
nokogiri-1.3.2 test/xml/test_relax_ng.rb
nokogiri-1.3.3 test/xml/test_relax_ng.rb
nokogiri-1.3.0-java test/xml/test_relax_ng.rb
nokogiri-1.3.1-java test/xml/test_relax_ng.rb
nokogiri-1.3.0 test/xml/test_relax_ng.rb
nokogiri-1.3.1-x86-mingw32 test/xml/test_relax_ng.rb
nokogiri-1.3.0-x86-mswin32 test/xml/test_relax_ng.rb
nokogiri-1.3.1 test/xml/test_relax_ng.rb
nokogiri-1.3.1-x86-mswin32 test/xml/test_relax_ng.rb