From 0f20b57dc6b4fcd86ad6e764fde892d42f3add98 Mon Sep 17 00:00:00 2001 From: Radu Preotiuc <49693472+radupr@users.noreply.github.com> Date: Tue, 16 Jul 2019 16:15:28 -0400 Subject: [PATCH 01/18] Initial setup of salsify fork of libxml-ruby (#1) * Initial setup * Modified README file --- .travis.yml | 12 --- Gemfile | 6 +- README.rdoc | 47 ++++----- Rakefile | 6 +- ext/libxml/extconf.rb | 95 +++++++++++-------- ...uby.gemspec => salsify_libxml_ruby.gemspec | 26 +++-- 6 files changed, 93 insertions(+), 99 deletions(-) delete mode 100644 .travis.yml rename libxml-ruby.gemspec => salsify_libxml_ruby.gemspec (67%) diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index cf555e3b..00000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: ruby -sudo: required - -before_install: - - sudo apt-get install -y libxml2-dev - -script: -- rake compile -- rake test - -rvm: - - 2.5.0 diff --git a/Gemfile b/Gemfile index b42b1ad4..623def94 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,7 @@ -source "https://www.rubygems.org" +source 'https://gems.salsify.com' +# override the :github shortcut to be secure by using HTTPS +git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" } + +# Specify your gem's dependencies in salsify_libxml_ruby.gemspec gemspec diff --git a/README.rdoc b/README.rdoc index b72cf69f..4d1b93fe 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,4 +1,23 @@ -= LibXML Ruby += Salsify LibXML Ruby +The libxml_ruby gem provides bindings for libxml library. The Salsify version +of this gem adds static linking to a locally-compiled version of libxml2 +whose version can be set in extconf.rb. This isolates it from changes to the +underlying native library, which follows the model of a much better known +Ruby library binding to libxml2 (Nokogiri) and is especially important in +this case due to the use of bindings to undocumented APIs. + +== SECURITY +The maintainers will periodically provide security updates for libxml, but +YOU SHOULD NOT USE this library in production environments. + +== INSTALLATION +Add a reference to "salsify_libxml_ruby" in your Gemfile. This assumes +that bundler is configured to use https://gems.salisfy.com. + +== Original library +Original README offering more information about this library follows. + +== LibXML Ruby == Overview The libxml gem provides Ruby language bindings for GNOME's Libxml2 @@ -10,32 +29,6 @@ We think libxml-ruby is the best XML library for Ruby because: * Features - It provides an amazing number of featues * Conformance - It passes all 1800+ tests from the OASIS XML Tests Suite -== Requirements -libxml-ruby requires Ruby 1.8.7 or higher. It depends on libxml2 to -function propoerly. libxml2, in turn, depends on: - -* libm (math routines: very standard) -* libz (zlib) -* libiconv - -If you are running Linux or Unix you'll need a C compiler so the -extension can be compiled when it is installed. If you are running -Windows, then install the x64-mingw32 gem or build it yourself using -Devkit (http://rubyinstaller.org/add-ons/devkit/) or -msys2 (https://msys2.github.io/). - -== INSTALLATION -The easiest way to install libxml-ruby is via Ruby Gems. To install: - -gem install libxml-ruby - -If you are running Windows, then install the libxml-ruby-x64-mingw32 gem. -THe gem inncludes prebuilt extensions for Ruby 2.3. These -extensions are built using MinGW64 and libxml2 version 2.9.3, -iconv version 1.14 and zlib version 1.2.8. Note these binaries -are available in the lib\libs directory. To use them, put them -someplace on your path. - The gem also includes a Microsoft VC++ 2012 solution and XCode 5 project - these are very useful for debugging. diff --git a/Rakefile b/Rakefile index f9019155..3221c7f2 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,7 @@ #!/usr/bin/env ruby +require "bundler/gem_tasks" +require "salsify_gem" require "rubygems" require "rake/extensiontask" require "rake/testtask" @@ -7,7 +9,7 @@ require "rubygems/package_task" require "rdoc/task" require "yaml" -GEM_NAME = "libxml-ruby" +GEM_NAME = "salsify_libxml_ruby" SO_NAME = "libxml_ruby" # Read the spec file @@ -88,4 +90,4 @@ Rake::TestTask.new do |t| t.libs << "test" t.test_files = FileList['test/test*.rb'] - ['test/test_suite.rb'] t.verbose = true -end \ No newline at end of file +end diff --git a/ext/libxml/extconf.rb b/ext/libxml/extconf.rb index d047c1d6..ebfbc34c 100644 --- a/ext/libxml/extconf.rb +++ b/ext/libxml/extconf.rb @@ -2,56 +2,67 @@ require 'mkmf' +LIBXML2_VERSION = '2.9.9'.freeze +LIBXML2_SHA256 = '94fb70890143e3c6549f265cee93ec064c80a84c42ad0f23e85ee1fd6540a871'.freeze + +def darwin? + RbConfig::CONFIG['target_os'] =~ /darwin/ +end + def crash(str) - printf(" extconf failure: %s\n", str) + puts(" extconf failure: #{str}") exit 1 end -xc = with_config('xml2-config') -if xc - cflags = `#{xc} --cflags`.chomp - if $? != 0 - cflags = nil - else - libs = `#{xc} --libs`.chomp - if $? != 0 - libs = nil - else - $CFLAGS += ' ' + cflags - $libs = libs + " " + $libs - end - end -else - dir_config('xml2') -end +# The gem version constraint in the Rakefile is not respected at install time. +# Keep this version in sync with the one in the Rakefile ! +require 'rubygems' +gem 'mini_portile2', '~> 2.4.0' +require 'mini_portile2' +message "Using mini_portile version #{MiniPortile::VERSION}\n" -unless find_header('libxml/xmlversion.h', - '/opt/include/libxml2', - '/opt/local/include/libxml2', - '/usr/local/include/libxml2', - '/usr/include/libxml2') && - find_library('xml2', 'xmlParseDoc', - '/opt/lib', - '/opt/local/lib', - '/usr/local/lib', - '/usr/lib') - crash(< Date: Wed, 17 Jul 2019 11:04:33 -0400 Subject: [PATCH 02/18] Fix iconv (#2) * Only require iconv as a separate library on macOS * Incremented gem version --- Gemfile.lock | 27 +++++++++++++++++++++++++++ ext/libxml/extconf.rb | 6 ++++-- ext/libxml/ruby_xml_version.h | 6 +++--- 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..11f9b51c --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,27 @@ +PATH + remote: . + specs: + salsify_libxml_ruby (3.1.0) + +GEM + remote: https://gems.salsify.com/ + specs: + minitest (5.11.3) + rake (12.3.2) + rake-compiler (1.0.7) + rake + salsify_gem (0.3.1) + thor + thor (0.20.3) + +PLATFORMS + ruby + +DEPENDENCIES + minitest + rake-compiler + salsify_gem + salsify_libxml_ruby! + +BUNDLED WITH + 1.17.2 diff --git a/ext/libxml/extconf.rb b/ext/libxml/extconf.rb index ebfbc34c..279d9233 100644 --- a/ext/libxml/extconf.rb +++ b/ext/libxml/extconf.rb @@ -21,9 +21,11 @@ def crash(str) require 'mini_portile2' message "Using mini_portile version #{MiniPortile::VERSION}\n" -!darwin? || have_header('iconv.h') || crash('missing iconv.h') +if darwin? + have_header('iconv.h') || crash('missing iconv.h') + have_library('iconv') || crash('missing libiconv') +end have_library('z', 'gzdopen', 'zlib.h') || crash('missing zlib') -have_library('iconv') || crash('missing libiconv') have_library('lzma') || crash('missing lzma') libxml2_recipe = MiniPortile.new('libxml2', LIBXML2_VERSION) diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h index 02ec80a4..13a6cfb6 100644 --- a/ext/libxml/ruby_xml_version.h +++ b/ext/libxml/ruby_xml_version.h @@ -1,9 +1,9 @@ /* Don't nuke this block! It is used for automatically updating the * versions below. VERSION = string formatting, VERNUM = numbered * version for inline testing: increment both or none at all.*/ -#define RUBY_LIBXML_VERSION "3.1.0" -#define RUBY_LIBXML_VERNUM 310 +#define RUBY_LIBXML_VERSION "3.1.0.1" +#define RUBY_LIBXML_VERNUM 3101 #define RUBY_LIBXML_VER_MAJ 3 #define RUBY_LIBXML_VER_MIN 1 #define RUBY_LIBXML_VER_MIC 0 -#define RUBY_LIBXML_VER_PATCH 0 +#define RUBY_LIBXML_VER_PATCH 1 From 8a7d20de392517f22bab35c8cd714590f5f414fe Mon Sep 17 00:00:00 2001 From: Radu Preotiuc <49693472+radupr@users.noreply.github.com> Date: Wed, 17 Jul 2019 11:27:06 -0400 Subject: [PATCH 03/18] Deleted Gemfile.lock - added by mistake in previous commit (#3) --- Gemfile.lock | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 11f9b51c..00000000 --- a/Gemfile.lock +++ /dev/null @@ -1,27 +0,0 @@ -PATH - remote: . - specs: - salsify_libxml_ruby (3.1.0) - -GEM - remote: https://gems.salsify.com/ - specs: - minitest (5.11.3) - rake (12.3.2) - rake-compiler (1.0.7) - rake - salsify_gem (0.3.1) - thor - thor (0.20.3) - -PLATFORMS - ruby - -DEPENDENCIES - minitest - rake-compiler - salsify_gem - salsify_libxml_ruby! - -BUNDLED WITH - 1.17.2 From a27dfb1d910ea3d5248a192582f471a45b76e45d Mon Sep 17 00:00:00 2001 From: Radu Preotiuc <49693472+radupr@users.noreply.github.com> Date: Wed, 17 Jul 2019 11:55:56 -0400 Subject: [PATCH 04/18] Correctly pass compilation flags that are needed on Linux (#4) * Correctly pass compilation flags neede on Linux * Removed annnoying Gemfile.lock --- ext/libxml/extconf.rb | 2 +- ext/libxml/ruby_xml_version.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/libxml/extconf.rb b/ext/libxml/extconf.rb index 279d9233..ea300f15 100644 --- a/ext/libxml/extconf.rb +++ b/ext/libxml/extconf.rb @@ -48,7 +48,7 @@ def crash(str) "--with-iconv", *(darwin? ? ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"] : "") ] -append_cflags('-fPIC') +env['CFLAGS'] = "-fPIC #{env['CFLAGS']}" message "Building with libxml2-#{LIBXML2_VERSION}" diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h index 13a6cfb6..2bc71526 100644 --- a/ext/libxml/ruby_xml_version.h +++ b/ext/libxml/ruby_xml_version.h @@ -1,9 +1,9 @@ /* Don't nuke this block! It is used for automatically updating the * versions below. VERSION = string formatting, VERNUM = numbered * version for inline testing: increment both or none at all.*/ -#define RUBY_LIBXML_VERSION "3.1.0.1" -#define RUBY_LIBXML_VERNUM 3101 +#define RUBY_LIBXML_VERSION "3.1.0.2" +#define RUBY_LIBXML_VERNUM 3102 #define RUBY_LIBXML_VER_MAJ 3 #define RUBY_LIBXML_VER_MIN 1 #define RUBY_LIBXML_VER_MIC 0 -#define RUBY_LIBXML_VER_PATCH 1 +#define RUBY_LIBXML_VER_PATCH 2 From 6b536434d507b9055f2fa8245a1057e9c03934f1 Mon Sep 17 00:00:00 2001 From: Radu Preotiuc <49693472+radupr@users.noreply.github.com> Date: Wed, 17 Jul 2019 12:15:21 -0400 Subject: [PATCH 05/18] Fix access to environment variable (#5) --- ext/libxml/extconf.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/libxml/extconf.rb b/ext/libxml/extconf.rb index ea300f15..833fc63d 100644 --- a/ext/libxml/extconf.rb +++ b/ext/libxml/extconf.rb @@ -48,7 +48,7 @@ def crash(str) "--with-iconv", *(darwin? ? ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"] : "") ] -env['CFLAGS'] = "-fPIC #{env['CFLAGS']}" +ENV['CFLAGS'] = "-fPIC #{ENV['CFLAGS']}" message "Building with libxml2-#{LIBXML2_VERSION}" From 244afe10a15008cedaa8aedb6855b2415703bf49 Mon Sep 17 00:00:00 2001 From: Radu Preotiuc Date: Wed, 17 Jul 2019 12:17:23 -0400 Subject: [PATCH 06/18] Incremented version number --- ext/libxml/ruby_xml_version.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h index 2bc71526..adf8171f 100644 --- a/ext/libxml/ruby_xml_version.h +++ b/ext/libxml/ruby_xml_version.h @@ -1,9 +1,9 @@ /* Don't nuke this block! It is used for automatically updating the * versions below. VERSION = string formatting, VERNUM = numbered * version for inline testing: increment both or none at all.*/ -#define RUBY_LIBXML_VERSION "3.1.0.2" -#define RUBY_LIBXML_VERNUM 3102 +#define RUBY_LIBXML_VERSION "3.1.0.3" +#define RUBY_LIBXML_VERNUM 3103 #define RUBY_LIBXML_VER_MAJ 3 #define RUBY_LIBXML_VER_MIN 1 #define RUBY_LIBXML_VER_MIC 0 -#define RUBY_LIBXML_VER_PATCH 2 +#define RUBY_LIBXML_VER_PATCH 3 From 9a9c8273e4ab5369c6bd0a6a50c2532a7e8818c7 Mon Sep 17 00:00:00 2001 From: Radu Preotiuc Date: Fri, 26 Jul 2019 15:27:21 -0400 Subject: [PATCH 07/18] Fixed field names in Schema::Element. --- lib/libxml/schema/element.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libxml/schema/element.rb b/lib/libxml/schema/element.rb index 889d6252..fadf517f 100644 --- a/lib/libxml/schema/element.rb +++ b/lib/libxml/schema/element.rb @@ -4,11 +4,11 @@ module LibXML module XML class Schema::Element def required? - !min_occurs.zero? + !min.zero? end def array? - max_occurs > 1 + max > 1 end def elements From 159be3f61f4de47fbc145ade88778ac0563284cf Mon Sep 17 00:00:00 2001 From: Radu Preotiuc Date: Fri, 26 Jul 2019 15:30:47 -0400 Subject: [PATCH 08/18] Fixed field names in Schema::Element. --- ext/libxml/ruby_xml_version.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h index adf8171f..74760f9d 100644 --- a/ext/libxml/ruby_xml_version.h +++ b/ext/libxml/ruby_xml_version.h @@ -1,9 +1,9 @@ /* Don't nuke this block! It is used for automatically updating the * versions below. VERSION = string formatting, VERNUM = numbered * version for inline testing: increment both or none at all.*/ -#define RUBY_LIBXML_VERSION "3.1.0.3" -#define RUBY_LIBXML_VERNUM 3103 +#define RUBY_LIBXML_VERSION "3.1.0.4" +#define RUBY_LIBXML_VERNUM 3104 #define RUBY_LIBXML_VER_MAJ 3 #define RUBY_LIBXML_VER_MIN 1 #define RUBY_LIBXML_VER_MIC 0 -#define RUBY_LIBXML_VER_PATCH 3 +#define RUBY_LIBXML_VER_PATCH 4 From 98bc20a792a8d980ff6e23fa8f1c458e215ad8d3 Mon Sep 17 00:00:00 2001 From: Radu Preotiuc Date: Fri, 26 Jul 2019 15:40:15 -0400 Subject: [PATCH 09/18] Fixed field names in Schema::Element. --- ext/libxml/ruby_xml_version.h | 6 +++--- lib/libxml/schema/element.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h index 74760f9d..b05fb8c0 100644 --- a/ext/libxml/ruby_xml_version.h +++ b/ext/libxml/ruby_xml_version.h @@ -1,9 +1,9 @@ /* Don't nuke this block! It is used for automatically updating the * versions below. VERSION = string formatting, VERNUM = numbered * version for inline testing: increment both or none at all.*/ -#define RUBY_LIBXML_VERSION "3.1.0.4" -#define RUBY_LIBXML_VERNUM 3104 +#define RUBY_LIBXML_VERSION "3.1.0.5" +#define RUBY_LIBXML_VERNUM 3105 #define RUBY_LIBXML_VER_MAJ 3 #define RUBY_LIBXML_VER_MIN 1 #define RUBY_LIBXML_VER_MIC 0 -#define RUBY_LIBXML_VER_PATCH 4 +#define RUBY_LIBXML_VER_PATCH 5 diff --git a/lib/libxml/schema/element.rb b/lib/libxml/schema/element.rb index fadf517f..74b3acce 100644 --- a/lib/libxml/schema/element.rb +++ b/lib/libxml/schema/element.rb @@ -4,11 +4,11 @@ module LibXML module XML class Schema::Element def required? - !min.zero? + !@min.zero? end def array? - max > 1 + @max > 1 end def elements From 181467290bdaaa7844a6952c59b3fa2d34c040ac Mon Sep 17 00:00:00 2001 From: Radu Preotiuc Date: Mon, 5 Aug 2019 11:12:51 -0400 Subject: [PATCH 10/18] One more fix for the max/minOccurs issue --- ext/libxml/ruby_xml_version.h | 6 +++--- lib/libxml/schema/element.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h index b05fb8c0..b487b020 100644 --- a/ext/libxml/ruby_xml_version.h +++ b/ext/libxml/ruby_xml_version.h @@ -1,9 +1,9 @@ /* Don't nuke this block! It is used for automatically updating the * versions below. VERSION = string formatting, VERNUM = numbered * version for inline testing: increment both or none at all.*/ -#define RUBY_LIBXML_VERSION "3.1.0.5" -#define RUBY_LIBXML_VERNUM 3105 +#define RUBY_LIBXML_VERSION "3.1.0.6" +#define RUBY_LIBXML_VERNUM 3106 #define RUBY_LIBXML_VER_MAJ 3 #define RUBY_LIBXML_VER_MIN 1 #define RUBY_LIBXML_VER_MIC 0 -#define RUBY_LIBXML_VER_PATCH 5 +#define RUBY_LIBXML_VER_PATCH 6 diff --git a/lib/libxml/schema/element.rb b/lib/libxml/schema/element.rb index 74b3acce..a295b6fb 100644 --- a/lib/libxml/schema/element.rb +++ b/lib/libxml/schema/element.rb @@ -4,11 +4,11 @@ module LibXML module XML class Schema::Element def required? - !@min.zero? + !@min || !@min.zero? end def array? - @max > 1 + @max && @max > 1 end def elements From 6b6bae3cf4d732a5b53e516301706a96e464ccc4 Mon Sep 17 00:00:00 2001 From: Radu Preotiuc <49693472+radupr@users.noreply.github.com> Date: Mon, 26 Apr 2021 20:45:09 -0400 Subject: [PATCH 11/18] Merged changes. (#6) --- HISTORY | 13 + README.rdoc | 56 ++-- ext/libxml/extconf.rb | 1 - ext/libxml/ruby_libxml.h | 8 - ext/libxml/ruby_xml_document.c | 6 +- ext/libxml/ruby_xml_dtd.c | 14 +- ext/libxml/ruby_xml_encoding.c | 14 +- ext/libxml/ruby_xml_encoding.h | 3 - ext/libxml/ruby_xml_io.c | 32 +-- ext/libxml/ruby_xml_io.h | 2 +- ext/libxml/ruby_xml_node.c | 2 +- ext/libxml/ruby_xml_parser_context.c | 2 +- ext/libxml/ruby_xml_version.h | 10 +- ext/libxml/ruby_xml_writer.c | 381 ++++++++++++------------- ext/vc/libxml_ruby/libxml_ruby.vcxproj | 18 +- lib/libxml-ruby.rb | 30 ++ lib/libxml.rb | 31 +- salsify_libxml_ruby.gemspec | 3 +- test/test_attr.rb | 36 +-- test/test_attr_decl.rb | 16 +- test/test_attributes.rb | 20 +- test/test_canonicalize.rb | 40 ++- test/test_deprecated_require.rb | 6 +- test/test_document.rb | 50 ++-- test/test_document_write.rb | 127 +++------ test/test_dtd.rb | 46 +-- test/test_encoding.rb | 30 +- test/test_encoding_sax.rb | 6 +- test/test_error.rb | 102 +++---- test/test_helper.rb | 11 +- test/test_html_parser.rb | 60 ++-- test/test_html_parser_context.rb | 12 +- test/test_namespace.rb | 32 +-- test/test_namespaces.rb | 50 ++-- test/test_node.rb | 62 ++-- test/test_node_cdata.rb | 20 +- test/test_node_comment.rb | 12 +- test/test_node_copy.rb | 4 +- test/test_node_edit.rb | 32 +-- test/test_node_pi.rb | 14 +- test/test_node_text.rb | 12 +- test/test_node_write.rb | 42 ++- test/test_node_xlink.rb | 12 +- test/test_parser.rb | 138 +++++---- test/test_parser_context.rb | 60 ++-- test/test_properties.rb | 10 +- test/test_reader.rb | 165 ++++++----- test/test_relaxng.rb | 22 +- test/test_sax_parser.rb | 56 ++-- test/test_schema.rb | 48 ++-- test/test_suite.rb | 7 +- test/test_traversal.rb | 8 +- test/test_writer.rb | 169 ++++++----- test/test_xinclude.rb | 6 +- test/test_xml.rb | 214 +++++++------- test/test_xpath.rb | 44 +-- test/test_xpath_context.rb | 10 +- test/test_xpath_expression.rb | 12 +- test/test_xpointer.rb | 30 +- 59 files changed, 1200 insertions(+), 1279 deletions(-) create mode 100644 lib/libxml-ruby.rb diff --git a/HISTORY b/HISTORY index 75ce02f6..01add45b 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,18 @@ = Release History +== 3.2.1 / 2020-11-05 + +* Fix incorrect handling of encodings when using XMLWriter.io (Charlie Savage) +* Clean up README (Richard Michael) + +== 3.2.0 / 2020-05-09 Charlie Savage + +* Fix crash when creating an empty DTD +* Modernize tests to use Bundler to load gem +* Add libxml-ruby.rb file so gem loads in expected way. +* Add support for xmlSaveNoEmptyTags. +* Clean up extconf.rb file + == 3.1.0 / 2018-02-03 Charlie Savage * Fix segmentation fault when adding one node to another node (Charlie Savage) diff --git a/README.rdoc b/README.rdoc index 4d1b93fe..f4cf5869 100644 --- a/README.rdoc +++ b/README.rdoc @@ -32,7 +32,7 @@ We think libxml-ruby is the best XML library for Ruby because: The gem also includes a Microsoft VC++ 2012 solution and XCode 5 project - these are very useful for debugging. -libxml-ruby's source codes lives on Github at https://github.com/xml4r/libxml-ruby. +libxml-ruby's source codes lives on GitHub[https://github.com/xml4r/libxml-ruby]. == Getting Started Using libxml is easy. First decide what parser you want to use: @@ -53,7 +53,7 @@ Beyond the basics of parsing and processing XML and HTML documents, libxml provides a wealth of additional functionality. Most commonly, you'll want to use its LibXML::XML::XPath support, which makes -it easy to find data inside a XML document. Although not as popular, +it easy to find data inside an XML document. Although not as popular, LibXML::XML::XPointer provides another API for finding data inside an XML document. Often times you'll need to validate data before processing it. For example, @@ -65,17 +65,16 @@ This can be done using libxml's powerful set of validators: * Relax Schemas (LibXML::XML::RelaxNG) * XML Schema (LibXML::XML::Schema) -Finally, if you'd like to use XSL Transformations to process data, -then install the libxslt gem which is available at -https://github.com/xml4r/libxslt-ruby. +Finally, if you'd like to use XSL Transformations to process data, then install +the {libxslt gem}[https://github.com/xml4r/libxslt-rubygem]. == Usage -For information about using libxml-ruby please refer to its documentation at -http://xml4r.github.com/libxml-ruby/rdoc/index.html. Some tutorials are also -available at https://github.com/xml4r/libxml-ruby/wiki. +For information about using libxml-ruby please refer to its +documentation[http://xml4r.github.io/libxml-ruby]. Some tutorials are also +available[https://github.com/xml4r/libxml-ruby/wiki]. All libxml classes are in the LibXML::XML module. The easiest -way to use libxml is to require 'xml'. This will mixin +way to use libxml is to require 'xml'. This will mixin the LibXML module into the global namespace, allowing you to write code like this: @@ -124,10 +123,11 @@ Once you have build the shared libary, you can then run tests using rake: +Travis build status: {Build Status}[https://travis-ci.org/xml4r/libxml-ruby] == Performance + In addition to being feature rich and conformation, the main reason -people use libxml-ruby is for performance. Here are the results +people use libxml-ruby is for performance. Here are the results of a couple simple benchmarks recently blogged about on the -Web (you can find them in the benchmark directory of the +Web (you can find them in the benchmark directory of the libxml distribution). From http://depixelate.com/2008/4/23/ruby-xml-parsing-benchmarks @@ -149,46 +149,46 @@ From https://svn.concord.org/svn/projects/trunk/common/ruby/xml_benchmarks/ Documentation is available via rdoc, and is installed automatically with the gem. -libxml-ruby's online documentation is generated using Hanna, which is a -development gem dependency. +libxml-ruby's {online +documentation}[https://xml4r.github.io/libxml-ruby/rdoc/index.html] is generated +using Hanna, which is a development gem dependency. Note that older versions of Rdoc, which ship with Ruby 1.8.x, will report a number of errors. To avoid them, install Rdoc 2.1 or higher. Once you have installed the gem, you'll have to disable the version of Rdoc that Ruby 1.8.x -includes. An easy way to do that is rename the directory ruby/lib/ruby/1.8/rdoc to -ruby/lib/ruby/1.8/rdoc_old. +includes. An easy way to do that is rename the directory +ruby/lib/ruby/1.8/rdoc to +ruby/lib/ruby/1.8/rdoc_old. == Support - -If you have any questions about using libxml-ruby, please report them to -Git Hub at https://github.com/xml4r/libxml-ruby/issues +If you have any questions about using libxml-ruby, please report an issue +on GitHub[https://github.com/xml4r/libxml-ruby/issues]. == Memory Management libxml-ruby automatically manages memory associated with the underlying libxml2 library. The bindings create a one-to-one mapping between -ruby objects and libxml documents and libxml parent nodes (ie, nodes that do not -have a parent and do not belong to a document). In these cases, +Ruby objects and libxml documents and libxml parent nodes (ie, nodes that do not +have a parent and do not belong to a document). In these cases, the bindings manage the memory. They do this by installing a free function and storing a back pointer to the Ruby object from the xmlnode using the _private member on libxml structures. When the Ruby object goes out of scope, the underlying libxml structure is freed. Libxml -itself then frees all child node (recursively). +itself then frees all child nodes (recursively). For all other nodes (the vast majority), the bindings create temporary Ruby objects that get freed once they go out of scope. Thus there can be -more than one ruby object pointing to the same xml node. To mostly hide -this from programmers on the ruby side, the #eql? and #== methods are -overriden to check if two ruby objects wrap the same xmlnode. If they do, +more than one Ruby object pointing to the same xml node. To mostly hide +this from a programmer on the Ruby side, the #eql? and #== methods are +overriden to check if two Ruby objects wrap the same xmlnode. If they do, then the methods return true. During the mark phase, each of these temporary objects marks its owning document, thereby keeping the Ruby document object alive and thus the xmldoc tree. In the sweep phase of the garbage collector, or when a program ends, -there is no order to how Ruby objects are freed. In fact, the ruby document -object is almost always freed before any ruby objects that wrap child nodes. -However, this is ok because those ruby objects do not have a free function +there is no order to how Ruby objects are freed. In fact, the Ruby document +object is almost always freed before any Ruby objects that wrap child nodes. +However, this is ok because those Ruby objects do not have a free function and are no longer in scope (since if they were the document would not be freed). == License See LICENSE for license information. - diff --git a/ext/libxml/extconf.rb b/ext/libxml/extconf.rb index 833fc63d..bb349dcd 100644 --- a/ext/libxml/extconf.rb +++ b/ext/libxml/extconf.rb @@ -64,7 +64,6 @@ def crash(str) have_header('libxml/parser.h') || crash('parser.h not found') have_library('xml2', 'xmlParseDoc ') || crash('libxml2 not found') -have_func('rb_io_bufwrite', 'ruby/io.h') create_header() create_makefile('libxml_ruby') diff --git a/ext/libxml/ruby_libxml.h b/ext/libxml/ruby_libxml.h index 3e90b931..a66b722f 100644 --- a/ext/libxml/ruby_libxml.h +++ b/ext/libxml/ruby_libxml.h @@ -16,15 +16,7 @@ #include #include -/* Needed prior to Ruby 1.9.1 */ -#ifndef RHASH_TBL -#define RHASH_TBL(s) (RHASH(s)->tbl) -#endif - -// Encoding support added in Ruby 1.9.* -#ifdef HAVE_RUBY_ENCODING_H #include -#endif #ifdef LIBXML_DEBUG_ENABLED #include diff --git a/ext/libxml/ruby_xml_document.c b/ext/libxml/ruby_xml_document.c index e8826586..0dce1c1a 100644 --- a/ext/libxml/ruby_xml_document.c +++ b/ext/libxml/ruby_xml_document.c @@ -483,7 +483,6 @@ static VALUE rxml_document_encoding_get(VALUE self) * Returns the Ruby encoding specified by this document * (available on Ruby 1.9.x and higher). */ -#ifdef HAVE_RUBY_ENCODING_H static VALUE rxml_document_rb_encoding_get(VALUE self) { xmlDocPtr xdoc; @@ -493,7 +492,6 @@ static VALUE rxml_document_rb_encoding_get(VALUE self) rbencoding = rxml_xml_encoding_to_rb_encoding(mXMLEncoding, xmlParseCharEncoding((const char*)xdoc->encoding)); return rb_enc_from_encoding(rbencoding); } -#endif /* * call-seq: @@ -738,7 +736,7 @@ static VALUE rxml_document_root_set(VALUE self, VALUE node) Data_Get_Struct(node, xmlNode, xnode); if (xnode->doc != NULL && xnode->doc != xdoc) - rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling XML::Document.import"); + rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import"); xmlDocSetRootElement(xdoc, xnode); @@ -1097,9 +1095,7 @@ void rxml_init_document(void) rb_define_method(cXMLDocument, "compression?", rxml_document_compression_q, 0); rb_define_method(cXMLDocument, "debug", rxml_document_debug, 0); rb_define_method(cXMLDocument, "encoding", rxml_document_encoding_get, 0); -#ifdef HAVE_RUBY_ENCODING_H rb_define_method(cXMLDocument, "rb_encoding", rxml_document_rb_encoding_get, 0); -#endif rb_define_method(cXMLDocument, "encoding=", rxml_document_encoding_set, 1); rb_define_method(cXMLDocument, "import", rxml_document_import, 1); rb_define_method(cXMLDocument, "last", rxml_document_last_get, 0); diff --git a/ext/libxml/ruby_xml_dtd.c b/ext/libxml/ruby_xml_dtd.c index 2cbc0dc8..062be1fe 100644 --- a/ext/libxml/ruby_xml_dtd.c +++ b/ext/libxml/ruby_xml_dtd.c @@ -38,13 +38,11 @@ void rxml_dtd_free(xmlDtdPtr xdtd) void rxml_dtd_mark(xmlDtdPtr xdtd) { - VALUE doc = Qnil; - - if (xdtd == NULL) - return; - - doc = (VALUE)xdtd->doc->_private; - rb_gc_mark(doc); + if (xdtd && xdtd->doc) + { + VALUE doc = (VALUE)xdtd->doc->_private; + rb_gc_mark(doc); + } } static VALUE rxml_dtd_alloc(VALUE klass) @@ -173,7 +171,7 @@ static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self) } if (doc != Qnil) { if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse) - rb_raise(rb_eTypeError, "Must pass an XML::Document object"); + rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object"); Data_Get_Struct(doc, xmlDoc, xdoc); } diff --git a/ext/libxml/ruby_xml_encoding.c b/ext/libxml/ruby_xml_encoding.c index 31e50eae..d53c8c64 100644 --- a/ext/libxml/ruby_xml_encoding.c +++ b/ext/libxml/ruby_xml_encoding.c @@ -74,7 +74,6 @@ static VALUE rxml_encoding_to_s(VALUE klass, VALUE encoding) return rxml_new_cstr(xencoding, xencoding); } -#ifdef HAVE_RUBY_ENCODING_H /* * Converts an xmlCharEncoding enum value into a Ruby Encoding object (available * on Ruby 1.9.* and higher). @@ -179,26 +178,17 @@ rb_encoding* rxml_figure_encoding(const xmlChar* xencoding) } return result; } -#endif VALUE rxml_new_cstr(const xmlChar* xstr, const xmlChar* xencoding) { -#ifdef HAVE_RUBY_ENCODING_H rb_encoding *rbencoding = rxml_figure_encoding(xencoding); return rb_external_str_new_with_enc((const char*)xstr, strlen((const char*)xstr), rbencoding); -#else - return rb_str_new2((const char*)xstr); -#endif } VALUE rxml_new_cstr_len(const xmlChar* xstr, const long length, const xmlChar* xencoding) { -#ifdef HAVE_RUBY_ENCODING_H rb_encoding *rbencoding = rxml_figure_encoding(xencoding); return rb_external_str_new_with_enc((const char*)xstr, length, rbencoding); -#else - return rb_str_new((const char*)xstr, length); -#endif } void rxml_init_encoding(void) @@ -207,9 +197,7 @@ void rxml_init_encoding(void) rb_define_module_function(mXMLEncoding, "from_s", rxml_encoding_from_s, 1); rb_define_module_function(mXMLEncoding, "to_s", rxml_encoding_to_s, 1); -#ifdef HAVE_RUBY_ENCODING_H - // rb_define_module_function(mXMLEncoding, "to_rb_encoding", rxml_encoding_to_rb_encoding, 2); -#endif + rb_define_module_function(mXMLEncoding, "to_rb_encoding", rxml_encoding_to_rb_encoding, 2); /* -1: No char encoding detected. */ rb_define_const(mXMLEncoding, "ERROR", INT2NUM(XML_CHAR_ENCODING_ERROR)); diff --git a/ext/libxml/ruby_xml_encoding.h b/ext/libxml/ruby_xml_encoding.h index cb582135..e0d89b46 100644 --- a/ext/libxml/ruby_xml_encoding.h +++ b/ext/libxml/ruby_xml_encoding.h @@ -7,13 +7,10 @@ extern VALUE mXMLEncoding; void rxml_init_encoding(); -// Ruby 1.8/1.9 encoding compatibility VALUE rxml_new_cstr(const xmlChar* xstr, const xmlChar* xencoding); VALUE rxml_new_cstr_len(const xmlChar* xstr, const long length, const xmlChar* xencoding); -#ifdef HAVE_RUBY_ENCODING_H rb_encoding* rxml_xml_encoding_to_rb_encoding(VALUE klass, xmlCharEncoding xmlEncoding); rb_encoding* rxml_figure_encoding(const xmlChar* xencoding); -#endif #endif diff --git a/ext/libxml/ruby_xml_io.c b/ext/libxml/ruby_xml_io.c index 465e70b6..e577a73f 100644 --- a/ext/libxml/ruby_xml_io.c +++ b/ext/libxml/ruby_xml_io.c @@ -1,13 +1,10 @@ /* Please see the LICENSE file for copyright and distribution information */ #include "ruby_libxml.h" +#include static ID READ_METHOD; -#ifdef HAVE_RB_IO_BUFWRITE -#include -#else static ID WRITE_METHOD; -#endif /* !HAVE_RB_IO_BUFWRITE */ /* This method is called by libxml when it wants to read more data from a stream. We go with the duck typing @@ -27,25 +24,24 @@ int rxml_read_callback(void *context, char *buffer, int len) return (int)size; } -int rxml_write_callback(void *context, const char *buffer, int len) +int rxml_write_callback(VALUE io, const char *buffer, int len) { -#ifndef HAVE_RB_IO_BUFWRITE - VALUE io, written, string; - - io = (VALUE) context; - string = rb_str_new(buffer, len); - written = rb_funcall(io, WRITE_METHOD, 1, string); - - return NUM2INT(written); -#else - return (int)rb_io_bufwrite((VALUE) context, buffer, (size_t)len); -#endif /* !HAVE_RB_IO_BUFWRITE */ + if (rb_io_check_io(io) == Qnil) + { + // Could be StringIO + VALUE written, string; + string = rb_external_str_new_with_enc(buffer, strlen(buffer), rb_enc_get(io)); + written = rb_funcall(io, WRITE_METHOD, 1, string); + return NUM2INT(written); + } + else + { + return (int)rb_io_bufwrite(io, buffer, (size_t)len); + } } void rxml_init_io(void) { READ_METHOD = rb_intern("read"); -#ifndef HAVE_RB_IO_BUFWRITE WRITE_METHOD = rb_intern("write"); -#endif /* !HAVE_RB_IO_BUFWRITE */ } diff --git a/ext/libxml/ruby_xml_io.h b/ext/libxml/ruby_xml_io.h index 7e8a0fc0..cafd95ce 100644 --- a/ext/libxml/ruby_xml_io.h +++ b/ext/libxml/ruby_xml_io.h @@ -4,7 +4,7 @@ #define __RXML_IO__ int rxml_read_callback(void *context, char *buffer, int len); -int rxml_write_callback(void *context, const char *buffer, int len); +int rxml_write_callback(VALUE io, const char *buffer, int len); void rxml_init_io(void); #endif diff --git a/ext/libxml/ruby_xml_node.c b/ext/libxml/ruby_xml_node.c index 4d20c9a1..0f2b9d37 100644 --- a/ext/libxml/ruby_xml_node.c +++ b/ext/libxml/ruby_xml_node.c @@ -310,7 +310,7 @@ static VALUE rxml_node_modify_dom(VALUE self, VALUE target, xtarget = rxml_get_xnode(target); if (xtarget->doc != NULL && xtarget->doc != xnode->doc) - rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling XML::Document.import"); + rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import"); xmlUnlinkNode(xtarget); diff --git a/ext/libxml/ruby_xml_parser_context.c b/ext/libxml/ruby_xml_parser_context.c index e679e526..e9f7a04e 100644 --- a/ext/libxml/ruby_xml_parser_context.c +++ b/ext/libxml/ruby_xml_parser_context.c @@ -47,7 +47,7 @@ static VALUE rxml_parser_context_document(VALUE klass, VALUE document) int length; if (rb_obj_is_kind_of(document, cXMLDocument) == Qfalse) - rb_raise(rb_eTypeError, "Must pass an XML::Document object"); + rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object"); Data_Get_Struct(document, xmlDoc, xdoc); xmlDocDumpFormatMemoryEnc(xdoc, &buffer, &length, (const char*)xdoc->encoding, 0); diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h index b487b020..63e5b019 100644 --- a/ext/libxml/ruby_xml_version.h +++ b/ext/libxml/ruby_xml_version.h @@ -1,9 +1,9 @@ /* Don't nuke this block! It is used for automatically updating the * versions below. VERSION = string formatting, VERNUM = numbered * version for inline testing: increment both or none at all.*/ -#define RUBY_LIBXML_VERSION "3.1.0.6" -#define RUBY_LIBXML_VERNUM 3106 +#define RUBY_LIBXML_VERSION "3.2.1.1" +#define RUBY_LIBXML_VERNUM 3211 #define RUBY_LIBXML_VER_MAJ 3 -#define RUBY_LIBXML_VER_MIN 1 -#define RUBY_LIBXML_VER_MIC 0 -#define RUBY_LIBXML_VER_PATCH 6 +#define RUBY_LIBXML_VER_MIN 2 +#define RUBY_LIBXML_VER_MIC 1 +#define RUBY_LIBXML_VER_PATCH 1 diff --git a/ext/libxml/ruby_xml_writer.c b/ext/libxml/ruby_xml_writer.c index a385484b..68a706ef 100644 --- a/ext/libxml/ruby_xml_writer.c +++ b/ext/libxml/ruby_xml_writer.c @@ -19,57 +19,29 @@ static VALUE sEncoding, sStandalone; #include -typedef enum { +typedef enum +{ RXMLW_OUTPUT_NONE, RXMLW_OUTPUT_IO, RXMLW_OUTPUT_DOC, RXMLW_OUTPUT_STRING } rxmlw_output_type; -typedef struct { +typedef struct +{ VALUE output; -#ifdef HAVE_RUBY_ENCODING_H - rb_encoding *encoding; -#endif /* HAVE_RUBY_ENCODING_H */ + rb_encoding* encoding; xmlBufferPtr buffer; xmlTextWriterPtr writer; rxmlw_output_type output_type; int closed; } rxml_writer_object; -#ifdef HAVE_RUBY_ENCODING_H - -#define /*VALUE*/ rxml_writer_c_to_ruby_string(/*const xmlChar **/ string, /*long*/ string_len) \ - rb_external_str_new_with_enc(string, string_len, rb_utf8_encoding()) - -#define /*VALUE*/ rxml_writer_ruby_string_to_utf8(/*VALUE*/ string) \ - rb_str_conv_enc(string, rb_enc_get(string), rb_utf8_encoding()) -// rb_str_export_to_enc(string, rb_utf8_encoding()) - -#define /*void*/ rxml_writer_free_utf8_string(/*VALUE*/ orig, /*VALUE*/ utf8) \ - do { \ - if (orig != utf8) { \ - rb_str_free(utf8); \ - } \ - } while (0); - -#else - -#define /*VALUE*/ rxml_writer_c_to_ruby_string(/*const xmlChar **/ string, /*long*/ string_len) \ - rb_str_new(string, string_len) - -#define /*VALUE*/ rxml_writer_ruby_string_to_utf8(/*VALUE*/ string) \ - string - -#define /*void*/ rxml_writer_free_utf8_string(/*VALUE*/ orig, /*VALUE*/ utf8) \ - /* NOP */ - -#endif /* HAVE_RUBY_ENCODING_H */ - -static void rxml_writer_free(rxml_writer_object *rwo) +static void rxml_writer_free(rxml_writer_object* rwo) { #if 0 /* seems to be done by xmlFreeTextWriter */ - if (NULL != rwo->buffer) { + if (NULL != rwo->buffer) + { xmlBufferFree(rwo->buffer); } #endif @@ -79,36 +51,40 @@ static void rxml_writer_free(rxml_writer_object *rwo) xfree(rwo); } -static void rxml_writer_mark(rxml_writer_object *rwo) +static void rxml_writer_mark(rxml_writer_object* rwo) { - if (!NIL_P(rwo->output)) { + if (!NIL_P(rwo->output)) + { rb_gc_mark(rwo->output); } } -static VALUE rxml_writer_wrap(rxml_writer_object *rwo) +static VALUE rxml_writer_wrap(rxml_writer_object* rwo) { return Data_Wrap_Struct(cXMLWriter, rxml_writer_mark, rxml_writer_free, rwo); } -static rxml_writer_object *rxml_textwriter_get(VALUE obj) +static rxml_writer_object* rxml_textwriter_get(VALUE obj) { - rxml_writer_object *rwo; + rxml_writer_object* rwo; Data_Get_Struct(obj, rxml_writer_object, rwo); return rwo; } -int rxml_writer_write_callback(void *context, const char *buffer, int len) +int rxml_writer_write_callback(void* context, const char* buffer, int len) { - rxml_writer_object *rwo = context; + rxml_writer_object* rwo = context; - if(rwo->closed){ - return 0; - }else{ - return rxml_write_callback((void *)rwo->output, buffer, len); - } + if (rwo->closed) + { + return 0; + } + else + { + return rxml_write_callback(rwo->output, buffer, len); + } } /* ===== public class methods ===== */ @@ -120,31 +96,26 @@ int rxml_writer_write_callback(void *context, const char *buffer, int len) */ static VALUE rxml_writer_io(VALUE klass, VALUE io) { -#if 0 -typedef int (*xmlOutputCloseCallback)(void * context); -typedef int (*xmlOutputWriteCallback)(void * context, const char * buffer, int len); - -ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size); - -xmlOutputBufferPtr xmlOutputBufferCreateIO(xmlOutputWriteCallback iowrite, xmlOutputCloseCallback ioclose, void * ioctx, xmlCharEncodingHandlerPtr encoder) - -xmlCharEncodingHandlerPtr xmlFindCharEncodingHandler(const char * name); -#endif xmlOutputBufferPtr out; - rxml_writer_object *rwo; + rxml_writer_object* rwo; rwo = ALLOC(rxml_writer_object); rwo->output = io; rwo->buffer = NULL; rwo->closed = 0; -#ifdef HAVE_RUBY_ENCODING_H - rwo->encoding = NULL; -#endif /* HAVE_RUBY_ENCODING_H */ + rwo->encoding = rb_enc_get(io); + if (!rwo->encoding) + rwo->encoding = rb_utf8_encoding(); + rwo->output_type = RXMLW_OUTPUT_IO; - if (NULL == (out = xmlOutputBufferCreateIO(rxml_writer_write_callback, NULL, (void *) rwo, NULL))) { + + xmlCharEncodingHandlerPtr encodingHdlr = xmlFindCharEncodingHandler(rwo->encoding->name); + if (NULL == (out = xmlOutputBufferCreateIO(rxml_writer_write_callback, NULL, (void*)rwo, encodingHdlr))) + { rxml_raise(&xmlLastError); } - if (NULL == (rwo->writer = xmlNewTextWriter(out))) { + if (NULL == (rwo->writer = xmlNewTextWriter(out))) + { rxml_raise(&xmlLastError); } @@ -160,17 +131,16 @@ xmlCharEncodingHandlerPtr xmlFindCharEncodingHandler(const char * name); */ static VALUE rxml_writer_file(VALUE klass, VALUE filename) { - rxml_writer_object *rwo; + rxml_writer_object* rwo; rwo = ALLOC(rxml_writer_object); rwo->output = Qnil; rwo->buffer = NULL; rwo->closed = 0; -#ifdef HAVE_RUBY_ENCODING_H - rwo->encoding = NULL; -#endif /* HAVE_RUBY_ENCODING_H */ + rwo->encoding = rb_utf8_encoding(); rwo->output_type = RXMLW_OUTPUT_NONE; - if (NULL == (rwo->writer = xmlNewTextWriterFilename(StringValueCStr(filename), 0))) { + if (NULL == (rwo->writer = xmlNewTextWriterFilename(StringValueCStr(filename), 0))) + { rxml_raise(&xmlLastError); } @@ -184,19 +154,19 @@ static VALUE rxml_writer_file(VALUE klass, VALUE filename) */ static VALUE rxml_writer_string(VALUE klass) { - rxml_writer_object *rwo; + rxml_writer_object* rwo; rwo = ALLOC(rxml_writer_object); rwo->output = Qnil; rwo->closed = 0; -#ifdef HAVE_RUBY_ENCODING_H - rwo->encoding = NULL; -#endif /* HAVE_RUBY_ENCODING_H */ + rwo->encoding = rb_utf8_encoding(); rwo->output_type = RXMLW_OUTPUT_STRING; - if (NULL == (rwo->buffer = xmlBufferCreate())) { + if (NULL == (rwo->buffer = xmlBufferCreate())) + { rxml_raise(&xmlLastError); } - if (NULL == (rwo->writer = xmlNewTextWriterMemory(rwo->buffer, 0))) { + if (NULL == (rwo->writer = xmlNewTextWriterMemory(rwo->buffer, 0))) + { xmlBufferFree(rwo->buffer); rxml_raise(&xmlLastError); } @@ -212,17 +182,16 @@ static VALUE rxml_writer_string(VALUE klass) static VALUE rxml_writer_doc(VALUE klass) { xmlDocPtr doc; - rxml_writer_object *rwo; + rxml_writer_object* rwo; rwo = ALLOC(rxml_writer_object); rwo->buffer = NULL; rwo->output = Qnil; rwo->closed = 0; -#ifdef HAVE_RUBY_ENCODING_H - rwo->encoding = NULL; -#endif /* HAVE_RUBY_ENCODING_H */ + rwo->encoding = rb_utf8_encoding(); rwo->output_type = RXMLW_OUTPUT_DOC; - if (NULL == (rwo->writer = xmlNewTextWriterDoc(&doc, 0))) { + if (NULL == (rwo->writer = xmlNewTextWriterDoc(&doc, 0))) + { rxml_raise(&xmlLastError); } rwo->output = rxml_document_wrap(doc); @@ -240,33 +209,34 @@ static VALUE rxml_writer_doc(VALUE klass) * If +empty?+ is +true+, and for a in memory XML::Writer, this internel * buffer is empty. */ -static VALUE rxml_writer_flush(int argc, VALUE *argv, VALUE self) +static VALUE rxml_writer_flush(int argc, VALUE* argv, VALUE self) { int ret; VALUE empty; - rxml_writer_object *rwo; + rxml_writer_object* rwo; rb_scan_args(argc, argv, "01", &empty); rwo = rxml_textwriter_get(self); - if (-1 == (ret = xmlTextWriterFlush(rwo->writer))) { + if (-1 == (ret = xmlTextWriterFlush(rwo->writer))) + { rxml_raise(&xmlLastError); } - if (NULL != rwo->buffer) { + if (NULL != rwo->buffer) + { VALUE content; -#ifdef HAVE_RUBY_ENCODING_H content = rb_external_str_new_with_enc((const char*)rwo->buffer->content, rwo->buffer->use, rwo->encoding); -#else - content = rb_str_new(rwo->buffer->content, rwo->buffer->use); -#endif /* HAVE_RUBY_ENCODING_H */ - if (NIL_P(empty) || RTEST(empty)) { /* nil = default value = true */ + if (NIL_P(empty) || RTEST(empty)) + { /* nil = default value = true */ xmlBufferEmpty(rwo->buffer); } return content; - } else { + } + else + { return INT2NUM(ret); } } @@ -281,26 +251,28 @@ static VALUE rxml_writer_flush(int argc, VALUE *argv, VALUE self) static VALUE rxml_writer_result(VALUE self) { VALUE ret = Qnil; - rxml_writer_object *rwo = rxml_textwriter_get(self); + rxml_writer_object* rwo = rxml_textwriter_get(self); int bytesWritten = xmlTextWriterFlush(rwo->writer); - if (bytesWritten == -1) { + if (bytesWritten == -1) + { rxml_raise(&xmlLastError); } - switch (rwo->output_type) { - case RXMLW_OUTPUT_DOC: - ret = rwo->output; - break; - case RXMLW_OUTPUT_STRING: - ret = rxml_writer_c_to_ruby_string((const char*)rwo->buffer->content, rwo->buffer->use); - break; - case RXMLW_OUTPUT_IO: - case RXMLW_OUTPUT_NONE: - break; - default: - rb_bug("unexpected output"); - break; + switch (rwo->output_type) + { + case RXMLW_OUTPUT_DOC: + ret = rwo->output; + break; + case RXMLW_OUTPUT_STRING: + ret = rb_external_str_new_with_enc((const char*)rwo->buffer->content, rwo->buffer->use, rwo->encoding); + break; + case RXMLW_OUTPUT_IO: + case RXMLW_OUTPUT_NONE: + break; + default: + rb_bug("unexpected output"); + break; } return ret; @@ -311,7 +283,7 @@ static VALUE rxml_writer_result(VALUE self) static VALUE numeric_rxml_writer_void(VALUE obj, int (*fn)(xmlTextWriterPtr)) { int ret; - rxml_writer_object *rwo; + rxml_writer_object* rwo; rwo = rxml_textwriter_get(obj); ret = fn(rwo->writer); @@ -335,88 +307,102 @@ static VALUE numeric_rxml_writer_va_strings(VALUE obj, VALUE pe, size_t strings_ { va_list ap; size_t argc; - int ret = -1; - rxml_writer_object *rwo; - const xmlChar *argv[XMLWRITER_MAX_STRING_ARGS]; + int ret = -1; + rxml_writer_object* rwo; + const xmlChar* argv[XMLWRITER_MAX_STRING_ARGS]; VALUE utf8[XMLWRITER_MAX_STRING_ARGS], orig[XMLWRITER_MAX_STRING_ARGS]; - if (strings_count > XMLWRITER_MAX_STRING_ARGS) { + if (strings_count > XMLWRITER_MAX_STRING_ARGS) + { rb_bug("more arguments than expected"); } va_start(ap, fn); rwo = rxml_textwriter_get(obj); - for (argc = 0; argc < strings_count; argc++) { + for (argc = 0; argc < strings_count; argc++) + { VALUE arg; arg = va_arg(ap, VALUE); orig[argc] = arg; - if (NIL_P(arg)) { + if (NIL_P(arg)) + { utf8[argc] = Qnil; argv[argc] = NULL; - } else { - utf8[argc] = rxml_writer_ruby_string_to_utf8(orig[argc]); + } + else + { + utf8[argc] = rb_str_conv_enc(orig[argc], rb_enc_get(orig[argc]), rwo->encoding); argv[argc] = BAD_CAST StringValueCStr(utf8[argc]); } } va_end(ap); - if (Qundef == pe) { - switch (strings_count) { - case 0: - ret = fn(rwo->writer); - break; - case 1: - ret = fn(rwo->writer, argv[0]); - break; - case 2: - ret = fn(rwo->writer, argv[0], argv[1]); - break; - case 3: - ret = fn(rwo->writer, argv[0], argv[1], argv[2]); - break; - case 4: - ret = fn(rwo->writer, argv[0], argv[1], argv[2], argv[3]); - break; - case 5: - ret = fn(rwo->writer, argv[0], argv[1], argv[2], argv[3], argv[4]); - break; - default: - break; + if (Qundef == pe) + { + switch (strings_count) + { + case 0: + ret = fn(rwo->writer); + break; + case 1: + ret = fn(rwo->writer, argv[0]); + break; + case 2: + ret = fn(rwo->writer, argv[0], argv[1]); + break; + case 3: + ret = fn(rwo->writer, argv[0], argv[1], argv[2]); + break; + case 4: + ret = fn(rwo->writer, argv[0], argv[1], argv[2], argv[3]); + break; + case 5: + ret = fn(rwo->writer, argv[0], argv[1], argv[2], argv[3], argv[4]); + break; + default: + break; } - } else { + } + else + { int xpe; xpe = RTEST(pe); - switch (strings_count) { /* strings_count doesn't include pe */ - case 0: - ret = fn(rwo->writer, xpe); - break; - case 1: - ret = fn(rwo->writer, xpe, argv[0]); - break; - case 2: - ret = fn(rwo->writer, xpe, argv[0], argv[1]); - break; - case 3: - ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2]); - break; - case 4: - ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2], argv[3]); - break; - case 5: - ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2], argv[3], argv[4]); - break; - default: - break; + switch (strings_count) + { /* strings_count doesn't include pe */ + case 0: + ret = fn(rwo->writer, xpe); + break; + case 1: + ret = fn(rwo->writer, xpe, argv[0]); + break; + case 2: + ret = fn(rwo->writer, xpe, argv[0], argv[1]); + break; + case 3: + ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2]); + break; + case 4: + ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2], argv[3]); + break; + case 5: + ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2], argv[3], argv[4]); + break; + default: + break; } } -#ifdef HAVE_RUBY_ENCODING_H - while (--strings_count > 0) { - if (!NIL_P(orig[strings_count])) { - rxml_writer_free_utf8_string(orig[strings_count], utf8[strings_count]); + + while (--strings_count > 0) + { + if (!NIL_P(orig[strings_count])) + { + if (orig[strings_count] != utf8[strings_count]) + { + rb_str_free(utf8[strings_count]); + } } } -#endif /* HAVE_RUBY_ENCODING_H */ return (-1 == ret ? Qfalse : Qtrue); } @@ -434,7 +420,7 @@ static VALUE numeric_rxml_writer_va_strings(VALUE obj, VALUE pe, size_t strings_ static VALUE rxml_writer_set_indent(VALUE self, VALUE indentation) { int ret; - rxml_writer_object *rwo; + rxml_writer_object* rwo; rwo = rxml_textwriter_get(self); ret = xmlTextWriterSetIndent(rwo->writer, RTEST(indentation)); @@ -484,7 +470,7 @@ static VALUE rxml_writer_write_cdata(VALUE self, VALUE content) } static VALUE rxml_writer_start_element(VALUE, VALUE); -static VALUE rxml_writer_start_element_ns(int, VALUE *, VALUE); +static VALUE rxml_writer_start_element_ns(int, VALUE*, VALUE); static VALUE rxml_writer_end_element(VALUE); /* call-seq: @@ -494,17 +480,21 @@ static VALUE rxml_writer_end_element(VALUE); * This is equivalent to start_element(name) + write_string(content) + * end_element. */ -static VALUE rxml_writer_write_element(int argc, VALUE *argv, VALUE self) +static VALUE rxml_writer_write_element(int argc, VALUE* argv, VALUE self) { VALUE name, content; rb_scan_args(argc, argv, "11", &name, &content); - if (Qnil == content) { - if (Qfalse == rxml_writer_start_element(self, name)) { + if (Qnil == content) + { + if (Qfalse == rxml_writer_start_element(self, name)) + { return Qfalse; } return rxml_writer_end_element(self); - } else { + } + else + { return numeric_rxml_writer_va_strings(self, Qundef, 2, xmlTextWriterWriteElement, name, content); } } @@ -526,19 +516,23 @@ static VALUE rxml_writer_write_element(int argc, VALUE *argv, VALUE self) * earlier. * - +content+ can be omitted for an empty tag */ -static VALUE rxml_writer_write_element_ns(int argc, VALUE *argv, VALUE self) +static VALUE rxml_writer_write_element_ns(int argc, VALUE* argv, VALUE self) { VALUE prefix, name, namespaceURI, content; rb_scan_args(argc, argv, "22", &prefix, &name, &namespaceURI, &content); - if (Qnil == content) { + if (Qnil == content) + { VALUE argv[3] = { prefix, name, namespaceURI }; - if (Qfalse == rxml_writer_start_element_ns(ARRAY_SIZE(argv), argv, self)) { + if (Qfalse == rxml_writer_start_element_ns(ARRAY_SIZE(argv), argv, self)) + { return Qfalse; } return rxml_writer_end_element(self); - } else { + } + else + { return numeric_rxml_writer_va_strings(self, Qundef, 4, xmlTextWriterWriteElementNS, prefix, name, namespaceURI, content); } } @@ -568,7 +562,7 @@ static VALUE rxml_writer_write_attribute(VALUE self, VALUE name, VALUE content) * earlier. * - +content+ can be omitted too for an empty attribute */ -static VALUE rxml_writer_write_attribute_ns(int argc, VALUE *argv, VALUE self) +static VALUE rxml_writer_write_attribute_ns(int argc, VALUE* argv, VALUE self) { VALUE prefix, name, namespaceURI, content; @@ -634,7 +628,7 @@ static VALUE rxml_writer_start_attribute(VALUE self, VALUE name) * +namespaceURI+ to nil or omit it. Don't forget to declare the namespace * prefix somewhere earlier. */ -static VALUE rxml_writer_start_attribute_ns(int argc, VALUE *argv, VALUE self) +static VALUE rxml_writer_start_attribute_ns(int argc, VALUE* argv, VALUE self) { VALUE prefix, name, namespaceURI; @@ -697,7 +691,7 @@ static VALUE rxml_writer_start_element(VALUE self, VALUE name) * +namespaceURI+ to nil or omit it. Don't forget to declare the namespace * prefix somewhere earlier. */ -static VALUE rxml_writer_start_element_ns(int argc, VALUE *argv, VALUE self) +static VALUE rxml_writer_start_element_ns(int argc, VALUE* argv, VALUE self) { VALUE prefix, name, namespaceURI; @@ -762,16 +756,17 @@ static VALUE rxml_writer_end_cdata(VALUE self) * - standalone: nil (default) or a boolean to indicate if the document is * standalone or not */ -static VALUE rxml_writer_start_document(int argc, VALUE *argv, VALUE self) +static VALUE rxml_writer_start_document(int argc, VALUE* argv, VALUE self) { int ret; VALUE options = Qnil; - rxml_writer_object *rwo; - const xmlChar *xencoding = NULL; - const char *xstandalone = NULL; + rxml_writer_object* rwo; + const xmlChar* xencoding = NULL; + const char* xstandalone = NULL; rb_scan_args(argc, argv, "01", &options); - if (!NIL_P(options)) { + if (!NIL_P(options)) + { VALUE encoding, standalone; encoding = standalone = Qnil; @@ -779,16 +774,17 @@ static VALUE rxml_writer_start_document(int argc, VALUE *argv, VALUE self) encoding = rb_hash_aref(options, sEncoding); xencoding = NIL_P(encoding) ? NULL : (const xmlChar*)xmlGetCharEncodingName(NUM2INT(encoding)); standalone = rb_hash_aref(options, sStandalone); - if (NIL_P(standalone)) { + if (NIL_P(standalone)) + { xstandalone = NULL; - } else { + } + else + { xstandalone = RTEST(standalone) ? "yes" : "no"; } } rwo = rxml_textwriter_get(self); -#ifdef HAVE_RUBY_ENCODING_H rwo->encoding = rxml_figure_encoding(xencoding); -#endif /* !HAVE_RUBY_ENCODING_H */ ret = xmlTextWriterStartDocument(rwo->writer, NULL, (const char*)xencoding, xstandalone); return (-1 == ret ? Qfalse : Qtrue); @@ -829,7 +825,7 @@ static VALUE rxml_writer_end_pi(VALUE self) * * Starts a DTD. Returns +false+ on failure. */ -static VALUE rxml_writer_start_dtd(int argc, VALUE *argv, VALUE self) +static VALUE rxml_writer_start_dtd(int argc, VALUE* argv, VALUE self) { VALUE name, pubid, sysid; @@ -853,12 +849,13 @@ static VALUE rxml_writer_start_dtd_element(VALUE self, VALUE name) * * Starts a DTD entity (). Returns +false+ on failure. */ -static VALUE rxml_writer_start_dtd_entity(int argc, VALUE *argv, VALUE self) +static VALUE rxml_writer_start_dtd_entity(int argc, VALUE* argv, VALUE self) { VALUE name, pe; rb_scan_args(argc, argv, "11", &name, &pe); - if (NIL_P(pe)) { + if (NIL_P(pe)) + { pe = Qfalse; } @@ -934,7 +931,7 @@ static VALUE rxml_writer_end_dtd_element(VALUE self) * writer.write_dtd 'person', nil, nil, '' * #=> ]> */ -static VALUE rxml_writer_write_dtd(int argc, VALUE *argv, VALUE self) +static VALUE rxml_writer_write_dtd(int argc, VALUE* argv, VALUE self) { VALUE name, pubid, sysid, subset; @@ -1043,12 +1040,12 @@ static VALUE rxml_writer_write_dtd_notation(VALUE self, VALUE name, VALUE pubid, static VALUE rxml_writer_set_quote_char(VALUE self, VALUE quotechar) { int ret; - const char *xquotechar; - rxml_writer_object *rwo; + const char* xquotechar; + rxml_writer_object* rwo; rwo = rxml_textwriter_get(self); xquotechar = StringValueCStr(quotechar); - ret = xmlTextWriterSetQuoteChar(rwo->writer, (xmlChar) xquotechar[0]); + ret = xmlTextWriterSetQuoteChar(rwo->writer, (xmlChar)xquotechar[0]); return (-1 == ret ? Qfalse : Qtrue); } diff --git a/ext/vc/libxml_ruby/libxml_ruby.vcxproj b/ext/vc/libxml_ruby/libxml_ruby.vcxproj index f0a9e000..226ef25a 100644 --- a/ext/vc/libxml_ruby/libxml_ruby.vcxproj +++ b/ext/vc/libxml_ruby/libxml_ruby.vcxproj @@ -22,30 +22,30 @@ {0B65CD1D-EEB9-41AE-93BB-75496E504152} libxml Win32Proj - 10.0.16299.0 + 10.0 DynamicLibrary Unicode true - v141 + v142 DynamicLibrary Unicode true - v141 + v142 DynamicLibrary Unicode - v141 + v142 DynamicLibrary Unicode - v141 + v142 @@ -77,7 +77,7 @@ .so - ..\..\..\lib\2.5\ + ..\..\..\lib\2.7\ @@ -112,7 +112,7 @@ Disabled - C:\msys64\local\ruby250vc\include\ruby-2.5.0;C:\msys64\local\ruby250vc\include\ruby-2.5.0\x64-mswin64_140;C:\msys64\local\include\libxml2;C:\msys64\mingw64\include;%(AdditionalIncludeDirectories) + C:\msys64\usr\local\ruby-2.7.2vc\include\ruby-2.7.0;C:\msys64\usr\local\ruby-2.7.2vc\include\ruby-2.7.0\x64-mswin64_140;C:\msys64\mingw64\include\libxml2;C:\msys64\mingw64\include;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBXML_EXPORTS;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL @@ -126,9 +126,9 @@ - x64-vcruntime140-ruby250.lib;libxml2.lib;%(AdditionalDependencies) + x64-vcruntime140-ruby270.lib;libxml2.lib;%(AdditionalDependencies) $(OutDir)\$(TargetName)$(TargetExt) - C:\msys64\local\ruby250vc\lib;C:\msys64\local\lib;%(AdditionalLibraryDirectories) + C:\msys64\usr\local\ruby-2.7.2vc\lib;C:\msys64\mingw64\lib;%(AdditionalLibraryDirectories) true Console false diff --git a/lib/libxml-ruby.rb b/lib/libxml-ruby.rb new file mode 100644 index 00000000..f9086c0a --- /dev/null +++ b/lib/libxml-ruby.rb @@ -0,0 +1,30 @@ +# encoding: UTF-8 + +# Load the C-based binding. +begin + RUBY_VERSION =~ /(\d+.\d+)/ + require "#{$1}/libxml_ruby" +rescue LoadError + require "libxml_ruby" +end + +# Load Ruby supporting code. +require 'libxml/error' +require 'libxml/parser' +require 'libxml/document' +require 'libxml/namespaces' +require 'libxml/namespace' +require 'libxml/node' +require 'libxml/attributes' +require 'libxml/attr' +require 'libxml/attr_decl' +require 'libxml/tree' +require 'libxml/html_parser' +require 'libxml/sax_parser' +require 'libxml/sax_callbacks' + +#Schema Interface +require 'libxml/schema' +require 'libxml/schema/type' +require 'libxml/schema/element' +require 'libxml/schema/attribute' diff --git a/lib/libxml.rb b/lib/libxml.rb index 3cbd4b5a..e9390a87 100644 --- a/lib/libxml.rb +++ b/lib/libxml.rb @@ -1,30 +1,5 @@ # encoding: UTF-8 +# +# This include is deprecated, use libxml-ruby instead! -# Load the C-based binding. -begin - RUBY_VERSION =~ /(\d+.\d+)/ - require "#{$1}/libxml_ruby" -rescue LoadError - require "libxml_ruby" -end - -# Load Ruby supporting code. -require 'libxml/error' -require 'libxml/parser' -require 'libxml/document' -require 'libxml/namespaces' -require 'libxml/namespace' -require 'libxml/node' -require 'libxml/attributes' -require 'libxml/attr' -require 'libxml/attr_decl' -require 'libxml/tree' -require 'libxml/html_parser' -require 'libxml/sax_parser' -require 'libxml/sax_callbacks' - -#Schema Interface -require 'libxml/schema' -require 'libxml/schema/type' -require 'libxml/schema/element' -require 'libxml/schema/attribute' +require 'libxml-ruby' \ No newline at end of file diff --git a/salsify_libxml_ruby.gemspec b/salsify_libxml_ruby.gemspec index 0dbcaca2..18773147 100644 --- a/salsify_libxml_ruby.gemspec +++ b/salsify_libxml_ruby.gemspec @@ -34,8 +34,9 @@ Gem::Specification.new do |spec| 'lib/**/*.rb', 'script/**/*', 'test/**/*']) + spec.test_files = Dir.glob('test/test_*.rb') - spec.required_ruby_version = '>= 1.8.6' + spec.required_ruby_version = '>= 2.5' spec.add_development_dependency 'salsify_gem' spec.add_development_dependency 'rake-compiler' spec.add_development_dependency 'minitest' diff --git a/test/test_attr.rb b/test/test_attr.rb index 42f7c345..9df8b0b4 100644 --- a/test/test_attr.rb +++ b/test/test_attr.rb @@ -1,10 +1,10 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class AttrNodeTest < Minitest::Test def setup - xp = XML::Parser.string(<<-EOS) + xp = LibXML::XML::Parser.string(<<-EOS) @@ -42,7 +42,7 @@ def test_attr # Get the attr_decl attr = elem.attributes.get_attribute('access') refute_nil(attr) - assert_equal(XML::Node::ATTRIBUTE_NODE, attr.node_type) + assert_equal(LibXML::XML::Node::ATTRIBUTE_NODE, attr.node_type) assert_equal('attribute', attr.node_type_name) # Get its value @@ -56,7 +56,7 @@ def test_attr_decl # Get the attr_decl attr_decl = elem.attributes.get_attribute('access') refute_nil(attr_decl) - assert_equal(XML::Node::ATTRIBUTE_DECL, attr_decl.node_type) + assert_equal(LibXML::XML::Node::ATTRIBUTE_DECL, attr_decl.node_type) assert_equal('attribute declaration', attr_decl.node_type_name) # Get its value @@ -69,7 +69,7 @@ def test_type attr_decl = elem.attributes.get_attribute('access') refute_nil(attr_decl) - assert_equal(XML::Node::ATTRIBUTE_DECL, attr_decl.node_type) + assert_equal(LibXML::XML::Node::ATTRIBUTE_DECL, attr_decl.node_type) assert_equal('attribute declaration', attr_decl.node_type_name) end @@ -99,12 +99,12 @@ def test_prev attr_decl = elem.attributes.get_attribute('access') first_decl = attr_decl.prev - assert_equal(XML::Node::ATTRIBUTE_DECL, first_decl.node_type) + assert_equal(LibXML::XML::Node::ATTRIBUTE_DECL, first_decl.node_type) assert_equal('name', first_decl.name) assert_nil(first_decl.value) elem_decl = first_decl.prev - assert_equal(XML::Node::ELEMENT_DECL, elem_decl.node_type) + assert_equal(LibXML::XML::Node::ELEMENT_DECL, elem_decl.node_type) end def test_next @@ -127,6 +127,6 @@ def test_parent attr_decl = elem.attributes.get_attribute('access') parent = attr_decl.parent - assert_instance_of(XML::Dtd, parent) + assert_instance_of(LibXML::XML::Dtd, parent) end end \ No newline at end of file diff --git a/test/test_attributes.rb b/test/test_attributes.rb index cc09228e..ae1e5fa5 100644 --- a/test/test_attributes.rb +++ b/test/test_attributes.rb @@ -1,10 +1,10 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class AttributesTest < Minitest::Test def setup - xp = XML::Parser.string(<<-EOS) + xp = LibXML::XML::Parser.string(<<-EOS) mode)) end#test_canonicalize_with_w3c_c14n_3_1 @@ -30,12 +30,12 @@ def test_canonicalize_with_w3c_c14n_3_1 # (www.w3.org) 3.2 Whitespace in Document Content # http://www.w3.org/TR/xml-c14n#Example-WhitespaceInContent def test_canonicalize_with_w3c_c14n_3_2 - given_doc = XML::Document.file(self.path('c14n/given/example-2.xml')) + given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-2.xml')) expected = IO.read(self.path('c14n/result/without-comments/example-2')) assert_equal(expected, given_doc.canonicalize) expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-2')) - mode = XML::Document::XML_C14N_1_1 + mode = LibXML::XML::Document::XML_C14N_1_1 assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode)) end @@ -45,24 +45,24 @@ def test_canonicalize_with_w3c_c14n_3_2 # - Embedded DTD not parsed out of XML, therefore default attributes are # not applied to canonicalization. def test_canonicalize_with_w3c_c14n_3_3 - given_doc = XML::Document.file(self.path('c14n/given/example-3.xml')) + given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-3.xml')) expected = IO.read(self.path('c14n/result/without-comments/example-3')) assert_equal(expected, given_doc.canonicalize) expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-3')) - mode = XML::Document::XML_C14N_1_1 + mode = LibXML::XML::Document::XML_C14N_1_1 assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode)) end # (www.w3.org) 3.4 Character Modifications and Character References # http://www.w3.org/TR/xml-c14n#Example-Chars def test_canonicalize_with_w3c_c14n_3_4 - given_doc = XML::Document.file(self.path('c14n/given/example-4.xml')) + given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-4.xml')) expected = IO.read(self.path('c14n/result/without-comments/example-4')) assert_equal(expected, given_doc.canonicalize) expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-4')) - mode = XML::Document::XML_C14N_1_1 + mode = LibXML::XML::Document::XML_C14N_1_1 assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode)) end @@ -71,7 +71,7 @@ def test_canonicalize_with_w3c_c14n_3_4 # (2012-02-20) Failing likely due to a logic error # - libxml2(c14n.c:1788) XML_ENTITY_REF_NODE is invalid node for parsing. def test_canonicalize_with_w3c_c14n_3_5 - #given_doc = XML::Document.file(self.path('c14n/given/example-5.xml')) + #given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-5.xml')) # With Comments #expected_with_comments = IO.read(self.path('c14n/result/with-comments/example-5')) @@ -84,7 +84,7 @@ def test_canonicalize_with_w3c_c14n_3_5 # TODO - CANNOT COMPLETE TEST unless libxml2 supports additional node types. #assert_equal(expected_without_comments, given_doc.canonicalize(:comments => false)) #expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-5')) - #mode = XML::Document::XML_C14N_1_1 + #mode = LibXML::XML::Document::XML_C14N_1_1 # TODO - CANNOT COMPLETE TEST unless libxml2 supports additional node types. #assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode)) @@ -93,20 +93,12 @@ def test_canonicalize_with_w3c_c14n_3_5 # (www.w3.org) 3.6 UTF-8 Encoding # http://www.w3.org/TR/xml-c14n#Example-UTF8 def test_canonicalize_with_w3c_c14n_3_6 - given_doc = XML::Document.file(self.path('c14n/given/example-6.xml')) - if defined?(Encoding) - expected = IO.read(self.path('c14n/result/without-comments/example-6'), :encoding => Encoding::UTF_8) - else - expected = IO.read(self.path('c14n/result/without-comments/example-6')) - end + given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-6.xml')) + expected = IO.read(self.path('c14n/result/without-comments/example-6'), :encoding => Encoding::UTF_8) assert_equal(expected, given_doc.canonicalize) - if defined?(Encoding) - expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-6'), :encoding => Encoding::UTF_8) - else - expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-6')) - end - mode = XML::Document::XML_C14N_1_1 + expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-6'), :encoding => Encoding::UTF_8) + mode = LibXML::XML::Document::XML_C14N_1_1 assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode)) end @@ -114,7 +106,7 @@ def test_canonicalize_with_w3c_c14n_3_6 # http://www.w3.org/TR/xml-c14n#Example-DocSubsets def test_canonicalize_with_w3c_c14n_3_7 # Non Canonicalized Document - # given_doc = XML::Document.file(self.path('c14n/given/example-7.xml')) + # given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-7.xml')) #expected = IO.read(self.path('c14n/result/without-comments/example-7')) # e1_node = given_doc.find_first('ietf:e1', 'ietf:http://www.ietf.org') diff --git a/test/test_deprecated_require.rb b/test/test_deprecated_require.rb index fc1ab5ad..a5eabb45 100644 --- a/test/test_deprecated_require.rb +++ b/test/test_deprecated_require.rb @@ -4,9 +4,9 @@ class TestDeprecatedRequire < Minitest::Test def test_basic - xp = XML::Parser.string('onetwo') - assert_instance_of(XML::Parser, xp) + xp = LibXML::XML::Parser.string('onetwo') + assert_instance_of(LibXML::XML::Parser, xp) @doc = xp.parse - assert_instance_of(XML::Document, @doc) + assert_instance_of(LibXML::XML::Document, @doc) end end diff --git a/test/test_document.rb b/test/test_document.rb index d0e1e65d..2e1654dc 100644 --- a/test/test_document.rb +++ b/test/test_document.rb @@ -1,12 +1,12 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TestDocument < Minitest::Test def setup - xp = XML::Parser.string('onetwo') - assert_instance_of(XML::Parser, xp) + xp = LibXML::XML::Parser.string('onetwo') + assert_instance_of(LibXML::XML::Parser, xp) @doc = xp.parse - assert_instance_of(XML::Document, @doc) + assert_instance_of(LibXML::XML::Document, @doc) end def teardown @@ -14,24 +14,24 @@ def teardown end def test_klass - assert_instance_of(XML::Document, @doc) + assert_instance_of(LibXML::XML::Document, @doc) end def test_context context = @doc.context - assert_instance_of(XML::XPath::Context, context) + assert_instance_of(LibXML::XML::XPath::Context, context) end def test_find set = @doc.find('/ruby_array/fixnum') - assert_instance_of(XML::XPath::Object, set) + assert_instance_of(LibXML::XML::XPath::Object, set) assert_raises(NoMethodError) { set.xpath } end def test_compression - if XML.enabled_zlib? + if LibXML::XML.enabled_zlib? 0.upto(9) do |i| assert_equal(i, @doc.compression = i) assert_equal(i, @doc.compression) @@ -59,30 +59,30 @@ def test_compression def test_version assert_equal('1.0', @doc.version) - doc = XML::Document.new('6.9') + doc = LibXML::XML::Document.new('6.9') assert_equal('6.9', doc.version) end def test_write_root - @doc.root = XML::Node.new('rubynet') - assert_instance_of(XML::Node, @doc.root) - assert_instance_of(XML::Document, @doc.root.doc) + @doc.root = LibXML::XML::Node.new('rubynet') + assert_instance_of(LibXML::XML::Node, @doc.root) + assert_instance_of(LibXML::XML::Document, @doc.root.doc) assert_equal("\n\n", @doc.to_s(:indent => false)) end def test_doc_node_type - assert_equal(XML::Node::DOCUMENT_NODE, XML::Document.new.node_type) + assert_equal(LibXML::XML::Node::DOCUMENT_NODE, LibXML::XML::Document.new.node_type) end def test_doc_node_type_name - assert_equal('document_xml', XML::Document.new.node_type_name) + assert_equal('document_xml', LibXML::XML::Document.new.node_type_name) end def test_xhtml - doc = XML::Document.new + doc = LibXML::XML::Document.new assert(!doc.xhtml?) - XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true + LibXML::XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true assert(doc.xhtml?) end @@ -90,10 +90,10 @@ def test_document_root doc1 = LibXML::XML::Document.string("") doc2 = LibXML::XML::Document.string("") - error = assert_raises(XML::Error) do + error = assert_raises(LibXML::XML::Error) do doc1.root = doc2.root end - assert_equal(" Nodes belong to different documents. You must first import the node by calling XML::Document.import.", + assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.", error.to_s) doc2.root << doc2.import(doc1.root) @@ -105,16 +105,16 @@ def test_document_root end def test_import_node - doc1 = XML::Parser.string('').parse - doc2 = XML::Parser.string('').parse + doc1 = LibXML::XML::Parser.string('').parse + doc2 = LibXML::XML::Parser.string('').parse node = doc1.root.child - error = assert_raises(XML::Error) do + error = assert_raises(LibXML::XML::Error) do doc2.root << node end - assert_equal(" Nodes belong to different documents. You must first import the node by calling XML::Document.import.", + assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.", error.to_s) doc2.root << doc2.import(node) @@ -122,4 +122,10 @@ def test_import_node assert_equal("", doc2.root.to_s(:indent => false)) end + + def test_nonet + xml_string = 'onetwo' + xml = LibXML::XML::Document.string(xml_string, options: LibXML::XML::Parser::Options::NONET) + schema_document = LibXML::XML::Document.file('d:/src/libxml-ruby/test/model/atom.xml', options: LibXML::XML::Parser::Options::NONET) + end end diff --git a/test/test_document_write.rb b/test/test_document_write.rb index 462b2579..f8970ef5 100644 --- a/test/test_document_write.rb +++ b/test/test_document_write.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' require 'tmpdir' class TestDocumentWrite < Minitest::Test @@ -8,56 +8,41 @@ def setup @file_name = "model/bands.utf-8.xml" # Strip spaces to make testing easier - XML.default_keep_blanks = false + LibXML::XML.default_keep_blanks = false file = File.join(File.dirname(__FILE__), @file_name) - @doc = XML::Document.file(file) + @doc = LibXML::XML::Document.file(file) end def teardown - XML.default_keep_blanks = true + LibXML::XML.default_keep_blanks = true @doc = nil end # --- to_s tests --- def test_to_s_default # Default to_s has indentation - if defined?(Encoding) - assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", - @doc.to_s) - else - assert_equal("\n\n M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", - @doc.to_s) - end + assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", + @doc.to_s) end def test_to_s_no_global_indentation # No indentation due to global setting - XML.indent_tree_output = false + LibXML::XML.indent_tree_output = false value = @doc.to_s - if defined?(Encoding) - assert_equal(Encoding::UTF_8, value.encoding) - assert_equal("\n\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\nIron Maiden is a British heavy metal band formed in 1975.\n\n", - value) - else - assert_equal("\n\nM\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.\nIron Maiden is a British heavy metal band formed in 1975.\n\n", - value) - end + assert_equal(Encoding::UTF_8, value.encoding) + assert_equal("\n\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\nIron Maiden is a British heavy metal band formed in 1975.\n\n", + value) ensure - XML.indent_tree_output = true + LibXML::XML.indent_tree_output = true end def test_to_s_no_indentation # No indentation due to local setting value = @doc.to_s(:indent => false) - if defined?(Encoding) - assert_equal(Encoding::UTF_8, value.encoding) - assert_equal("\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n", - value) - else - assert_equal("\nM\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n", - value) - end + assert_equal(Encoding::UTF_8, value.encoding) + assert_equal("\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n", + value) end def test_to_s_encoding @@ -66,28 +51,18 @@ def test_to_s_encoding # UTF8: # ö - c3 b6 in hex, \303\266 in octal # ü - c3 bc in hex, \303\274 in octal - value = @doc.to_s(:encoding => XML::Encoding::UTF_8) - if defined?(Encoding) - assert_equal(Encoding::UTF_8, value.encoding) - assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", - value) - else - assert_equal("\n\n M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", - value) - end + value = @doc.to_s(:encoding => LibXML::XML::Encoding::UTF_8) + assert_equal(Encoding::UTF_8, value.encoding) + assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", + value) # ISO_8859_1: # ö - f6 in hex, \366 in octal # ü - fc in hex, \374 in octal - value = @doc.to_s(:encoding => XML::Encoding::ISO_8859_1) - if defined?(Encoding) - assert_equal(Encoding::ISO8859_1, value.encoding) - assert_equal("\n\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n".force_encoding(Encoding::ISO8859_1), - @doc.to_s(:encoding => XML::Encoding::ISO_8859_1)) - else - assert_equal("\n\n M\366tley Cr\374e is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", - @doc.to_s(:encoding => XML::Encoding::ISO_8859_1)) - end + value = @doc.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1) + assert_equal(Encoding::ISO8859_1, value.encoding) + assert_equal("\n\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n".force_encoding(Encoding::ISO8859_1), + @doc.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1)) # Invalid encoding error = assert_raises(ArgumentError) do @@ -103,16 +78,10 @@ def test_save_utf8 bytes = @doc.save(temp_filename) assert_equal(305, bytes) - if defined?(Encoding) - contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8) - assert_equal(Encoding::UTF_8, contents.encoding) - assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", - contents) - else - contents = File.read(temp_filename) - assert_equal("\n\n M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", - contents) - end + contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8) + assert_equal(Encoding::UTF_8, contents.encoding) + assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", + contents) ensure File.delete(temp_filename) end @@ -123,53 +92,35 @@ def test_save_utf8_no_indents bytes = @doc.save(temp_filename, :indent => false) assert_equal(298, bytes) - if defined?(Encoding) - contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8) - assert_equal("\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n", - contents) - else - contents = File.read(temp_filename) - assert_equal("\nM\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n", - contents) - end + contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8) + assert_equal("\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n", + contents) ensure File.delete(temp_filename) end def test_save_iso_8859_1 temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1.xml") - bytes = @doc.save(temp_filename, :encoding => XML::Encoding::ISO_8859_1) + bytes = @doc.save(temp_filename, :encoding => LibXML::XML::Encoding::ISO_8859_1) assert_equal(304, bytes) - if defined?(Encoding) - contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1) - assert_equal(Encoding::ISO8859_1, contents.encoding) - assert_equal("\n\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n".force_encoding(Encoding::ISO8859_1), - contents) - else - contents = File.read(temp_filename) - assert_equal("\n\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n", - contents) - end + contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1) + assert_equal(Encoding::ISO8859_1, contents.encoding) + assert_equal("\n\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n".force_encoding(Encoding::ISO8859_1), + contents) ensure File.delete(temp_filename) end def test_save_iso_8859_1_no_indent temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1_no_indent.xml") - bytes = @doc.save(temp_filename, :indent => false, :encoding => XML::Encoding::ISO_8859_1) + bytes = @doc.save(temp_filename, :indent => false, :encoding => LibXML::XML::Encoding::ISO_8859_1) assert_equal(297, bytes) - if defined?(Encoding) - contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1) - assert_equal(Encoding::ISO8859_1, contents.encoding) - assert_equal("\nM\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1), - contents) - else - contents = File.read(temp_filename) - assert_equal("\nM\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n", - contents) - end + contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1) + assert_equal(Encoding::ISO8859_1, contents.encoding) + assert_equal("\nM\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1), + contents) ensure File.delete(temp_filename) end diff --git a/test/test_dtd.rb b/test/test_dtd.rb index f2dea424..9f154bbb 100644 --- a/test/test_dtd.rb +++ b/test/test_dtd.rb @@ -1,11 +1,11 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TestDtd < Minitest::Test def setup - xp = XML::Parser.string(<<-EOS) + xp = LibXML::XML::Parser.string(<<-EOS) Colorado Lots of nice mountains @@ -19,7 +19,7 @@ def teardown end def dtd - XML::Dtd.new(<<-EOS) + LibXML::XML::Dtd.new(<<-EOS) XML::Parser::Options::DTDLOAD).parse + LibXML::XML::Parser.string(xml, :options => LibXML::XML::Parser::Options::DTDLOAD).parse assert_equal(1, errors.length) assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.", errors[0].to_s) ensure - XML.default_load_external_dtd = false - XML::Error.reset_handler + LibXML::XML.default_load_external_dtd = false + LibXML::XML::Error.reset_handler end end diff --git a/test/test_encoding.rb b/test/test_encoding.rb index 97d84279..00417018 100644 --- a/test/test_encoding.rb +++ b/test/test_encoding.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' # Code UTF8 Latin1 Hex # m 109 109 6D @@ -39,24 +39,24 @@ def load_encoding(encoding) file = file_for_encoding(encoding) # Strip spaces to make testing easier - XML.default_keep_blanks = false - @doc = XML::Document.file(file) - XML.default_keep_blanks = true + LibXML::XML.default_keep_blanks = false + @doc = LibXML::XML::Document.file(file) + LibXML::XML.default_keep_blanks = true end def test_encoding - doc = XML::Document.new - assert_equal(XML::Encoding::NONE, doc.encoding) - assert_equal(Encoding::ASCII_8BIT, doc.rb_encoding) if defined?(Encoding) + doc = LibXML::XML::Document.new + assert_equal(LibXML::XML::Encoding::NONE, doc.encoding) + assert_equal(Encoding::ASCII_8BIT, doc.rb_encoding) file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml')) - doc = XML::Document.file(file) - assert_equal(XML::Encoding::UTF_8, doc.encoding) - assert_equal(Encoding::UTF_8, doc.rb_encoding) if defined?(Encoding) + doc = LibXML::XML::Document.file(file) + assert_equal(LibXML::XML::Encoding::UTF_8, doc.encoding) + assert_equal(Encoding::UTF_8, doc.rb_encoding) - doc.encoding = XML::Encoding::ISO_8859_1 - assert_equal(XML::Encoding::ISO_8859_1, doc.encoding) - assert_equal(Encoding::ISO8859_1, doc.rb_encoding) if defined?(Encoding) + doc.encoding = LibXML::XML::Encoding::ISO_8859_1 + assert_equal(LibXML::XML::Encoding::ISO_8859_1, doc.encoding) + assert_equal(Encoding::ISO8859_1, doc.rb_encoding) end def test_no_internal_encoding_iso_8859_1 @@ -123,7 +123,7 @@ def test_internal_encoding_utf_8 end def test_encoding_conversions - assert_equal("UTF-8", XML::Encoding.to_s(XML::Encoding::UTF_8)) - assert_equal(XML::Encoding::UTF_8, XML::Encoding.from_s("UTF-8")) + assert_equal("UTF-8", LibXML::XML::Encoding.to_s(LibXML::XML::Encoding::UTF_8)) + assert_equal(LibXML::XML::Encoding::UTF_8, LibXML::XML::Encoding.from_s("UTF-8")) end end diff --git a/test/test_encoding_sax.rb b/test/test_encoding_sax.rb index 67ef0044..f1b81c6d 100644 --- a/test/test_encoding_sax.rb +++ b/test/test_encoding_sax.rb @@ -1,5 +1,5 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class SaxEncodingCallbacks attr_reader :encoding @@ -102,13 +102,13 @@ def file_for_encoding(encoding) end def test_encoding_iso_8859_1 - parser = XML::SaxParser.file(file_for_encoding(Encoding::ISO_8859_1)) + parser = LibXML::XML::SaxParser.file(file_for_encoding(Encoding::ISO_8859_1)) parser.callbacks = SaxEncodingCallbacks.new parser.parse end def test_encoding_utf8 - parser = XML::SaxParser.file(file_for_encoding(Encoding::UTF_8)) + parser = LibXML::XML::SaxParser.file(file_for_encoding(Encoding::UTF_8)) parser.callbacks = SaxEncodingCallbacks.new parser.parse end diff --git a/test/test_error.rb b/test/test_error.rb index ca25ca40..ab689b6a 100644 --- a/test/test_error.rb +++ b/test/test_error.rb @@ -1,42 +1,42 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' require 'stringio' class TestError < Minitest::Test # def test_error_codes - # assert_equal(4, XML::Error::DTD) - # assert_equal(4, XML::Error.const_get('DTD')) + # assert_equal(4, LibXML::XML::Error::DTD) + # assert_equal(4, LibXML::XML::Error.const_get('DTD')) # - # assert_equal(4, XML::Error::DOCUMENT_EMPTY) - # assert_equal(4, XML::Error.const_get('DOCUMENT_EMPTY')) + # assert_equal(4, LibXML::XML::Error::DOCUMENT_EMPTY) + # assert_equal(4, LibXML::XML::Error.const_get('DOCUMENT_EMPTY')) # end # # def test_invalid_handler # assert_raises(RuntimeError) do - # XML::Error.set_handler + # LibXML::XML::Error.set_handler # end # end # # def test_handler # exception = nil - # XML::Error.set_handler do |error| + # LibXML::XML::Error.set_handler do |error| # exception = error # end # # # Raise the error - # error = assert_raises(XML::Error) do - # XML::Reader.string('').parse + # assert_raises(LibXML::XML::Error) do + # LibXML::XML::Parser.string('').parse # end # ensure # Object.const_set(:STDERR, original_stderr) @@ -87,14 +87,14 @@ class TestError < Minitest::Test # end # # def test_no_hanlder - # XML::Error.reset_handler + # LibXML::XML::Error.reset_handler # output = StringIO.new # original_stderr = Object::STDERR # # Object.const_set(:STDERR, output) # begin - # assert_raises(XML::Error) do - # XML::Parser.string('').parse + # assert_raises(LibXML::XML::Error) do + # LibXML::XML::Parser.string('').parse # end # ensure # Object.const_set(:STDERR, original_stderr) @@ -103,41 +103,41 @@ class TestError < Minitest::Test # end # # def test_parse_error - # exception = assert_raises(XML::Error) do - # XML::Parser.string('').parse + # exception = assert_raises(LibXML::XML::Error) do + # LibXML::XML::Parser.string('').parse # end # - # assert_instance_of(XML::Error, exception) + # assert_instance_of(LibXML::XML::Error, exception) # assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", exception.message) - # assert_equal(XML::Error::PARSER, exception.domain) - # assert_equal(XML::Error::TAG_NAME_MISMATCH, exception.code) - # assert_equal(XML::Error::FATAL, exception.level) + # assert_equal(LibXML::XML::Error::PARSER, exception.domain) + # assert_equal(LibXML::XML::Error::TAG_NAME_MISMATCH, exception.code) + # assert_equal(LibXML::XML::Error::FATAL, exception.level) # assert_nil(exception.file) # assert_equal(1, exception.line) # end # # def test_xpath_error - # doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml')) + # doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml')) # - # exception = assert_raises(XML::Error) do + # exception = assert_raises(LibXML::XML::Error) do # doc.find('/foo[bar=test') # end # - # assert_instance_of(XML::Error, exception) + # assert_instance_of(LibXML::XML::Error, exception) # assert_equal("Error: Invalid predicate.", exception.message) - # assert_equal(XML::Error::XPATH, exception.domain) - # assert_equal(XML::Error::XPATH_INVALID_PREDICATE_ERROR, exception.code) - # assert_equal(XML::Error::ERROR, exception.level) + # assert_equal(LibXML::XML::Error::XPATH, exception.domain) + # assert_equal(LibXML::XML::Error::XPATH_INVALID_PREDICATE_ERROR, exception.code) + # assert_equal(LibXML::XML::Error::ERROR, exception.level) # assert_nil(exception.file) # assert_nil(nil) # end def test_double_parse - XML::Parser.register_error_handler(lambda {|msg| nil }) - parser = XML::Parser.string("something") + LibXML::XML::Parser.register_error_handler(lambda {|msg| nil }) + parser = LibXML::XML::Parser.string("something") parser.parse - error = assert_raises(XML::Error) do + error = assert_raises(LibXML::XML::Error) do # Try parsing a second time parser.parse end @@ -146,7 +146,7 @@ def test_double_parse end # def test_libxml_parser_empty_string - # xp = XML::Parser.new + # xp = LibXML::XML::Parser.new # # error = assert_raises(TypeError) do # xp.string = nil @@ -160,19 +160,19 @@ def test_double_parse # end # # def test_error_domain_to_s - # exception = assert_raises(XML::Error) do - # XML::Parser.string('').parse + # exception = assert_raises(LibXML::XML::Error) do + # LibXML::XML::Parser.string('').parse # end # - # assert_equal(XML::Error::PARSER, exception.domain) + # assert_equal(LibXML::XML::Error::PARSER, exception.domain) # assert_equal("PARSER",exception.domain_to_s) # end # # def test_error_code_to_s - # exception = assert_raises(XML::Error) do - # XML::Parser.string('').parse + # exception = assert_raises(LibXML::XML::Error) do + # LibXML::XML::Parser.string('').parse # end - # assert_equal(XML::Error::ENTITYREF_SEMICOL_MISSING, exception.code) + # assert_equal(LibXML::XML::Error::ENTITYREF_SEMICOL_MISSING, exception.code) # assert_equal("ENTITYREF_SEMICOL_MISSING",exception.code_to_s) # end end diff --git a/test/test_helper.rb b/test/test_helper.rb index a152ad90..b1b72cce 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,13 +2,6 @@ # To make testing/debugging easier, test within this source tree versus an installed gem -dir = File.dirname(__FILE__) -root = File.expand_path(File.join(dir, '..')) -lib = File.expand_path(File.join(root, 'lib')) -ext = File.expand_path(File.join(root, 'ext', 'libxml')) - -$LOAD_PATH << lib -$LOAD_PATH << ext - -require 'xml' +require 'bundler/setup' require 'minitest/autorun' +require 'libxml-ruby' diff --git a/test/test_html_parser.rb b/test/test_html_parser.rb index c8e39413..aa3cda2a 100644 --- a/test/test_html_parser.rb +++ b/test/test_html_parser.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' require 'stringio' class HTMLParserTest < Minitest::Test @@ -10,15 +10,15 @@ def html_file # ----- Sources ------ def test_file - xp = XML::HTMLParser.file(html_file) - assert_instance_of(XML::HTMLParser, xp) + xp = LibXML::XML::HTMLParser.file(html_file) + assert_instance_of(LibXML::XML::HTMLParser, xp) doc = xp.parse refute_nil(doc) end def test_noexistent_file - error = assert_raises(XML::Error) do - XML::HTMLParser.file('i_dont_exist.xml') + error = assert_raises(LibXML::XML::Error) do + LibXML::XML::HTMLParser.file('i_dont_exist.xml') end assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s) @@ -26,7 +26,7 @@ def test_noexistent_file def test_nil_file error = assert_raises(TypeError) do - XML::HTMLParser.file(nil) + LibXML::XML::HTMLParser.file(nil) end assert_match(/nil into String/, error.to_s) @@ -34,11 +34,11 @@ def test_nil_file def test_io File.open(html_file) do |io| - xp = XML::HTMLParser.io(io) - assert_instance_of(XML::HTMLParser, xp) + xp = LibXML::XML::HTMLParser.io(io) + assert_instance_of(LibXML::XML::HTMLParser, xp) doc = xp.parse - assert_instance_of(XML::Document, doc) + assert_instance_of(LibXML::XML::Document, doc) end end @@ -46,7 +46,7 @@ def test_io_gc # Test that the reader keeps a reference # to the io object file = File.open(html_file) - parser = XML::HTMLParser.io(file) + parser = LibXML::XML::HTMLParser.io(file) file = nil GC.start assert(parser.parse) @@ -54,7 +54,7 @@ def test_io_gc def test_nil_io error = assert_raises(TypeError) do - XML::HTMLParser.io(nil) + LibXML::XML::HTMLParser.io(nil) end assert_equal("Must pass in an IO object", error.to_s) @@ -63,27 +63,27 @@ def test_nil_io def test_string_io data = File.read(html_file) io = StringIO.new(data) - xp = XML::HTMLParser.io(io) - assert_instance_of(XML::HTMLParser, xp) + xp = LibXML::XML::HTMLParser.io(io) + assert_instance_of(LibXML::XML::HTMLParser, xp) doc = xp.parse - assert_instance_of(XML::Document, doc) + assert_instance_of(LibXML::XML::Document, doc) end def test_string str = '

hi

' - xp = XML::HTMLParser.string(str) + xp = LibXML::XML::HTMLParser.string(str) - assert_instance_of(XML::HTMLParser, xp) - assert_instance_of(XML::HTMLParser, xp) + assert_instance_of(LibXML::XML::HTMLParser, xp) + assert_instance_of(LibXML::XML::HTMLParser, xp) doc = xp.parse - assert_instance_of(XML::Document, doc) + assert_instance_of(LibXML::XML::Document, doc) end def test_nil_string error = assert_raises(TypeError) do - XML::HTMLParser.string(nil) + LibXML::XML::HTMLParser.string(nil) end assert_equal("wrong argument type nil (expected String)", error.to_s) @@ -98,26 +98,26 @@ def test_parse Hello
World EOS - parser = XML::HTMLParser.string(html, :options => XML::HTMLParser::Options::NOBLANKS) + parser = LibXML::XML::HTMLParser.string(html, :options => LibXML::XML::HTMLParser::Options::NOBLANKS) doc = parser.parse - assert_instance_of XML::Document, doc + assert_instance_of LibXML::XML::Document, doc root = doc.root - assert_instance_of XML::Node, root + assert_instance_of LibXML::XML::Node, root assert_equal 'html', root.name head = root.child - assert_instance_of XML::Node, head + assert_instance_of LibXML::XML::Node, head assert_equal 'head', head.name meta = head.child - assert_instance_of XML::Node, meta + assert_instance_of LibXML::XML::Node, meta assert_equal 'meta', meta.name assert_equal 'keywords', meta[:name] assert_equal 'nasty', meta[:content] body = head.next - assert_instance_of XML::Node, body + assert_instance_of LibXML::XML::Node, body assert_equal 'body', body.name hello = body.child @@ -125,21 +125,21 @@ def test_parse # cant figure our why or how, so this skips it if there hello = hello.child if hello.name == "p" - assert_instance_of XML::Node, hello + assert_instance_of LibXML::XML::Node, hello assert_equal 'Hello', hello.content br = hello.next - assert_instance_of XML::Node, br + assert_instance_of LibXML::XML::Node, br assert_equal 'br', br.name world = br.next - assert_instance_of XML::Node, world + assert_instance_of LibXML::XML::Node, world assert_equal 'World', world.content end def test_no_implied html = "hello world" - parser = XML::HTMLParser.string(html, :options => XML::HTMLParser::Options::NOIMPLIED) + parser = LibXML::XML::HTMLParser.string(html, :options => LibXML::XML::HTMLParser::Options::NOIMPLIED) doc = parser.parse assert_equal("

#{html}

", doc.root.to_s) end @@ -156,7 +156,7 @@ def test_comment def test_open_many_files file = File.expand_path(File.join(File.dirname(__FILE__), 'model/ruby-lang.html')) 1000.times do - XML::HTMLParser.file(file).parse + LibXML::XML::HTMLParser.file(file).parse end end end diff --git a/test/test_html_parser_context.rb b/test/test_html_parser_context.rb index b32d11d2..abbc7f5c 100644 --- a/test/test_html_parser_context.rb +++ b/test/test_html_parser_context.rb @@ -1,23 +1,23 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TestHtmlParserContext < Minitest::Test def test_default_options - context = XML::HTMLParser::Context.new + context = LibXML::XML::HTMLParser::Context.new assert_equal(0, context.options) end def test_no_options - context = XML::HTMLParser::Context.new + context = LibXML::XML::HTMLParser::Context.new context.options = 0 assert_equal(0, context.options) end def test_options - context = XML::HTMLParser::Context.new - context.options = XML::HTMLParser::Options::NOERROR - assert_equal(XML::HTMLParser::Options::NOERROR, context.options) + context = LibXML::XML::HTMLParser::Context.new + context.options = LibXML::XML::HTMLParser::Options::NOERROR + assert_equal(LibXML::XML::HTMLParser::Options::NOERROR, context.options) end end \ No newline at end of file diff --git a/test/test_namespace.rb b/test/test_namespace.rb index 6094e37b..a2c97d5f 100644 --- a/test/test_namespace.rb +++ b/test/test_namespace.rb @@ -1,12 +1,12 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TestNS < Minitest::Test def setup file = File.join(File.dirname(__FILE__), 'model/soap.xml') - @doc = XML::Document.file(file) + @doc = LibXML::XML::Document.file(file) end def teardown @@ -14,46 +14,46 @@ def teardown end def test_create_ns - node = XML::Node.new('foo') - ns = XML::Namespace.new(node, 'my_namepace', 'http://www.mynamespace.com') + node = LibXML::XML::Node.new('foo') + ns = LibXML::XML::Namespace.new(node, 'my_namepace', 'http://www.mynamespace.com') assert_equal(ns.prefix, 'my_namepace') assert_equal(ns.href, 'http://www.mynamespace.com') end def test_create_default_ns - node = XML::Node.new('foo') - ns = XML::Namespace.new(node, nil, 'http://www.mynamespace.com') + node = LibXML::XML::Node.new('foo') + ns = LibXML::XML::Namespace.new(node, nil, 'http://www.mynamespace.com') assert_nil(ns.prefix) assert_equal(ns.href, 'http://www.mynamespace.com') end def test_create_unbound_ns error = assert_raises(TypeError) do - XML::Namespace.new(nil, 'my_namepace', 'http://www.mynamespace.com') + LibXML::XML::Namespace.new(nil, 'my_namepace', 'http://www.mynamespace.com') end assert_equal('wrong argument type nil (expected Data)', error.to_s) end def test_duplicate_ns - node = XML::Node.new('foo') - XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com') - assert_raises(XML::Error) do - XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com') + node = LibXML::XML::Node.new('foo') + LibXML::XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com') + assert_raises(LibXML::XML::Error) do + LibXML::XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com') end end def test_eql - node = XML::Node.new('Envelope') + node = LibXML::XML::Node.new('Envelope') assert(node.namespaces.namespace.eql?(node.namespaces.namespace)) end def test_equal - node1 = XML::Node.new('Envelope') - ns1 = XML::Namespace.new(node1, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') + node1 = LibXML::XML::Node.new('Envelope') + ns1 = LibXML::XML::Namespace.new(node1, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') - node2 = XML::Node.new('Envelope') - ns2 = XML::Namespace.new(node2, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') + node2 = LibXML::XML::Node.new('Envelope') + ns2 = LibXML::XML::Namespace.new(node2, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') assert(ns1 == ns2) end diff --git a/test/test_namespaces.rb b/test/test_namespaces.rb index 16a547f7..0e5aa99f 100644 --- a/test/test_namespaces.rb +++ b/test/test_namespaces.rb @@ -1,12 +1,12 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TestNamespaces < Minitest::Test def setup file = File.join(File.dirname(__FILE__), 'model/soap.xml') - @doc = XML::Document.file(file) + @doc = LibXML::XML::Document.file(file) end def teardown @@ -28,10 +28,10 @@ def test_namespace_attr end def test_set_namespace_node - node = XML::Node.new('Envelope') + node = LibXML::XML::Node.new('Envelope') assert_equal('', node.to_s) - ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') + ns = LibXML::XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') assert_equal("", node.to_s) assert_nil(node.namespaces.namespace) @@ -43,16 +43,16 @@ def test_set_namespace_node def test_set_namespace_attribute # Create node - node = XML::Node.new('Envelope') + node = LibXML::XML::Node.new('Envelope') assert_equal('', node.to_s) # Create attribute - attr = XML::Attr.new(node, "encodingStyle", "http://www.w3.org/2001/12/soap-encoding") + attr = LibXML::XML::Attr.new(node, "encodingStyle", "http://www.w3.org/2001/12/soap-encoding") assert_equal('', node.to_s) # Create namespace attribute - ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') + ns = LibXML::XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') assert_equal('', node.to_s) assert_nil(node.namespaces.namespace) @@ -71,19 +71,19 @@ def test_set_namespace_attribute end def test_define_namespace - node = XML::Node.new('Envelope') + node = LibXML::XML::Node.new('Envelope') assert_equal('', node.to_s) - XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') + LibXML::XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') assert_equal("", node.to_s) assert_nil(node.namespaces.namespace) end def test_define_default_namespace - node = XML::Node.new('Envelope') + node = LibXML::XML::Node.new('Envelope') assert_equal('', node.to_s) - XML::Namespace.new(node, nil, 'http://schemas.xmlsoap.org/soap/envelope/') + LibXML::XML::Namespace.new(node, nil, 'http://schemas.xmlsoap.org/soap/envelope/') assert_equal("", node.to_s) # This seems wrong, but appears to be the way libxml works assert_nil(node.namespaces.namespace) @@ -97,27 +97,27 @@ def test_namespaces assert_equal(5, namespaces.length) namespace = namespaces[0] - assert_instance_of(XML::Namespace, namespace) + assert_instance_of(LibXML::XML::Namespace, namespace) assert_nil(namespace.prefix) assert_equal('http://services.somewhere.com', namespace.href) namespace = namespaces[1] - assert_instance_of(XML::Namespace, namespace) + assert_instance_of(LibXML::XML::Namespace, namespace) assert_equal('ns1', namespace.prefix) assert_equal('http://domain.somewhere.com', namespace.href) namespace = namespaces[2] - assert_instance_of(XML::Namespace, namespace) + assert_instance_of(LibXML::XML::Namespace, namespace) assert_equal('soap', namespace.prefix) assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href) namespace = namespaces[3] - assert_instance_of(XML::Namespace, namespace) + assert_instance_of(LibXML::XML::Namespace, namespace) assert_equal('xsd', namespace.prefix) assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href) namespace = namespaces[4] - assert_instance_of(XML::Namespace, namespace) + assert_instance_of(LibXML::XML::Namespace, namespace) assert_equal('xsi', namespace.prefix) assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href) end @@ -127,17 +127,17 @@ def test_namespace_definitions assert_equal(3, ns_defs.size) namespace = ns_defs[0] - assert_instance_of(XML::Namespace, namespace) + assert_instance_of(LibXML::XML::Namespace, namespace) assert_equal('soap', namespace.prefix) assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href) namespace = ns_defs[1] - assert_instance_of(XML::Namespace, namespace) + assert_instance_of(LibXML::XML::Namespace, namespace) assert_equal('xsd', namespace.prefix) assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href) namespace = ns_defs[2] - assert_instance_of(XML::Namespace, namespace) + assert_instance_of(LibXML::XML::Namespace, namespace) assert_equal('xsi', namespace.prefix) assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href) @@ -147,7 +147,7 @@ def test_namespace_definitions assert_equal(1, ns_defs.size) namespace = ns_defs[0] - assert_instance_of(XML::Namespace, namespace) + assert_instance_of(LibXML::XML::Namespace, namespace) assert_nil(namespace.prefix) assert_equal('http://services.somewhere.com', namespace.href) end @@ -155,7 +155,7 @@ def test_namespace_definitions def test_find_by_prefix namespace = @doc.root.namespaces.find_by_prefix('soap') - assert_instance_of(XML::Namespace, namespace) + assert_instance_of(LibXML::XML::Namespace, namespace) assert_equal('soap', namespace.prefix) assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href) end @@ -168,7 +168,7 @@ def test_find_default_ns :ns1 => 'http://services.somewhere.com') namespace = node.namespaces.find_by_prefix(nil) - assert_instance_of(XML::Namespace, namespace) + assert_instance_of(LibXML::XML::Namespace, namespace) assert_nil(namespace.prefix) assert_equal('http://services.somewhere.com', namespace.href) end @@ -179,19 +179,19 @@ def test_find_ns_by_href namespace = node.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/') - assert_instance_of(XML::Namespace, namespace) + assert_instance_of(LibXML::XML::Namespace, namespace) assert_equal('soap', namespace.prefix) assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href) end def test_default_namespace - doc = XML::Document.string('') + doc = LibXML::XML::Document.string('') ns = doc.root.namespaces.default assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/') end def test_default_prefix - doc = XML::Document.string('') + doc = LibXML::XML::Document.string('') doc.root.namespaces.default_prefix = 'soap' node = doc.root.find_first('/soap:Envelope') diff --git a/test/test_node.rb b/test/test_node.rb index 5dcf6e8a..5a1ce4d7 100644 --- a/test/test_node.rb +++ b/test/test_node.rb @@ -1,19 +1,19 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TestNode < Minitest::Test def setup @file_name = "model/bands.utf-8.xml" # Strip spaces to make testing easier - XML.default_keep_blanks = false + LibXML::XML.default_keep_blanks = false file = File.join(File.dirname(__FILE__), @file_name) - @doc = XML::Document.file(file) + @doc = LibXML::XML::Document.file(file) end def teardown - XML.default_keep_blanks = true + LibXML::XML.default_keep_blanks = true @doc = nil end @@ -23,52 +23,48 @@ def nodes end def test_doc_class - assert_instance_of(XML::Document, @doc) + assert_instance_of(LibXML::XML::Document, @doc) end def test_doc_node_type - assert_equal XML::Node::DOCUMENT_NODE, @doc.node_type + assert_equal LibXML::XML::Node::DOCUMENT_NODE, @doc.node_type end def test_root_class - assert_instance_of(XML::Node, @doc.root) + assert_instance_of(LibXML::XML::Node, @doc.root) end def test_root_node_type - assert_equal XML::Node::ELEMENT_NODE, @doc.root.node_type + assert_equal LibXML::XML::Node::ELEMENT_NODE, @doc.root.node_type end def test_node_class for n in nodes - assert_instance_of(XML::Node, n) + assert_instance_of(LibXML::XML::Node, n) end end def test_context node = @doc.root context = node.context - assert_instance_of(XML::XPath::Context, context) + assert_instance_of(LibXML::XML::XPath::Context, context) end def test_find - assert_instance_of(XML::XPath::Object, self.nodes) + assert_instance_of(LibXML::XML::XPath::Object, self.nodes) end def test_node_child_get assert_instance_of(TrueClass, @doc.root.child?) - assert_instance_of(XML::Node, @doc.root.child) + assert_instance_of(LibXML::XML::Node, @doc.root.child) - if defined?(Encoding) - assert_equal(Encoding::UTF_8, @doc.root.child.name.encoding) - assert_equal("m\u00F6tley_cr\u00FCe", @doc.root.child.name) - else - assert_equal("m\303\266tley_cr\303\274e", @doc.root.child.name) - end + assert_equal(Encoding::UTF_8, @doc.root.child.name.encoding) + assert_equal("m\u00F6tley_cr\u00FCe", @doc.root.child.name) end def test_node_doc for n in nodes - assert_instance_of(XML::Document, n.doc) if n.document? + assert_instance_of(LibXML::XML::Document, n.doc) if n.document? end end @@ -80,7 +76,7 @@ def test_name def test_node_find nodes = @doc.root.find('./fixnum') for node in nodes - assert_instance_of(XML::Node, node) + assert_instance_of(LibXML::XML::Node, node) end end @@ -96,7 +92,7 @@ def test_equality assert(node_a.eql?(node_b)) file = File.join(File.dirname(__FILE__), @file_name) - doc2 = XML::Document.file(file) + doc2 = LibXML::XML::Document.file(file) node_a2 = doc2.find_first('*[@country]') @@ -107,8 +103,8 @@ def test_equality end def test_equality_2 - parent = XML::Node.new('parent') - child = XML::Node.new('child') + parent = LibXML::XML::Node.new('parent') + child = LibXML::XML::Node.new('child') parent << child node_a = child.parent @@ -139,7 +135,7 @@ def test_content end def test_base - doc = XML::Parser.string('').parse + doc = LibXML::XML::Parser.string('').parse assert_nil(doc.root.base_uri) end @@ -152,7 +148,7 @@ def test_base # def test_output_escaping text = 'if (a < b || b > c) { return "text"; }return ">>>snip<<<";' - node = XML::Parser.string(text).parse.root + node = LibXML::XML::Parser.string(text).parse.root assert_equal text, node.to_s text_noenc = 'if (a < b || b > c) { return "text"; }return ">>>snip<<<";' @@ -172,7 +168,7 @@ def test_output_escaping # Just a sanity check for output escaping. def test_output_escaping_sanity text = 'if (a < b || b > c) { return "text"; }return ">>>snip<<<";' - node = XML::Parser.string(text).parse.root + node = LibXML::XML::Parser.string(text).parse.root affected = node.find('//text()') check_escaping = lambda do |flag| @@ -205,15 +201,15 @@ def test_space_preserve node = @doc.root node.space_preserve = false - assert_equal XML::Node::SPACE_DEFAULT, node.space_preserve + assert_equal LibXML::XML::Node::SPACE_DEFAULT, node.space_preserve node.space_preserve = true - assert_equal XML::Node::SPACE_PRESERVE, node.space_preserve + assert_equal LibXML::XML::Node::SPACE_PRESERVE, node.space_preserve end def test_empty text = ' ' - doc = XML::Parser.string(text).parse + doc = LibXML::XML::Parser.string(text).parse node = doc.root assert(!node.empty?) @@ -223,17 +219,17 @@ def test_empty end def test_save_no_empty_tags - node = XML::Node.new('test') + node = LibXML::XML::Node.new('test') assert_equal '', node.to_s - XML.default_save_no_empty_tags = true + LibXML::XML.default_save_no_empty_tags = true assert_equal '', node.to_s - XML.default_save_no_empty_tags = false + LibXML::XML.default_save_no_empty_tags = false end def test_set_content - node = XML::Node.new('test') + node = LibXML::XML::Node.new('test') node.content = "unescaped & string" assert_equal("unescaped & string", node.content) assert_equal("unescaped & string", node.to_s) diff --git a/test/test_node_cdata.rb b/test/test_node_cdata.rb index 7fb40436..4f378cb5 100644 --- a/test/test_node_cdata.rb +++ b/test/test_node_cdata.rb @@ -1,46 +1,46 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class CDataCommentTest < Minitest::Test def setup - xp = XML::Parser.string('') + xp = LibXML::XML::Parser.string('') @doc = xp.parse - assert_instance_of(XML::Document, @doc) + assert_instance_of(LibXML::XML::Document, @doc) @root = @doc.root end def test_node_type - cnode = XML::Node.new_cdata('test cdata') - assert_equal(XML::Node::CDATA_SECTION_NODE, cnode.node_type) + cnode = LibXML::XML::Node.new_cdata('test cdata') + assert_equal(LibXML::XML::Node::CDATA_SECTION_NODE, cnode.node_type) end def test_add_cdata - @root << XML::Node.new_cdata('mycdata') + @root << LibXML::XML::Node.new_cdata('mycdata') assert_equal '', @root.to_s.gsub(/\n\s*/,'') end def test_add_cdata_2 - @root << XML::Node.new_cdata('mycdata') + @root << LibXML::XML::Node.new_cdata('mycdata') assert_equal 'cdata', @root.child.node_type_name end def test_add_cdata_3 - @root << el = XML::Node.new_cdata('mycdata') + @root << el = LibXML::XML::Node.new_cdata('mycdata') el << "_this_is_added" assert_equal '', @root.to_s.gsub(/\n\s*/,'') end def test_attributes - cnode = XML::Node.new_cdata('test cdata') + cnode = LibXML::XML::Node.new_cdata('test cdata') assert_equal(0, cnode.attributes.length) end def test_set_cdata_attribute - cnode = XML::Node.new_cdata('test cdata') + cnode = LibXML::XML::Node.new_cdata('test cdata') # Can't create attributes on non-element nodes assert_raises(ArgumentError) do diff --git a/test/test_node_comment.rb b/test/test_node_comment.rb index 9f3359da..d910f691 100644 --- a/test/test_node_comment.rb +++ b/test/test_node_comment.rb @@ -1,30 +1,30 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class NodeCommentTest < Minitest::Test def setup - xp = XML::Parser.string('') + xp = LibXML::XML::Parser.string('') @doc = xp.parse - assert_instance_of(XML::Document, @doc) + assert_instance_of(LibXML::XML::Document, @doc) @root = @doc.root end def test_libxml_node_add_comment_01 - @root << XML::Node.new_comment('mycomment') + @root << LibXML::XML::Node.new_comment('mycomment') assert_equal '', @root.to_s.gsub(/\n\s*/,'') end def test_libxml_node_add_comment_02 - @root << XML::Node.new_comment('mycomment') + @root << LibXML::XML::Node.new_comment('mycomment') assert_equal 'comment', @root.child.node_type_name end def test_libxml_node_add_comment_03 - @root << el = XML::Node.new_comment('mycomment') + @root << el = LibXML::XML::Node.new_comment('mycomment') el << "_this_is_added" assert_equal '', @root.to_s.gsub(/\n\s*/,'') diff --git a/test/test_node_copy.rb b/test/test_node_copy.rb index 192add2c..876f804c 100644 --- a/test/test_node_copy.rb +++ b/test/test_node_copy.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' # see mailing list archive # [libxml-devel] Segmentation fault when add the cloned/copied node @@ -15,7 +15,7 @@ def setup STR - doc = XML::Parser.string(str).parse + doc = LibXML::XML::Parser.string(str).parse xpath = "//div" @div1 = doc.find(xpath).to_a[0] diff --git a/test/test_node_edit.rb b/test/test_node_edit.rb index 34657e78..67a75c02 100644 --- a/test/test_node_edit.rb +++ b/test/test_node_edit.rb @@ -1,10 +1,10 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TestNodeEdit < Minitest::Test def setup - xp = XML::Parser.string('onetwothree') + xp = LibXML::XML::Parser.string('onetwothree') @doc = xp.parse end @@ -25,37 +25,37 @@ def third_node end def test_add_next_01 - first_node.next = XML::Node.new('num', 'one-and-a-half') + first_node.next = LibXML::XML::Node.new('num', 'one-and-a-half') assert_equal('oneone-and-a-halftwothree', @doc.root.to_s.gsub(/\n\s*/,'')) end def test_add_next_02 - second_node.next = XML::Node.new('num', 'two-and-a-half') + second_node.next = LibXML::XML::Node.new('num', 'two-and-a-half') assert_equal('onetwotwo-and-a-halfthree', @doc.root.to_s.gsub(/\n\s*/,'')) end def test_add_next_03 - third_node.next = XML::Node.new('num', 'four') + third_node.next = LibXML::XML::Node.new('num', 'four') assert_equal 'onetwothreefour', @doc.root.to_s.gsub(/\n\s*/,'') end def test_add_prev_01 - first_node.prev = XML::Node.new('num', 'half') + first_node.prev = LibXML::XML::Node.new('num', 'half') assert_equal 'halfonetwothree', @doc.root.to_s.gsub(/\n\s*/,'') end def test_add_prev_02 - second_node.prev = XML::Node.new('num', 'one-and-a-half') + second_node.prev = LibXML::XML::Node.new('num', 'one-and-a-half') assert_equal 'oneone-and-a-halftwothree', @doc.root.to_s.gsub(/\n\s*/,'') end def test_add_prev_03 - third_node.prev = XML::Node.new('num', 'two-and-a-half') + third_node.prev = LibXML::XML::Node.new('num', 'two-and-a-half') assert_equal 'onetwotwo-and-a-halfthree', @doc.root.to_s.gsub(/\n\s*/,'') end @@ -67,7 +67,7 @@ def test_remove_node end def test_remove_node_gc - xp = XML::Parser.string('onetwothree') + xp = LibXML::XML::Parser.string('onetwothree') doc = xp.parse doc.root.child.remove! GC.start @@ -98,7 +98,7 @@ def test_reuse_removed_node end def test_append_existing_node - doc = XML::Parser.string('abfirstsecondcd').parse + doc = LibXML::XML::Parser.string('abfirstsecondcd').parse node1 = doc.find_first('//two') doc.root << node1 @@ -107,17 +107,17 @@ def test_append_existing_node end def test_wrong_doc - doc1 = XML::Parser.string('').parse - doc2 = XML::Parser.string('').parse + doc1 = LibXML::XML::Parser.string('').parse + doc2 = LibXML::XML::Parser.string('').parse node = doc1.root.child - error = assert_raises(XML::Error) do + error = assert_raises(LibXML::XML::Error) do doc2.root << node end GC.start - assert_equal(' Nodes belong to different documents. You must first import the node by calling XML::Document.import.', + assert_equal(' Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.', error.to_s) end @@ -127,7 +127,7 @@ def test_merge # Read in 500 documents 500.times do - documents << XML::Parser.string(File.read(File.join(File.dirname(__FILE__), 'model', 'merge_bug_data.xml'))).parse + documents << LibXML::XML::Parser.string(File.read(File.join(File.dirname(__FILE__), 'model', 'merge_bug_data.xml'))).parse end master_doc = documents.shift @@ -145,7 +145,7 @@ def test_merge end def test_append_chain - node = XML::Node.new('foo') << XML::Node.new('bar') << "bars contents" + node = LibXML::XML::Node.new('foo') << LibXML::XML::Node.new('bar') << "bars contents" assert_equal('bars contents', node.to_s) end diff --git a/test/test_node_pi.rb b/test/test_node_pi.rb index 3c4770c0..acbc413e 100644 --- a/test/test_node_pi.rb +++ b/test/test_node_pi.rb @@ -1,36 +1,36 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class NodePiTest < Minitest::Test def setup - xp = XML::Parser.string('') + xp = LibXML::XML::Parser.string('') @doc = xp.parse - assert_instance_of(XML::Document, @doc) + assert_instance_of(LibXML::XML::Document, @doc) @root = @doc.root end def test_libxml_node_add_pi_01 - @root << XML::Node.new_pi('mypi') + @root << LibXML::XML::Node.new_pi('mypi') assert_equal '', @root.to_s.gsub(/\n\s*/,'') end def test_libxml_node_add_pi_02 - @root << XML::Node.new_pi('mypi') + @root << LibXML::XML::Node.new_pi('mypi') assert_equal 'pi', @root.child.node_type_name end def test_libxml_node_add_pi_03 - @root << el = XML::Node.new_pi('mypi') + @root << el = LibXML::XML::Node.new_pi('mypi') el << "_this_is_added" assert_equal '', @root.to_s.gsub(/\n\s*/,'') end def test_libxml_node_add_pi_04 - @root << XML::Node.new_pi('mypi','mycontent') + @root << LibXML::XML::Node.new_pi('mypi','mycontent') assert_equal '', @root.to_s.gsub(/\n\s*/,'') end diff --git a/test/test_node_text.rb b/test/test_node_text.rb index 2986c22a..3ce6daee 100644 --- a/test/test_node_text.rb +++ b/test/test_node_text.rb @@ -1,17 +1,17 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TestTextNode < Minitest::Test def test_content - node = XML::Node.new_text('testdata') - assert_instance_of(XML::Node, node) + node = LibXML::XML::Node.new_text('testdata') + assert_instance_of(LibXML::XML::Node, node) assert_equal('testdata', node.content) end def test_invalid_content error = assert_raises(TypeError) do - XML::Node.new_text(nil) + LibXML::XML::Node.new_text(nil) end assert_equal('wrong argument type nil (expected String)', error.to_s) end @@ -27,7 +27,7 @@ def test_output_escaping textnoenc = 'if (a < b || c > d) return "e";' text = "if (a < b || c > d) return \"e\";" - node = XML::Node.new_text(textnoenc) + node = LibXML::XML::Node.new_text(textnoenc) assert node.output_escaping? assert_equal text, node.to_s @@ -46,7 +46,7 @@ def test_output_escaping # Just a sanity check for output escaping. def test_output_escaping_sanity - node = XML::Node.new_text('testdata') + node = LibXML::XML::Node.new_text('testdata') assert_equal 'text', node.name assert node.output_escaping? diff --git a/test/test_node_write.rb b/test/test_node_write.rb index c5ccc859..45afe8ec 100644 --- a/test/test_node_write.rb +++ b/test/test_node_write.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TestNodeWrite < Minitest::Test def setup @@ -8,24 +8,24 @@ def setup end def teardown - XML.default_keep_blanks = true + LibXML::XML.default_keep_blanks = true @doc = nil end def load_encoding(name) - @encoding = Encoding.find(name) if defined?(Encoding) + @encoding = Encoding.find(name) @file_name = "model/bands.#{name.downcase}.xml" # Strip spaces to make testing easier - XML.default_keep_blanks = false + LibXML::XML.default_keep_blanks = false file = File.join(File.dirname(__FILE__), @file_name) - @doc = XML::Document.file(file) + @doc = LibXML::XML::Document.file(file) end def test_to_s_default # Default to_s has indentation node = @doc.root - assert_equal(Encoding::UTF_8, node.to_s.encoding) if defined?(Encoding) + assert_equal(Encoding::UTF_8, node.to_s.encoding) assert_equal("\n M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n", node.to_s) end @@ -33,11 +33,11 @@ def test_to_s_default def test_to_s_no_global_indentation # No indentation due to global setting node = @doc.root - XML.indent_tree_output = false + LibXML::XML.indent_tree_output = false assert_equal("\nM\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.\nIron Maiden is a British heavy metal band formed in 1975.\n", node.to_s) ensure - XML.indent_tree_output = true + LibXML::XML.indent_tree_output = true end def test_to_s_no_indentation @@ -61,23 +61,18 @@ def test_to_s_encoding # UTF8: # ö - c3 b6 in hex, \303\266 in octal # ü - c3 bc in hex, \303\274 in octal - value = node.to_s(:encoding => XML::Encoding::UTF_8) - assert_equal(Encoding::UTF_8, node.to_s.encoding) if defined?(Encoding) + value = node.to_s(:encoding => LibXML::XML::Encoding::UTF_8) + assert_equal(Encoding::UTF_8, node.to_s.encoding) assert_equal("\n M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n", value) # ISO_8859_1: # ö - f6 in hex, \366 in octal # ü - fc in hex, \374 in octal - value = node.to_s(:encoding => XML::Encoding::ISO_8859_1) - if defined?(Encoding) - assert_equal(Encoding::ISO8859_1, value.encoding) - assert_equal("\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1), - value) - else - assert_equal("\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n", + value = node.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1) + assert_equal(Encoding::ISO8859_1, value.encoding) + assert_equal("\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1), value) - end # Invalid encoding error = assert_raises(ArgumentError) do @@ -90,14 +85,9 @@ def test_inner_xml # Default to_s has indentation node = @doc.root - if defined?(Encoding) - assert_equal(Encoding::UTF_8, node.inner_xml.encoding) - assert_equal("M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.", - node.inner_xml) - else - assert_equal("M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.", - node.inner_xml) - end + assert_equal(Encoding::UTF_8, node.inner_xml.encoding) + assert_equal("M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.", + node.inner_xml) end # --- Debug --- diff --git a/test/test_node_xlink.rb b/test/test_node_xlink.rb index 5f9f86dd..2f168962 100644 --- a/test/test_node_xlink.rb +++ b/test/test_node_xlink.rb @@ -1,16 +1,16 @@ # encoding: UTF-8 # $Id$ -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TC_XML_Node_XLink < Minitest::Test def setup() - xp = XML::Parser.string('one') + xp = LibXML::XML::Parser.string('one') doc = xp.parse - assert_instance_of(XML::Document, doc) + assert_instance_of(LibXML::XML::Document, doc) @root = doc.root - assert_instance_of(XML::Node, @root) + assert_instance_of(LibXML::XML::Node, @root) end def teardown() @@ -19,10 +19,10 @@ def teardown() def test_xml_node_xlink() for elem in @root.find('fixnum') - assert_instance_of(XML::Node, elem) + assert_instance_of(LibXML::XML::Node, elem) assert_instance_of(TrueClass, elem.xlink?) assert_equal("simple", elem.xlink_type_name) - assert_equal(XML::Node::XLINK_TYPE_SIMPLE, elem.xlink_type) + assert_equal(LibXML::XML::Node::XLINK_TYPE_SIMPLE, elem.xlink_type) end end end diff --git a/test/test_parser.rb b/test/test_parser.rb index 53533769..2b16e9c6 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -1,47 +1,47 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' require 'stringio' class TestParser < Minitest::Test def setup - XML::Error.set_handler(&XML::Error::QUIET_HANDLER) + LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER) end # ----- Sources ------- def test_document file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml')) - parser = XML::Parser.file(file) + parser = LibXML::XML::Parser.file(file) doc = parser.parse - parser = XML::Parser.document(doc) + parser = LibXML::XML::Parser.document(doc) doc = parser.parse - assert_instance_of(XML::Document, doc) - assert_instance_of(XML::Parser::Context, parser.context) + assert_instance_of(LibXML::XML::Document, doc) + assert_instance_of(LibXML::XML::Parser::Context, parser.context) end def test_nil_document error = assert_raises(TypeError) do - XML::Parser.document(nil) + LibXML::XML::Parser.document(nil) end - assert_equal("Must pass an XML::Document object", error.to_s) + assert_equal("Must pass an LibXML::XML::Document object", error.to_s) end def test_file file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) - parser = XML::Parser.file(file) + parser = LibXML::XML::Parser.file(file) doc = parser.parse - assert_instance_of(XML::Document, doc) - assert_instance_of(XML::Parser::Context, parser.context) + assert_instance_of(LibXML::XML::Document, doc) + assert_instance_of(LibXML::XML::Parser::Context, parser.context) end def test_noexistent_file - error = assert_raises(XML::Error) do - XML::Parser.file('i_dont_exist.xml') + error = assert_raises(LibXML::XML::Error) do + LibXML::XML::Parser.file('i_dont_exist.xml') end assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s) @@ -49,7 +49,7 @@ def test_noexistent_file def test_nil_file error = assert_raises(TypeError) do - XML::Parser.file(nil) + LibXML::XML::Parser.file(nil) end assert_match(/nil into String/, error.to_s) @@ -57,15 +57,15 @@ def test_nil_file def test_file_encoding file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml')) - parser = XML::Parser.file(file, :encoding => XML::Encoding::ISO_8859_1) + parser = LibXML::XML::Parser.file(file, :encoding => LibXML::XML::Encoding::ISO_8859_1) - error = assert_raises(XML::Error) do + error = assert_raises(LibXML::XML::Error) do parser.parse end assert(error.to_s.match(/Fatal error: Extra content at the end of the document/)) - parser = XML::Parser.file(file, :encoding => XML::Encoding::UTF_8) + parser = LibXML::XML::Parser.file(file, :encoding => LibXML::XML::Encoding::UTF_8) doc = parser.parse refute_nil(doc) end @@ -73,23 +73,23 @@ def test_file_encoding def test_file_base_uri file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml')) - parser = XML::Parser.file(file) + parser = LibXML::XML::Parser.file(file) doc = parser.parse assert(doc.child.base_uri.match(/test\/model\/bands.utf-8.xml/)) - parser = XML::Parser.file(file, :base_uri => "http://libxml.org") + parser = LibXML::XML::Parser.file(file, :base_uri => "http://libxml.org") doc = parser.parse assert(doc.child.base_uri.match(/test\/model\/bands.utf-8.xml/)) end def test_io File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io| - parser = XML::Parser.io(io) - assert_instance_of(XML::Parser, parser) + parser = LibXML::XML::Parser.io(io) + assert_instance_of(LibXML::XML::Parser, parser) doc = parser.parse - assert_instance_of(XML::Document, doc) - assert_instance_of(XML::Parser::Context, parser.context) + assert_instance_of(LibXML::XML::Document, doc) + assert_instance_of(LibXML::XML::Parser::Context, parser.context) end end @@ -97,7 +97,7 @@ def test_io_gc # Test that the reader keeps a reference # to the io object file = File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) - parser = XML::Parser.io(file) + parser = LibXML::XML::Parser.io(file) file = nil GC.start assert(parser.parse) @@ -105,7 +105,7 @@ def test_io_gc def test_nil_io error = assert_raises(TypeError) do - XML::Parser.io(nil) + LibXML::XML::Parser.io(nil) end assert_equal("Must pass in an IO object", error.to_s) @@ -114,22 +114,22 @@ def test_nil_io def test_string_io data = File.read(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) string_io = StringIO.new(data) - parser = XML::Parser.io(string_io) + parser = LibXML::XML::Parser.io(string_io) doc = parser.parse - assert_instance_of(XML::Document, doc) - assert_instance_of(XML::Parser::Context, parser.context) + assert_instance_of(LibXML::XML::Document, doc) + assert_instance_of(LibXML::XML::Parser::Context, parser.context) end def test_string_io_thread thread = Thread.new do data = File.read(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) string_io = StringIO.new(data) - parser = XML::Parser.io(string_io) + parser = LibXML::XML::Parser.io(string_io) doc = parser.parse - assert_instance_of(XML::Document, doc) - assert_instance_of(XML::Parser::Context, parser.context) + assert_instance_of(LibXML::XML::Document, doc) + assert_instance_of(LibXML::XML::Parser::Context, parser.context) end thread.join @@ -140,17 +140,17 @@ def test_string_io_thread def test_string str = 'onetwo' - parser = XML::Parser.string(str) - assert_instance_of(XML::Parser, parser) + parser = LibXML::XML::Parser.string(str) + assert_instance_of(LibXML::XML::Parser, parser) doc = parser.parse - assert_instance_of(XML::Document, doc) - assert_instance_of(XML::Parser::Context, parser.context) + assert_instance_of(LibXML::XML::Document, doc) + assert_instance_of(LibXML::XML::Parser::Context, parser.context) end def test_nil_string error = assert_raises(TypeError) do - XML::Parser.string(nil) + LibXML::XML::Parser.string(nil) end assert_equal("wrong argument type nil (expected String)", error.to_s) @@ -165,30 +165,30 @@ def test_string_options EOS - XML::default_substitute_entities = false + LibXML::XML::default_substitute_entities = false # Parse normally - parser = XML::Parser.string(xml) + parser = LibXML::XML::Parser.string(xml) doc = parser.parse assert_nil(doc.child.base_uri) # Cdata section should be cdata nodes node = doc.find_first('/test/cdata').child - assert_equal(XML::Node::CDATA_SECTION_NODE, node.node_type) + assert_equal(LibXML::XML::Node::CDATA_SECTION_NODE, node.node_type) # Entities should not be subtituted node = doc.find_first('/test/entity') assert_equal('&foo;', node.child.to_s) # Parse with options - parser = XML::Parser.string(xml, :base_uri => 'http://libxml.rubyforge.org', - :options => XML::Parser::Options::NOCDATA | XML::Parser::Options::NOENT) + parser = LibXML::XML::Parser.string(xml, :base_uri => 'http://libxml.rubyforge.org', + :options => LibXML::XML::Parser::Options::NOCDATA | LibXML::XML::Parser::Options::NOENT) doc = parser.parse assert_equal(doc.child.base_uri, 'http://libxml.rubyforge.org') # Cdata section should be text nodes node = doc.find_first('/test/cdata').child - assert_equal(XML::Node::TEXT_NODE, node.node_type) + assert_equal(LibXML::XML::Node::TEXT_NODE, node.node_type) # Entities should be subtituted node = doc.find_first('/test/entity') @@ -207,9 +207,9 @@ def test_string_encoding EOS # Parse as UTF_8 - parser = XML::Parser.string(xml, :encoding => XML::Encoding::UTF_8) + parser = LibXML::XML::Parser.string(xml, :encoding => LibXML::XML::Encoding::UTF_8) - error = assert_raises(XML::Error) do + error = assert_raises(LibXML::XML::Error) do parser.parse end @@ -217,15 +217,11 @@ def test_string_encoding error.to_s) # Parse as ISO_8859_1: - parser = XML::Parser.string(xml, :encoding => XML::Encoding::ISO_8859_1) + parser = LibXML::XML::Parser.string(xml, :encoding => LibXML::XML::Encoding::ISO_8859_1) doc = parser.parse node = doc.find_first('//metal') - if defined?(Encoding) - assert_equal(Encoding::UTF_8, node.content.encoding) - assert_equal("m\303\266tley_cr\303\274e", node.content) - else - assert_equal("m\303\266tley_cr\303\274e", node.content) - end + assert_equal(Encoding::UTF_8, node.content.encoding) + assert_equal("m\303\266tley_cr\303\274e", node.content) end def test_fd_gc @@ -235,7 +231,7 @@ def test_fd_gc # re-open the same doc `limit descriptors` times. # If we make it to the end, then we've succeeded, # otherwise an exception will be thrown. - XML::Error.set_handler {|error|} + LibXML::XML::Error.set_handler {|error|} max_fd = if RUBY_PLATFORM.match(/mswin32|mswin64|mingw/i) 500 @@ -245,30 +241,30 @@ def test_fd_gc file = File.join(File.dirname(__FILE__), 'model/rubynet.xml') max_fd.times do - XML::Parser.file(file).parse + LibXML::XML::Parser.file(file).parse end - XML::Error.reset_handler {|error|} + LibXML::XML::Error.reset_handler {|error|} end def test_open_many_files file = File.expand_path(File.join(File.dirname(__FILE__), 'model/atom.xml')) 1000.times do - XML::Parser.file(file).parse + LibXML::XML::Parser.file(file).parse end end # ----- Errors ------ def test_error - error = assert_raises(XML::Error) do - XML::Parser.string('').parse + error = assert_raises(LibXML::XML::Error) do + LibXML::XML::Parser.string('').parse end refute_nil(error) - assert_kind_of(XML::Error, error) + assert_kind_of(LibXML::XML::Error, error) assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", error.message) - assert_equal(XML::Error::PARSER, error.domain) - assert_equal(XML::Error::TAG_NAME_MISMATCH, error.code) - assert_equal(XML::Error::FATAL, error.level) + assert_equal(LibXML::XML::Error::PARSER, error.domain) + assert_equal(LibXML::XML::Error::TAG_NAME_MISMATCH, error.code) + assert_equal(LibXML::XML::Error::FATAL, error.level) assert_nil(error.file) assert_equal(1, error.line) assert_equal('foo', error.str1) @@ -280,17 +276,17 @@ def test_error end def test_bad_xml - parser = XML::Parser.string('onetwo') - error = assert_raises(XML::Error) do + parser = LibXML::XML::Parser.string('onetwo') + error = assert_raises(LibXML::XML::Error) do refute_nil(parser.parse) end refute_nil(error) - assert_kind_of(XML::Error, error) + assert_kind_of(LibXML::XML::Error, error) assert_equal("Fatal error: Extra content at the end of the document at :1.", error.message) - assert_equal(XML::Error::PARSER, error.domain) - assert_equal(XML::Error::DOCUMENT_END, error.code) - assert_equal(XML::Error::FATAL, error.level) + assert_equal(LibXML::XML::Error::PARSER, error.domain) + assert_equal(LibXML::XML::Error::DOCUMENT_END, error.code) + assert_equal(LibXML::XML::Error::FATAL, error.level) assert_nil(error.file) assert_equal(1, error.line) assert_nil(error.str1) @@ -306,20 +302,20 @@ def test_errors_from_background_thread background_errors = [] begin - XML::Error.set_handler do |error| + LibXML::XML::Error.set_handler do |error| errors << error end - parser = XML::Parser.string("") + parser = LibXML::XML::Parser.string("") thread = Thread.new do - XML::Error.set_handler do |error| + LibXML::XML::Error.set_handler do |error| background_errors << error end parser.parse rescue nil end thread.join ensure - XML::Error.set_handler(&XML::Error::QUIET_HANDLER) + LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER) end assert_equal(errors.size, 0) diff --git a/test/test_parser_context.rb b/test/test_parser_context.rb index 2fe333c8..2587b5e2 100644 --- a/test/test_parser_context.rb +++ b/test/test_parser_context.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TestParserContext < Minitest::Test @@ -12,9 +12,9 @@ def test_string EOS - context = XML::Parser::Context.string(xml) - assert_instance_of(XML::Parser::Context, context) - assert_equal(XML::Encoding::NONE, context.encoding) + context = LibXML::XML::Parser::Context.string(xml) + assert_instance_of(LibXML::XML::Parser::Context, context) + assert_equal(LibXML::XML::Encoding::NONE, context.encoding) assert_nil(context.base_uri) end @@ -26,11 +26,11 @@ def test_encoding EOS - context = XML::Parser::Context.string(xml) - assert_equal(XML::Encoding::NONE, context.encoding) + context = LibXML::XML::Parser::Context.string(xml) + assert_equal(LibXML::XML::Encoding::NONE, context.encoding) - context.encoding = XML::Encoding::ISO_8859_1 - assert_equal(XML::Encoding::ISO_8859_1, context.encoding) + context.encoding = LibXML::XML::Encoding::ISO_8859_1 + assert_equal(LibXML::XML::Encoding::ISO_8859_1, context.encoding) end def test_invalid_encoding @@ -41,7 +41,7 @@ def test_invalid_encoding EOS - context = XML::Parser::Context.string(xml) + context = LibXML::XML::Parser::Context.string(xml) error = assert_raises(ArgumentError) do context.encoding = -999 @@ -57,7 +57,7 @@ def test_base_uri EOS - context = XML::Parser::Context.string(xml) + context = LibXML::XML::Parser::Context.string(xml) assert_nil(context.base_uri) context.base_uri = 'http://libxml.rubyforge.org' @@ -66,25 +66,25 @@ def test_base_uri def test_string_empty error = assert_raises(TypeError) do - XML::Parser::Context.string(nil) + LibXML::XML::Parser::Context.string(nil) end assert_equal("wrong argument type nil (expected String)", error.to_s) error = assert_raises(ArgumentError) do - XML::Parser::Context.string('') + LibXML::XML::Parser::Context.string('') end assert_equal("Must specify a string with one or more characters", error.to_s) end def test_well_formed - parser = XML::Parser.string("") + parser = LibXML::XML::Parser.string("") parser.parse assert(parser.context.well_formed?) end def test_not_well_formed - parser = XML::Parser.string("") - assert_raises(XML::Error) do + parser = LibXML::XML::Parser.string("") + assert_raises(LibXML::XML::Error) do parser.parse end assert(!parser.context.well_formed?) @@ -92,34 +92,34 @@ def test_not_well_formed def test_version_info file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml')) - parser = XML::Parser.file(file) + parser = LibXML::XML::Parser.file(file) assert_nil(parser.context.version) parser.parse assert_equal("1.0", parser.context.version) end def test_depth - context = XML::Parser::Context.new + context = LibXML::XML::Parser::Context.new assert_instance_of(Integer, context.depth) end def test_disable_sax - context = XML::Parser::Context.new + context = LibXML::XML::Parser::Context.new assert(!context.disable_sax?) end def test_docbook - context = XML::Parser::Context.new + context = LibXML::XML::Parser::Context.new assert(!context.docbook?) end def test_html - context = XML::Parser::Context.new + context = LibXML::XML::Parser::Context.new assert(!context.html?) end def test_keep_blanks - context = XML::Parser::Context.new + context = LibXML::XML::Parser::Context.new if context.keep_blanks? assert_instance_of(TrueClass, context.keep_blanks?) else @@ -134,11 +134,11 @@ def test_num_chars end def test_replace_entities - context = XML::Parser::Context.new + context = LibXML::XML::Parser::Context.new assert(!context.replace_entities?) -# context.options = 1 - # assert(context.replace_entities?) + context.options = LibXML::XML::Parser::Options::NOENT + assert(context.replace_entities?) context.options = 0 assert(!context.replace_entities?) @@ -148,24 +148,24 @@ def test_replace_entities end def test_space_depth - context = XML::Parser::Context.new + context = LibXML::XML::Parser::Context.new assert_equal(1, context.space_depth) end def test_subset_external - context = XML::Parser::Context.new + context = LibXML::XML::Parser::Context.new assert(!context.subset_external?) end def test_data_directory_get - context = XML::Parser::Context.new + context = LibXML::XML::Parser::Context.new assert_nil(context.data_directory) end def test_parse_error - xp = XML::Parser.string('') + xp = LibXML::XML::Parser.string('') - assert_raises(XML::Error) do + assert_raises(LibXML::XML::Error) do xp.parse end @@ -175,7 +175,7 @@ def test_parse_error assert_equal(0, context.depth) assert_equal(true, context.disable_sax?) assert_equal(false, context.docbook?) - assert_equal(XML::Encoding::NONE, context.encoding) + assert_equal(LibXML::XML::Encoding::NONE, context.encoding) assert_equal(76, context.errno) assert_equal(false, context.html?) assert_equal(5, context.io_max_num_streams) diff --git a/test/test_properties.rb b/test/test_properties.rb index fd055abd..9a409bfa 100644 --- a/test/test_properties.rb +++ b/test/test_properties.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' # attributes is deprecated - use attributes instead. @@ -8,7 +8,7 @@ class Testattributes < Minitest::Test def setup() - xp = XML::Parser.string('onetwo') + xp = LibXML::XML::Parser.string('onetwo') @doc = xp.parse end @@ -19,20 +19,20 @@ def teardown() def test_traversal attributes = @doc.root.attributes - assert_instance_of(XML::Attributes, attributes) + assert_instance_of(LibXML::XML::Attributes, attributes) attribute = attributes.first assert_equal('uga', attribute.name) assert_equal('booga', attribute.value) attribute = attribute.next - assert_instance_of(XML::Attr, attribute) + assert_instance_of(LibXML::XML::Attr, attribute) assert_equal('foo', attribute.name) assert_equal('bar', attribute.value) end def test_no_attributes attributes = @doc.root.child.attributes - assert_instance_of(XML::Attributes, attributes) + assert_instance_of(LibXML::XML::Attributes, attributes) assert_equal(0, attributes.length) end end diff --git a/test/test_reader.rb b/test/test_reader.rb index 10f2fd3e..ace19b19 100644 --- a/test/test_reader.rb +++ b/test/test_reader.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' require 'stringio' class TestReader < Minitest::Test @@ -19,60 +19,60 @@ def verify_simple(reader) assert(!reader.read) # Check what was read - expected = [XML::Reader::TYPE_PROCESSING_INSTRUCTION, - XML::Reader::TYPE_ELEMENT, - XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, - XML::Reader::TYPE_COMMENT, - XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, - XML::Reader::TYPE_ELEMENT, - XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, - XML::Reader::TYPE_ELEMENT, - XML::Reader::TYPE_CDATA, - XML::Reader::TYPE_END_ELEMENT, - XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, - XML::Reader::TYPE_ELEMENT, - XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, - XML::Reader::TYPE_ELEMENT, - XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, - XML::Reader::TYPE_ELEMENT, - XML::Reader::TYPE_TEXT, - XML::Reader::TYPE_END_ELEMENT, - XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, - XML::Reader::TYPE_END_ELEMENT, - XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, - XML::Reader::TYPE_END_ELEMENT, - XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, - XML::Reader::TYPE_END_ELEMENT, - XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, - XML::Reader::TYPE_END_ELEMENT] + expected = [LibXML::XML::Reader::TYPE_PROCESSING_INSTRUCTION, + LibXML::XML::Reader::TYPE_ELEMENT, + LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, + LibXML::XML::Reader::TYPE_COMMENT, + LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, + LibXML::XML::Reader::TYPE_ELEMENT, + LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, + LibXML::XML::Reader::TYPE_ELEMENT, + LibXML::XML::Reader::TYPE_CDATA, + LibXML::XML::Reader::TYPE_END_ELEMENT, + LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, + LibXML::XML::Reader::TYPE_ELEMENT, + LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, + LibXML::XML::Reader::TYPE_ELEMENT, + LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, + LibXML::XML::Reader::TYPE_ELEMENT, + LibXML::XML::Reader::TYPE_TEXT, + LibXML::XML::Reader::TYPE_END_ELEMENT, + LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, + LibXML::XML::Reader::TYPE_END_ELEMENT, + LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, + LibXML::XML::Reader::TYPE_END_ELEMENT, + LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, + LibXML::XML::Reader::TYPE_END_ELEMENT, + LibXML::XML::Reader::TYPE_SIGNIFICANT_WHITESPACE, + LibXML::XML::Reader::TYPE_END_ELEMENT] assert_equal(expected, node_types) end def test_document - reader = XML::Reader.document(XML::Document.file(XML_FILE)) + reader = LibXML::XML::Reader.document(LibXML::XML::Document.file(XML_FILE)) verify_simple(reader) end def test_file - reader = XML::Reader.file(XML_FILE) + reader = LibXML::XML::Reader.file(XML_FILE) verify_simple(reader) end def test_invalid_file - assert_raises(XML::Error) do - XML::Reader.file('/does/not/exist') + assert_raises(LibXML::XML::Error) do + LibXML::XML::Reader.file('/does/not/exist') end end def test_string - reader = XML::Reader.string(File.read(XML_FILE)) + reader = LibXML::XML::Reader.string(File.read(XML_FILE)) verify_simple(reader) end def test_io File.open(XML_FILE, 'rb') do |io| - reader = XML::Reader.io(io) + reader = LibXML::XML::Reader.io(io) verify_simple(reader) end end @@ -81,7 +81,7 @@ def test_io_gc # Test that the reader keeps a reference # to the io object file = File.open(XML_FILE, 'rb') - reader = XML::Reader.io(file) + reader = LibXML::XML::Reader.io(file) file = nil GC.start assert(reader.read) @@ -90,21 +90,21 @@ def test_io_gc def test_string_io data = File.read(XML_FILE) string_io = StringIO.new(data) - reader = XML::Reader.io(string_io) + reader = LibXML::XML::Reader.io(string_io) verify_simple(reader) end def test_error - reader = XML::Reader.string('") + parser = LibXML::XML::Reader.string("") assert(parser.read) assert_equal('foo', parser.name) assert_equal('1', parser['x']) @@ -116,7 +116,7 @@ def test_attr end def test_move_attr - reader = XML::Reader.string('') + reader = LibXML::XML::Reader.string('') assert(reader.read) # assert(reader.read) # @@ -134,7 +134,7 @@ def test_move_attr end def test_get_attr - reader = XML::Reader.string('') + reader = LibXML::XML::Reader.string('') assert(reader.read) # assert(reader.read) # @@ -148,24 +148,24 @@ def test_get_attr end def test_value - parser = XML::Reader.string("123") + parser = LibXML::XML::Reader.string("123") assert(parser.read) assert_equal('foo', parser.name) assert_nil(parser.value) 3.times do |i| assert(parser.read) - assert_equal(XML::Reader::TYPE_ELEMENT, parser.node_type) + assert_equal(LibXML::XML::Reader::TYPE_ELEMENT, parser.node_type) assert_equal('bar', parser.name) assert(parser.read) - assert_equal(XML::Reader::TYPE_TEXT, parser.node_type) + assert_equal(LibXML::XML::Reader::TYPE_TEXT, parser.node_type) assert_equal((i + 1).to_s, parser.value) assert(parser.read) - assert_equal(XML::Reader::TYPE_END_ELEMENT, parser.node_type) + assert_equal(LibXML::XML::Reader::TYPE_END_ELEMENT, parser.node_type) end end def test_expand - reader = XML::Reader.file(XML_FILE) + reader = LibXML::XML::Reader.file(XML_FILE) reader.read.to_s reader.read @@ -177,7 +177,7 @@ def test_expand end def test_expand_find - reader = XML::Reader.file(XML_FILE) + reader = LibXML::XML::Reader.file(XML_FILE) reader.read.to_s reader.read @@ -195,7 +195,7 @@ def test_expand_find end def test_expand_invalid - reader = XML::Reader.file(XML_FILE) + reader = LibXML::XML::Reader.file(XML_FILE) # Expand a node before one has been read node = reader.expand @@ -203,7 +203,7 @@ def test_expand_invalid end def test_expand_should_be_invalid - reader = XML::Reader.file(XML_FILE) + reader = LibXML::XML::Reader.file(XML_FILE) # Read a couple of nodes reader.read @@ -222,7 +222,7 @@ def test_expand_should_be_invalid def test_expand_incorrectly_use_returned_node file = File.join(File.dirname(__FILE__), 'model/cwm_1_0.xml') - reader = XML::Reader.file(file) + reader = LibXML::XML::Reader.file(file) nodes = Array.new while reader.read @@ -242,27 +242,27 @@ def test_expand_incorrectly_use_returned_node end def test_mode - reader = XML::Reader.string('') - assert_equal(XML::Reader::MODE_INITIAL, reader.read_state) + reader = LibXML::XML::Reader.string('') + assert_equal(LibXML::XML::Reader::MODE_INITIAL, reader.read_state) reader.read - assert_equal(XML::Reader::MODE_EOF, reader.read_state) + assert_equal(LibXML::XML::Reader::MODE_EOF, reader.read_state) end def test_bytes_consumed - reader = XML::Reader.file(XML_FILE) + reader = LibXML::XML::Reader.file(XML_FILE) reader.read - assert_equal(416, reader.byte_consumed) + assert_equal(428, reader.byte_consumed) end def test_node - XML.default_line_numbers = true - reader = XML::Reader.file(XML_FILE) + LibXML::XML.default_line_numbers = true + reader = LibXML::XML::Reader.file(XML_FILE) # first try to get a node assert_nil(reader.node) reader.read - assert_instance_of(XML::Node, reader.node) + assert_instance_of(LibXML::XML::Node, reader.node) end def test_base_uri @@ -270,7 +270,7 @@ def test_base_uri # ö - c3 b6 in hex, \303\266 in octal # ü - c3 bc in hex, \303\274 in octal xml = "\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n" - reader = XML::Reader.string(xml, :base_uri => "http://libxml.rubyforge.org") + reader = LibXML::XML::Reader.string(xml, :base_uri => "http://libxml.rubyforge.org") reader.read assert_equal(reader.base_uri, "http://libxml.rubyforge.org") @@ -287,22 +287,22 @@ def test_options EOS # Parse normally - reader = XML::Reader.string(xml) + reader = LibXML::XML::Reader.string(xml) reader.read # foo reader.read # test reader.read # text reader.read # cdata reader.read # cdata-section - assert_equal(XML::Node::CDATA_SECTION_NODE, reader.node_type) + assert_equal(LibXML::XML::Node::CDATA_SECTION_NODE, reader.node_type) # Convert cdata section to text - reader = XML::Reader.string(xml, :options => XML::Parser::Options::NOCDATA) + reader = LibXML::XML::Reader.string(xml, :options => LibXML::XML::Parser::Options::NOCDATA) reader.read # foo reader.read # test reader.read # text reader.read # cdata reader.read # cdata-section - assert_equal(XML::Node::TEXT_NODE, reader.node_type) + assert_equal(LibXML::XML::Node::TEXT_NODE, reader.node_type) end def test_encoding @@ -311,24 +311,19 @@ def test_encoding # ü - fc in hex, \374 in octal xml = "\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n" - reader = XML::Reader.string(xml, :encoding => XML::Encoding::ISO_8859_1) + reader = LibXML::XML::Reader.string(xml, :encoding => LibXML::XML::Encoding::ISO_8859_1) reader.read - if defined?(Encoding) - assert_equal(Encoding::ISO8859_1, reader.read_outer_xml.encoding) - assert_equal(Encoding::ISO8859_1, reader.read_inner_xml.encoding) - assert_equal(Encoding::ISO8859_1, reader.read_string.encoding) - - assert_equal("\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1), - reader.read_outer_xml) - assert_equal("\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1), - reader.read_inner_xml) - assert_equal("\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1), - reader.read_string) - else - assert_equal("\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n", - reader.read_outer_xml) - end + assert_equal(Encoding::ISO8859_1, reader.read_outer_xml.encoding) + assert_equal(Encoding::ISO8859_1, reader.read_inner_xml.encoding) + assert_equal(Encoding::ISO8859_1, reader.read_string.encoding) + + assert_equal("\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1), + reader.read_outer_xml) + assert_equal("\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1), + reader.read_inner_xml) + assert_equal("\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1), + reader.read_string) end def test_invalid_encoding @@ -337,8 +332,8 @@ def test_invalid_encoding # ü - fc in hex, \374 in octal xml = "\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n" - reader = XML::Reader.string(xml) - error = assert_raises(XML::Error) do + reader = LibXML::XML::Reader.string(xml) + error = assert_raises(LibXML::XML::Error) do reader.read end @@ -348,10 +343,10 @@ def test_invalid_encoding end def test_file_encoding - reader = XML::Reader.file(XML_FILE) + reader = LibXML::XML::Reader.file(XML_FILE) reader.read - assert_equal(XML::Encoding::UTF_8, reader.encoding) - assert_equal(Encoding::UTF_8, reader.value.encoding) if defined?(Encoding) + assert_equal(LibXML::XML::Encoding::UTF_8, reader.encoding) + assert_equal(Encoding::UTF_8, reader.value.encoding) end def test_string_encoding @@ -359,10 +354,10 @@ def test_string_encoding # ö - f6 in hex, \366 in octal # ü - fc in hex, \374 in octal xml = "\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n" - reader = XML::Reader.string(xml, :encoding => XML::Encoding::ISO_8859_1) + reader = LibXML::XML::Reader.string(xml, :encoding => LibXML::XML::Encoding::ISO_8859_1) reader.read # Encoding is always null for strings, very annoying! - assert_equal(reader.encoding, XML::Encoding::NONE) + assert_equal(reader.encoding, LibXML::XML::Encoding::NONE) end end diff --git a/test/test_relaxng.rb b/test/test_relaxng.rb index b912fe47..01cb2146 100644 --- a/test/test_relaxng.rb +++ b/test/test_relaxng.rb @@ -1,12 +1,12 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TestRelaxNG < Minitest::Test def setup file = File.join(File.dirname(__FILE__), 'model/shiporder.xml') - @doc = XML::Document.file(file) + @doc = LibXML::XML::Document.file(file) end def teardown @@ -14,12 +14,12 @@ def teardown end def relaxng - document = XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.rng')) - XML::RelaxNG.document(document) + document = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.rng')) + LibXML::XML::RelaxNG.document(document) end def test_from_doc - assert_instance_of(XML::RelaxNG, relaxng) + assert_instance_of(LibXML::XML::RelaxNG, relaxng) end def test_valid @@ -27,19 +27,19 @@ def test_valid end def test_invalid - new_node = XML::Node.new('invalid', 'this will mess up validation') + new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation') @doc.root << new_node - error = assert_raises(XML::Error) do + error = assert_raises(LibXML::XML::Error) do @doc.validate_relaxng(relaxng) end refute_nil(error) - assert_kind_of(XML::Error, error) + assert_kind_of(LibXML::XML::Error, error) assert(error.message.match(/Error: Did not expect element invalid there/)) - assert_equal(XML::Error::RELAXNGV, error.domain) - assert_equal(XML::Error::LT_IN_ATTRIBUTE, error.code) - assert_equal(XML::Error::ERROR, error.level) + assert_equal(LibXML::XML::Error::RELAXNGV, error.domain) + assert_equal(LibXML::XML::Error::LT_IN_ATTRIBUTE, error.code) + assert_equal(LibXML::XML::Error::ERROR, error.level) assert(error.file.match(/shiporder\.xml/)) assert_nil(error.line) assert_equal('invalid', error.str1) diff --git a/test/test_sax_parser.rb b/test/test_sax_parser.rb index 275e3d50..bdb2e3e4 100644 --- a/test/test_sax_parser.rb +++ b/test/test_sax_parser.rb @@ -1,16 +1,16 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' require 'stringio' class DocTypeCallback - include XML::SaxParser::Callbacks + include LibXML::XML::SaxParser::Callbacks def on_start_element(element, attributes) end end class TestCaseCallbacks - include XML::SaxParser::Callbacks + include LibXML::XML::SaxParser::Callbacks attr_accessor :result @@ -119,20 +119,20 @@ def verify(parser) end def test_file - parser = XML::SaxParser.file(saxtest_file) + parser = LibXML::XML::SaxParser.file(saxtest_file) parser.callbacks = TestCaseCallbacks.new parser.parse verify(parser) end def test_file_no_callbacks - parser = XML::SaxParser.file(saxtest_file) + parser = LibXML::XML::SaxParser.file(saxtest_file) assert_equal true, parser.parse end def test_noexistent_file - error = assert_raises(XML::Error) do - XML::SaxParser.file('i_dont_exist.xml') + error = assert_raises(LibXML::XML::Error) do + LibXML::XML::SaxParser.file('i_dont_exist.xml') end assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s) @@ -140,7 +140,7 @@ def test_noexistent_file def test_nil_file error = assert_raises(TypeError) do - XML::SaxParser.file(nil) + LibXML::XML::SaxParser.file(nil) end assert_match(/nil into String/, error.to_s) @@ -148,7 +148,7 @@ def test_nil_file def test_io File.open(saxtest_file) do |file| - parser = XML::SaxParser.io(file) + parser = LibXML::XML::SaxParser.io(file) parser.callbacks = TestCaseCallbacks.new parser.parse verify(parser) @@ -157,7 +157,7 @@ def test_io def test_nil_io error = assert_raises(TypeError) do - XML::HTMLParser.io(nil) + LibXML::XML::HTMLParser.io(nil) end assert_equal("Must pass in an IO object", error.to_s) @@ -165,13 +165,13 @@ def test_nil_io def test_string_no_callbacks xml = File.read(saxtest_file) - parser = XML::SaxParser.string(xml) + parser = LibXML::XML::SaxParser.string(xml) assert_equal true, parser.parse end def test_string xml = File.read(saxtest_file) - parser = XML::SaxParser.string(xml) + parser = LibXML::XML::SaxParser.string(xml) parser.callbacks = TestCaseCallbacks.new parser.parse verify(parser) @@ -180,7 +180,7 @@ def test_string def test_string_io xml = File.read(saxtest_file) io = StringIO.new(xml) - parser = XML::SaxParser.io(io) + parser = LibXML::XML::SaxParser.io(io) parser.callbacks = TestCaseCallbacks.new parser.parse @@ -189,7 +189,7 @@ def test_string_io def test_nil_string error = assert_raises(TypeError) do - XML::SaxParser.string(nil) + LibXML::XML::SaxParser.string(nil) end assert_equal("wrong argument type nil (expected String)", error.to_s) @@ -203,7 +203,7 @@ def test_doctype a1 EOS - parser = XML::SaxParser.string(xml) + parser = LibXML::XML::SaxParser.string(xml) parser.callbacks = DocTypeCallback.new doc = parser.parse refute_nil(doc) @@ -217,7 +217,7 @@ def test_parse_warning EOS - parser = XML::SaxParser.string(xml) + parser = LibXML::XML::SaxParser.string(xml) parser.callbacks = TestCaseCallbacks.new parser.parse @@ -239,10 +239,10 @@ def test_parse_error xml = <<-EOS EOS - parser = XML::SaxParser.string(xml) + parser = LibXML::XML::SaxParser.string(xml) parser.callbacks = TestCaseCallbacks.new - error = assert_raises(XML::Error) do + error = assert_raises(LibXML::XML::Error) do parser.parse end @@ -254,21 +254,21 @@ def test_parse_error assert_equal("start_element: Results, attr: {}", result[i+=1]) assert_equal("start_element_ns: Results, attr: {}, prefix: , uri: , ns: {}", result[i+=1]) assert_equal("characters: \n", result[i+=1]) - assert_equal("error: Fatal error: Premature end of data in tag Results line 1 at :2.", result[i+=1]) + assert_equal("error: Fatal error: EndTag: ' EOS - parser = XML::SaxParser.string(xml) + parser = LibXML::XML::SaxParser.string(xml) parser.callbacks = TestCaseCallbacks.new - error = assert_raises(XML::Error) do + error = assert_raises(LibXML::XML::Error) do parser.parse end assert_equal("Fatal error: xmlParseEntityRef: no name at :5.", error.to_s) diff --git a/test/test_schema.rb b/test/test_schema.rb index 6d57bdd1..eb82d046 100644 --- a/test/test_schema.rb +++ b/test/test_schema.rb @@ -1,11 +1,11 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TestSchema < Minitest::Test def setup file = File.join(File.dirname(__FILE__), 'model/shiporder.xml') - @doc = XML::Document.file(file) + @doc = LibXML::XML::Document.file(file) end def teardown @@ -13,17 +13,17 @@ def teardown end def schema - document = XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.xsd')) - XML::Schema.document(document) + document = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.xsd')) + LibXML::XML::Schema.document(document) end def check_error(error) refute_nil(error) assert(error.message.match(/Error: Element 'invalid': This element is not expected. Expected is \( item \)/)) - assert_kind_of(XML::Error, error) - assert_equal(XML::Error::SCHEMASV, error.domain) - assert_equal(XML::Error::SCHEMAV_ELEMENT_CONTENT, error.code) - assert_equal(XML::Error::ERROR, error.level) + assert_kind_of(LibXML::XML::Error, error) + assert_equal(LibXML::XML::Error::SCHEMASV, error.domain) + assert_equal(LibXML::XML::Error::SCHEMAV_ELEMENT_CONTENT, error.code) + assert_equal(LibXML::XML::Error::ERROR, error.level) assert(error.file.match(/shiporder.xml/)) if error.file assert_nil(error.str1) assert_nil(error.str2) @@ -33,7 +33,7 @@ def check_error(error) end def test_load_from_doc - assert_instance_of(XML::Schema, schema) + assert_instance_of(LibXML::XML::Schema, schema) end def test_doc_valid @@ -41,10 +41,10 @@ def test_doc_valid end def test_doc_invalid - new_node = XML::Node.new('invalid', 'this will mess up validation') + new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation') @doc.root << new_node - error = assert_raises(XML::Error) do + error = assert_raises(LibXML::XML::Error) do @doc.validate_schema(schema) end @@ -55,7 +55,7 @@ def test_doc_invalid end def test_reader_valid - reader = XML::Reader.string(@doc.to_s) + reader = LibXML::XML::Reader.string(@doc.to_s) assert(reader.schema_validate(schema)) while reader.read @@ -65,13 +65,13 @@ def test_reader_valid def test_reader_invalid # Set error handler errors = Array.new - XML::Error.set_handler do |error| + LibXML::XML::Error.set_handler do |error| errors << error end - new_node = XML::Node.new('invalid', 'this will mess up validation') + new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation') @doc.root << new_node - reader = XML::Reader.string(@doc.to_s) + reader = LibXML::XML::Reader.string(@doc.to_s) # Set a schema assert(reader.schema_validate(schema)) @@ -85,7 +85,7 @@ def test_reader_invalid check_error(error) assert_equal(21, error.line) ensure - XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER) + LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER) end @@ -93,19 +93,19 @@ def test_reader_invalid def test_elements assert_instance_of(Hash, schema.elements) assert_equal(1, schema.elements.length) - assert_instance_of(XML::Schema::Element, schema.elements['shiporder']) + assert_instance_of(LibXML::XML::Schema::Element, schema.elements['shiporder']) end def test_types assert_instance_of(Hash, schema.types) assert_equal(1, schema.types.length) - assert_instance_of(XML::Schema::Type, schema.types['shiporder']) + assert_instance_of(LibXML::XML::Schema::Type, schema.types['shiporder']) end def test_imported_types assert_instance_of(Hash, schema.imported_types) assert_equal(1, schema.imported_types.length) - assert_instance_of(XML::Schema::Type, schema.types['shiporder']) + assert_instance_of(LibXML::XML::Schema::Type, schema.types['shiporder']) end def test_namespaces @@ -119,11 +119,11 @@ def test_schema_type assert_equal('shiporder', type.name) assert_nil(type.namespace) assert_equal("Shiporder type documentation", type.annotation) - assert_instance_of(XML::Node, type.node) - assert_equal(XML::Schema::Types::XML_SCHEMA_TYPE_COMPLEX, type.kind) - assert_instance_of(XML::Schema::Type, type.base) + assert_instance_of(LibXML::XML::Node, type.node) + assert_equal(LibXML::XML::Schema::Types::XML_SCHEMA_TYPE_COMPLEX, type.kind) + assert_instance_of(LibXML::XML::Schema::Type, type.base) assert_equal("anyType", type.base.name) - assert_equal(XML::Schema::Types::XML_SCHEMA_TYPE_BASIC, type.base.kind) + assert_equal(LibXML::XML::Schema::Types::XML_SCHEMA_TYPE_BASIC, type.base.kind) assert_instance_of(Hash, type.elements) assert_equal(3, type.elements.length) @@ -149,7 +149,7 @@ def test_schema_attributes assert_instance_of(Array, type.attributes) assert_equal(2, type.attributes.length) - assert_instance_of(XML::Schema::Attribute, type.attributes.first) + assert_instance_of(LibXML::XML::Schema::Attribute, type.attributes.first) end def test_schema_attribute diff --git a/test/test_suite.rb b/test/test_suite.rb index ba1026ce..5f4c63e7 100644 --- a/test/test_suite.rb +++ b/test/test_suite.rb @@ -40,10 +40,9 @@ require './test_xpath_expression' require './test_xpointer' -if defined?(Encoding) - require './test_encoding' - require './test_encoding_sax' -end +require './test_encoding' +require './test_encoding_sax' + # Compatibility require './test_properties' require './test_deprecated_require' \ No newline at end of file diff --git a/test/test_traversal.rb b/test/test_traversal.rb index ba92f3e7..a1842e7d 100644 --- a/test/test_traversal.rb +++ b/test/test_traversal.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TestTranversal < Minitest::Test ROOT_NODES_LENGTH = 27 @@ -8,7 +8,7 @@ class TestTranversal < Minitest::Test def setup filename = File.join(File.dirname(__FILE__), 'model/books.xml') - @doc = XML::Document.file(filename) + @doc = LibXML::XML::Document.file(filename) end def teardown @@ -143,10 +143,10 @@ def test_next_children_equivalence end def test_doc_class - assert_instance_of(XML::Document, @doc) + assert_instance_of(LibXML::XML::Document, @doc) end def test_root_class - assert_instance_of(XML::Node, @doc.root) + assert_instance_of(LibXML::XML::Node, @doc.root) end end diff --git a/test/test_writer.rb b/test/test_writer.rb index 23884d88..f4e65380 100644 --- a/test/test_writer.rb +++ b/test/test_writer.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' require 'stringio' class TestWriter < Minitest::Test @@ -8,33 +8,56 @@ class TestWriter < Minitest::Test XSL_URI = 'http://www.w3.org/1999/XSL/Transform' def test_generic_failure - writer = XML::Writer.string + writer = LibXML::XML::Writer.string writer.start_document assert(!writer.end_element) writer.end_document end def test_empty_doc - writer = XML::Writer.string - document writer + writer = LibXML::XML::Writer.string + document(writer) assert_equal(writer.result.strip!, '') - writer = XML::Writer.string - document writer, { :encoding => XML::Encoding::ISO_8859_1 } + writer = LibXML::XML::Writer.string + document(writer, :encoding => LibXML::XML::Encoding::ISO_8859_1) assert_equal(writer.result.strip!, '') - writer = XML::Writer.string - document writer, { :standalone => 1 } + writer = LibXML::XML::Writer.string + document(writer, :standalone => 1) assert_equal(writer.result.strip!, '') - writer = XML::Writer.string - document writer, { :standalone => 1, :encoding => XML::Encoding::ISO_8859_1, :foo => :bar } + writer = LibXML::XML::Writer.string + document(writer, :standalone => 1, :encoding => LibXML::XML::Encoding::ISO_8859_1, :foo => :bar) assert_equal(writer.result.strip!, '') end + def test_file_encoding + value = "François".encode(Encoding::UTF_8) + + File.open('test.xml', 'wb', encoding: 'UTF-8') do |file| + writer = LibXML::XML::Writer::io(file) + document(writer, encoding: LibXML::XML::Encoding::UTF_8) do + writer.write_element('Name', value) + end + end + end + + def test_io_encoding + value = "François".encode(Encoding::UTF_8) + expected = "\nFrançois".encode(Encoding::UTF_8) + + io = StringIO.new + writer = LibXML::XML::Writer::io(io) + document(writer, encoding: LibXML::XML::Encoding::UTF_8) do + writer.write_element('Name', value) + end + assert_equal(expected, io.string.strip) + end + def test_single_root - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do element writer, 'root' end @@ -44,16 +67,16 @@ def test_single_root def test_pi expected = "\n" - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do assert(writer.start_pi('php')) assert(writer.write_string('echo "foo";')) assert(writer.end_pi) end assert_equal(writer.result.strip!, expected) - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do assert(writer.write_pi('php', 'echo "foo";')) end assert_equal(writer.result.strip!, expected) @@ -62,16 +85,16 @@ def test_pi def test_comment expected = "\n" - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do assert(writer.start_comment) assert(writer.write_string 'foo') assert(writer.end_comment) end assert_equal(writer.result.strip!, expected) - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do assert(writer.write_comment 'foo') end assert_equal(writer.result.strip!, expected) @@ -80,8 +103,8 @@ def test_comment def test_cdata expected = "\n]]>" - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do element writer, 'root' do assert(writer.start_cdata) assert(writer.write_string '') @@ -90,8 +113,8 @@ def test_cdata end assert_equal(writer.result.strip!, expected) - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do element writer, 'root' do assert(writer.write_cdata '') end @@ -100,14 +123,14 @@ def test_cdata end def test_write_empty_elements - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do assert(writer.write_element 'foo') end assert_equal(writer.result.strip!, "\n") - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do assert(writer.write_element_ns XSL_PREFIX, 'stylesheet', XSL_URI) end assert_equal(writer.result.strip!, "\n<" + XSL_PREFIX + ":stylesheet xmlns:xsl=\"" + XSL_URI + "\"/>") @@ -116,8 +139,8 @@ def test_write_empty_elements def test_valued_element expected = "\n123456789cueillir des cerisesnous irons au bois" - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do assert(writer.start_element 'abc') assert(writer.write_string '123') assert(writer.start_element 'def') @@ -132,8 +155,8 @@ def test_valued_element end assert_equal(writer.result.strip!, expected) - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do assert(writer.start_element 'abc') assert(writer.write_string '123') assert(writer.start_element 'def') @@ -156,8 +179,8 @@ def test_valued_element_ns "" + "" - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do assert(writer.start_element_ns XSL_PREFIX, 'stylesheet', XSL_URI) assert(writer.start_element_ns XSL_PREFIX, 'attribute-set') assert(writer.start_element_ns XSL_PREFIX, 'attribute') @@ -171,8 +194,8 @@ def test_valued_element_ns end assert_equal(writer.result.strip!, expected) - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do assert(writer.start_element_ns XSL_PREFIX, 'stylesheet', XSL_URI) assert(writer.start_element_ns XSL_PREFIX, 'attribute-set') assert(writer.write_element_ns XSL_PREFIX, 'attribute', nil, '20px') @@ -184,8 +207,8 @@ def test_valued_element_ns end def test_attribute - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do element writer, 'root' do element writer, 'child' do assert(writer.start_attribute 'foo') @@ -196,8 +219,8 @@ def test_attribute end assert_equal(writer.result.strip!, "\n") - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do element writer, 'root' do element writer, 'child' do assert(writer.write_attribute 'abc', 'def') @@ -211,8 +234,8 @@ def test_attribute def test_attribute_ns expected = "\n" - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do element writer, 'root' do element writer, 'link' do assert(writer.write_attribute_ns 'xlink', 'href', nil, 'abc') @@ -222,8 +245,8 @@ def test_attribute_ns end assert_equal(writer.result.strip!, expected) - writer = XML::Writer.string - document writer do + writer = LibXML::XML::Writer.string + document(writer) do element writer, 'root' do element writer, 'link' do assert(writer.start_attribute_ns 'xlink', 'href') @@ -239,10 +262,10 @@ def test_attribute_ns end def test_quote_char - if XML::Writer.method_defined? :set_quote_char - writer = XML::Writer.string + if LibXML::XML::Writer.method_defined? :set_quote_char + writer = LibXML::XML::Writer.string writer.set_quote_char "'" - document writer do + document(writer) do element writer, 'root' do assert(writer.start_attribute 'abc') assert(writer.write_string 'def') @@ -254,10 +277,10 @@ def test_quote_char end def test_indentation_on - if XML::Writer.method_defined? :set_indent - writer = XML::Writer.string + if LibXML::XML::Writer.method_defined? :set_indent + writer = LibXML::XML::Writer.string assert(writer.set_indent true) - document writer do + document(writer) do element writer, 'root' do element writer, 'child' do assert(writer.start_attribute 'abc') @@ -271,11 +294,11 @@ def test_indentation_on end def test_indentation_string - if XML::Writer.method_defined? :set_indent_string - writer = XML::Writer.string + if LibXML::XML::Writer.method_defined? :set_indent_string + writer = LibXML::XML::Writer.string assert(writer.set_indent true) assert(writer.set_indent_string ' ' * 4) - document writer do + document(writer) do element writer, 'root' do element writer, 'child' do assert(writer.start_attribute 'abc') @@ -289,11 +312,11 @@ def test_indentation_string end def test_dtd_declaration - writer = XML::Writer.string + writer = LibXML::XML::Writer.string dtd writer, 'html' assert_equal(writer.result, '') - writer = XML::Writer.string + writer = LibXML::XML::Writer.string dtd writer, 'html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd' assert_equal(writer.result, '') end @@ -301,7 +324,7 @@ def test_dtd_declaration def test_dtd_attlist expected = ']>' - writer = XML::Writer.string + writer = LibXML::XML::Writer.string dtd writer, 'http' do assert(writer.start_dtd_attlist 'method') assert(writer.write_string '(get|post) "get"') @@ -309,7 +332,7 @@ def test_dtd_attlist end assert_equal(writer.result, expected) - writer = XML::Writer.string + writer = LibXML::XML::Writer.string dtd writer, 'http' do assert(writer.write_dtd_attlist 'method', '(get|post) "get"') end @@ -319,7 +342,7 @@ def test_dtd_attlist def test_dtd_element expected = ']>' - writer = XML::Writer.string + writer = LibXML::XML::Writer.string dtd writer, 'html' do assert(writer.start_dtd_element 'dl') assert(writer.write_string '(dt|dd)+') @@ -327,7 +350,7 @@ def test_dtd_element end assert_equal(writer.result, expected) - writer = XML::Writer.string + writer = LibXML::XML::Writer.string dtd writer, 'html' do assert(writer.write_dtd_element 'dl', '(dt|dd)+') end @@ -338,7 +361,7 @@ def test_dtd_entity # parameterized entity expected = ']>' - writer = XML::Writer.string + writer = LibXML::XML::Writer.string dtd writer, 'html' do assert(writer.start_dtd_entity 'special.pre', true) assert(writer.write_string 'br | span | bdo | map') @@ -349,7 +372,7 @@ def test_dtd_entity end assert_equal(writer.result, expected) - writer = XML::Writer.string + writer = LibXML::XML::Writer.string dtd writer, 'html' do assert(writer.write_dtd_internal_entity 'special.pre', 'br | span | bdo | map', true) assert(writer.write_dtd_internal_entity 'special', '%special.pre; | object | img', true) @@ -359,7 +382,7 @@ def test_dtd_entity # non parameterized entity expected = ']>' - writer = XML::Writer.string + writer = LibXML::XML::Writer.string dtd writer, 'html' do assert(writer.start_dtd_entity 'Alpha') assert(writer.write_string 'Α') @@ -367,7 +390,7 @@ def test_dtd_entity end assert_equal(writer.result, expected) - writer = XML::Writer.string + writer = LibXML::XML::Writer.string dtd writer, 'html' do assert(writer.start_dtd_entity 'Alpha', false) assert(writer.write_string 'Α') @@ -375,7 +398,7 @@ def test_dtd_entity end assert_equal(writer.result, expected) - writer = XML::Writer.string + writer = LibXML::XML::Writer.string dtd writer, 'html' do assert(writer.write_dtd_internal_entity 'Alpha', 'Α', false) end @@ -383,7 +406,7 @@ def test_dtd_entity end def test_dtd_notation - writer = XML::Writer.string + writer = LibXML::XML::Writer.string dtd writer, 'pictures' do assert(writer.write_dtd_notation 'GIF89a', '-//Compuserve//NOTATION Graphics Interchange Format 89a//EN', nil) assert(writer.write_dtd_external_entity 'pictures', nil, 'images/plage.gif', 'GIF89a', false) @@ -392,19 +415,17 @@ def test_dtd_notation end def test_encoding - if defined?(Encoding) - iso = 'éloïse'.encode 'ISO-8859-1' + iso = 'éloïse'.encode 'ISO-8859-1' - writer = XML::Writer.string - document writer do - assert(writer.write_element iso) - end - assert_equal(writer.result.strip!, "\n<éloïse/>") + writer = LibXML::XML::Writer.string + document(writer) do + assert(writer.write_element iso) end + assert_equal(writer.result.strip!, "\n<éloïse/>") end def test_flush - writer = XML::Writer.string + writer = LibXML::XML::Writer.string assert(writer.start_document) assert_equal(writer.flush.strip!, '') assert(writer.start_element 'foo') @@ -417,7 +438,7 @@ def test_flush def test_nil_pe_issue expected = ']>' - writer = XML::Writer.string + writer = LibXML::XML::Writer.string dtd writer, 'html' do assert(writer.write_dtd_internal_entity 'special.pre', 'br | span | bdo | map', nil) assert(writer.write_dtd_internal_entity 'special', '%special.pre; | object | img', nil) diff --git a/test/test_xinclude.rb b/test/test_xinclude.rb index eca9ef01..1ff926f1 100644 --- a/test/test_xinclude.rb +++ b/test/test_xinclude.rb @@ -1,11 +1,11 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TestXInclude < Minitest::Test def setup - @doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/xinclude.xml')) - assert_instance_of(XML::Document, @doc) + @doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/xinclude.xml')) + assert_instance_of(LibXML::XML::Document, @doc) end def teardown diff --git a/test/test_xml.rb b/test/test_xml.rb index ce80582f..28ee2cbc 100644 --- a/test/test_xml.rb +++ b/test/test_xml.rb @@ -1,262 +1,262 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' require 'stringio' class TestXml < Minitest::Test # ----- Constants ------ def test_lib_versions - assert(XML.check_lib_versions) + assert(LibXML::XML.check_lib_versions) end def test_debug_entities - original = XML.debug_entities + original = LibXML::XML.debug_entities - XML.debug_entities = false - refute(XML.debug_entities) + LibXML::XML.debug_entities = false + refute(LibXML::XML.debug_entities) - XML.debug_entities = true - assert(XML.debug_entities) + LibXML::XML.debug_entities = true + assert(LibXML::XML.debug_entities) - XML.debug_entities = false - refute(XML.debug_entities) + LibXML::XML.debug_entities = false + refute(LibXML::XML.debug_entities) - XML.debug_entities = original + LibXML::XML.debug_entities = original end def test_default_compression - return unless XML.default_compression + return unless LibXML::XML.default_compression - original = XML.default_compression + original = LibXML::XML.default_compression 0.upto(9) do |i| - XML.default_compression = i - assert_equal(i, XML.default_compression) + LibXML::XML.default_compression = i + assert_equal(i, LibXML::XML.default_compression) end 9.downto(0) do |i| - assert_equal(i, XML.default_compression = i) - assert_equal(i, XML.default_compression) + assert_equal(i, LibXML::XML.default_compression = i) + assert_equal(i, LibXML::XML.default_compression) end 0.downto(-10) do |i| - assert_equal(i, XML.default_compression = i) - assert_equal(0, XML.default_compression) + assert_equal(i, LibXML::XML.default_compression = i) + assert_equal(0, LibXML::XML.default_compression) end 10.upto(20) do |i| - assert_equal(i, XML.default_compression = i) - assert_equal(9, XML.default_compression) + assert_equal(i, LibXML::XML.default_compression = i) + assert_equal(9, LibXML::XML.default_compression) end - XML.default_compression = original + LibXML::XML.default_compression = original end def test_default_keep_blanks - original = XML.default_keep_blanks + original = LibXML::XML.default_keep_blanks - XML.default_keep_blanks = false - refute(XML.default_keep_blanks) - assert_equal(XML::Parser::Options::NOBLANKS, XML.default_options) + LibXML::XML.default_keep_blanks = false + refute(LibXML::XML.default_keep_blanks) + assert_equal(LibXML::XML::Parser::Options::NOBLANKS, LibXML::XML.default_options) - XML.default_keep_blanks = true - assert(XML.default_keep_blanks) - assert_equal(0, XML.default_options) + LibXML::XML.default_keep_blanks = true + assert(LibXML::XML.default_keep_blanks) + assert_equal(0, LibXML::XML.default_options) - XML.default_keep_blanks = original + LibXML::XML.default_keep_blanks = original end def test_default_line_numbers - original = XML.default_line_numbers + original = LibXML::XML.default_line_numbers - XML.default_line_numbers = false - refute(XML.default_line_numbers) + LibXML::XML.default_line_numbers = false + refute(LibXML::XML.default_line_numbers) - XML.default_line_numbers = true - assert(XML.default_line_numbers) + LibXML::XML.default_line_numbers = true + assert(LibXML::XML.default_line_numbers) - XML.default_line_numbers = false - refute(XML.default_line_numbers) + LibXML::XML.default_line_numbers = false + refute(LibXML::XML.default_line_numbers) - XML.default_line_numbers = original + LibXML::XML.default_line_numbers = original end def test_default_substitute_entities - original = XML.default_substitute_entities + original = LibXML::XML.default_substitute_entities - XML.default_substitute_entities = false - refute(XML.default_substitute_entities) - assert_equal(0, XML.default_options) + LibXML::XML.default_substitute_entities = false + refute(LibXML::XML.default_substitute_entities) + assert_equal(0, LibXML::XML.default_options) - XML.default_substitute_entities = true - assert(XML.default_substitute_entities) - assert_equal(XML::Parser::Options::NOENT, XML.default_options) + LibXML::XML.default_substitute_entities = true + assert(LibXML::XML.default_substitute_entities) + assert_equal(LibXML::XML::Parser::Options::NOENT, LibXML::XML.default_options) - XML.default_substitute_entities = false - refute(XML.default_substitute_entities) + LibXML::XML.default_substitute_entities = false + refute(LibXML::XML.default_substitute_entities) - XML.default_substitute_entities = original + LibXML::XML.default_substitute_entities = original end def test_default_tree_indent_string - original = XML.default_tree_indent_string + original = LibXML::XML.default_tree_indent_string - s = XML.default_tree_indent_string + s = LibXML::XML.default_tree_indent_string assert_instance_of(String, s) assert_equal(' ', s) - XML.default_tree_indent_string = 'uga' - s = XML.default_tree_indent_string + LibXML::XML.default_tree_indent_string = 'uga' + s = LibXML::XML.default_tree_indent_string assert_instance_of(String, s) assert_equal('uga', s) - XML.default_tree_indent_string = ' ' - s = XML.default_tree_indent_string + LibXML::XML.default_tree_indent_string = ' ' + s = LibXML::XML.default_tree_indent_string assert_instance_of(String, s) assert_equal(' ', s) - XML.default_tree_indent_string = original + LibXML::XML.default_tree_indent_string = original end def test_default_validity_checking - original = XML.default_validity_checking + original = LibXML::XML.default_validity_checking - XML.default_validity_checking = false - refute(XML.default_validity_checking) - assert_equal(0, XML.default_options) + LibXML::XML.default_validity_checking = false + refute(LibXML::XML.default_validity_checking) + assert_equal(0, LibXML::XML.default_options) - XML.default_validity_checking = true - assert(XML.default_validity_checking) - assert_equal(XML::Parser::Options::DTDVALID, XML.default_options) + LibXML::XML.default_validity_checking = true + assert(LibXML::XML.default_validity_checking) + assert_equal(LibXML::XML::Parser::Options::DTDVALID, LibXML::XML.default_options) - XML.default_validity_checking = false - refute(XML.default_validity_checking) + LibXML::XML.default_validity_checking = false + refute(LibXML::XML.default_validity_checking) - XML.default_validity_checking = original + LibXML::XML.default_validity_checking = original end def test_default_warnings - original = XML.default_warnings + original = LibXML::XML.default_warnings - XML.default_warnings = false - refute(XML.default_warnings) - assert_equal(XML::Parser::Options::NOWARNING, XML.default_options) + LibXML::XML.default_warnings = false + refute(LibXML::XML.default_warnings) + assert_equal(LibXML::XML::Parser::Options::NOWARNING, LibXML::XML.default_options) - XML.default_warnings = true - assert(XML.default_warnings) - assert_equal(0, XML.default_options) + LibXML::XML.default_warnings = true + assert(LibXML::XML.default_warnings) + assert_equal(0, LibXML::XML.default_options) - XML.default_warnings = false - refute(XML.default_warnings) + LibXML::XML.default_warnings = false + refute(LibXML::XML.default_warnings) - XML.default_warnings = original + LibXML::XML.default_warnings = original end def test_enabled_automata - assert(XML.enabled_automata?) + assert(LibXML::XML.enabled_automata?) end def test_enabled_c14n - assert(XML.enabled_c14n?) + assert(LibXML::XML.enabled_c14n?) end def test_enabled_catalog - assert(XML.enabled_catalog?) + assert(LibXML::XML.enabled_catalog?) end def test_enabled_debug - assert(XML.enabled_debug?) + assert(LibXML::XML.enabled_debug?) end def test_enabled_docbook - assert(XML.enabled_docbook?) + assert(LibXML::XML.enabled_docbook?) end def test_enabled_ftp - assert(XML.enabled_ftp?) + assert(LibXML::XML.enabled_ftp?) end def test_enabled_http - assert(XML.enabled_http?) + assert(LibXML::XML.enabled_http?) end def test_enabled_html - assert(XML.enabled_html?) + assert(LibXML::XML.enabled_html?) end def test_enabled_iconv - assert(XML.enabled_iconv?) + assert(LibXML::XML.enabled_iconv?) end def test_enabled_memory_debug - assert_equal(false, XML.enabled_memory_debug?) + assert_equal(false, LibXML::XML.enabled_memory_debug?) end def test_enabled_regexp - assert(XML.enabled_regexp?) + assert(LibXML::XML.enabled_regexp?) end def test_enabled_schemas - assert(XML.enabled_schemas?) + assert(LibXML::XML.enabled_schemas?) end def test_enabled_thread - assert(XML.enabled_thread?) + assert(LibXML::XML.enabled_thread?) end def test_enabled_unicode - assert(XML.enabled_unicode?) + assert(LibXML::XML.enabled_unicode?) end def test_enabled_xinclude - assert(XML.enabled_xinclude?) + assert(LibXML::XML.enabled_xinclude?) end def test_enabled_xpath - assert(XML.enabled_xpath?) + assert(LibXML::XML.enabled_xpath?) end def test_enabled_xpointer - assert(XML.enabled_xpointer?) + assert(LibXML::XML.enabled_xpointer?) end def test_enabled_zlib - assert(XML.enabled_zlib?.is_a?(TrueClass) || XML.enabled_zlib?.is_a?(FalseClass)) + assert(LibXML::XML.enabled_zlib?.is_a?(TrueClass) || LibXML::XML.enabled_zlib?.is_a?(FalseClass)) end def test_intent_tree_output - assert(TrueClass, XML.indent_tree_output) + assert(TrueClass, LibXML::XML.indent_tree_output) - XML.indent_tree_output = false - assert(FalseClass, XML.indent_tree_output) + LibXML::XML.indent_tree_output = false + assert(FalseClass, LibXML::XML.indent_tree_output) - XML.indent_tree_output = true - assert(TrueClass, XML.indent_tree_output) + LibXML::XML.indent_tree_output = true + assert(TrueClass, LibXML::XML.indent_tree_output) end def test_version - assert_instance_of(String, XML::VERSION) + assert_instance_of(String, LibXML::XML::VERSION) end def test_vernum - assert_instance_of(Integer, XML::VERNUM) + assert_instance_of(Integer, LibXML::XML::VERNUM) end def test_libxml_parser_features - assert_instance_of(Array, XML.features) + assert_instance_of(Array, LibXML::XML.features) end def test_default_options - assert_equal(0, XML.default_options) + assert_equal(0, LibXML::XML.default_options) end def test_default_save_no_empty_tags - original = XML.default_save_no_empty_tags + original = LibXML::XML.default_save_no_empty_tags - XML.default_save_no_empty_tags = false - refute(XML.default_save_no_empty_tags) + LibXML::XML.default_save_no_empty_tags = false + refute(LibXML::XML.default_save_no_empty_tags) - XML.default_save_no_empty_tags = true - assert(XML.default_save_no_empty_tags) + LibXML::XML.default_save_no_empty_tags = true + assert(LibXML::XML.default_save_no_empty_tags) - XML.default_save_no_empty_tags = original + LibXML::XML.default_save_no_empty_tags = original end end diff --git a/test/test_xpath.rb b/test/test_xpath.rb index 7e18dc86..75aec3d6 100644 --- a/test/test_xpath.rb +++ b/test/test_xpath.rb @@ -1,11 +1,11 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' require 'tempfile' class TestXPath < Minitest::Test def setup - @doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml')) + @doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml')) end def teardown @@ -14,14 +14,14 @@ def teardown def test_doc_find nodes = @doc.find('/soap:Envelope') - assert_instance_of(XML::XPath::Object, nodes) + assert_instance_of(LibXML::XML::XPath::Object, nodes) assert_equal(1, nodes.length) - assert_equal(nodes.xpath_type, XML::XPath::NODESET) + assert_equal(nodes.xpath_type, LibXML::XML::XPath::NODESET) end def test_doc_find_first node = @doc.find_first('/soap:Envelope/soap:Body') - assert_instance_of(XML::Node, node) + assert_instance_of(LibXML::XML::Node, node) end def test_ns @@ -33,7 +33,7 @@ def test_ns_gc _stress = GC.stress GC.stress = true - doc = XML::Document.string('') + doc = LibXML::XML::Document.string('') node = doc.root # This line segfaults on prior versions of libxml-ruby node.find("namespace::*") @@ -89,7 +89,7 @@ def test_default_ns4 def test_default_ns5 # Find all nodes with http://services.somewhere.com namespace - XML::Namespace.new(@doc.root, 'ns', 'http://services.somewhere.com') + LibXML::XML::Namespace.new(@doc.root, 'ns', 'http://services.somewhere.com') nodes = @doc.find('//ns:*') assert_equal(2, nodes.length) assert_equal('getManufacturerNamesResponse', nodes[0].name) @@ -105,10 +105,10 @@ def test_attribute_ns end def test_register_default_ns - doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/atom.xml')) + doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/atom.xml')) # No namespace has been yet defined - assert_raises(XML::Error) do + assert_raises(LibXML::XML::Error) do doc.find("atom:title") end @@ -143,7 +143,7 @@ def test_node_find_first end def test_node_no_doc - node = XML::Node.new('header', 'some content') + node = LibXML::XML::Node.new('header', 'some content') assert_raises(TypeError) do node = node.find_first('/header') end @@ -157,11 +157,11 @@ def test_memory # to the document's nodes. A segmentation fault then happens. 1000.times do - doc = XML::Document.new('1.0') - doc.root = XML::Node.new("header") + doc = LibXML::XML::Document.new('1.0') + doc.root = LibXML::XML::Node.new("header") 1000.times do - doc.root << XML::Node.new("footer") + doc.root << LibXML::XML::Node.new("footer") end doc.find('/header/footer') @@ -170,35 +170,35 @@ def test_memory # Test that document doesn't get freed before nodes def test_xpath_free - doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml')) + doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml')) nodes = doc.find('//*') GC.start assert_equal('Envelope', nodes.first.name) end def test_xpath_namespace_nodes - doc = XML::Document.string('') + doc = LibXML::XML::Document.string('') nodes = doc.find('//atom:entry|namespace::*', :atom => "http://www.w3.org/2005/Atom") assert_equal(4, nodes.length) node = nodes[0] - assert_equal(XML::Node::ELEMENT_NODE, node.node_type) + assert_equal(LibXML::XML::Node::ELEMENT_NODE, node.node_type) node = nodes[1] - assert_equal(XML::Node::NAMESPACE_DECL, node.node_type) + assert_equal(LibXML::XML::Node::NAMESPACE_DECL, node.node_type) node = nodes[2] - assert_equal(XML::Node::NAMESPACE_DECL, node.node_type) + assert_equal(LibXML::XML::Node::NAMESPACE_DECL, node.node_type) node = nodes[3] - assert_equal(XML::Node::NAMESPACE_DECL, node.node_type) + assert_equal(LibXML::XML::Node::NAMESPACE_DECL, node.node_type) end # Test to make sure we don't get nil on empty results. # This is also to test that we don't segfault due to our C code getting a NULL pointer # and not handling it properly. def test_xpath_empty_result - doc = XML::Document.string('

Welcome to XHTML land!

') + doc = LibXML::XML::Document.string('

Welcome to XHTML land!

') nodes = doc.find("//object/param[translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'wmode']") refute_nil nodes end @@ -207,13 +207,13 @@ def test_invalid_expression xml = LibXML::XML::Document.string('') # Using the expression twice used to cause a Segmentation Fault - error = assert_raises(XML::Error) do + error = assert_raises(LibXML::XML::Error) do xml.find('//a/') end assert_equal("Error: Invalid expression.", error.to_s) # Try again - this used to cause a Segmentation Fault - error = assert_raises(XML::Error) do + error = assert_raises(LibXML::XML::Error) do xml.find('//a/') end assert_equal("Error: Invalid expression.", error.to_s) diff --git a/test/test_xpath_context.rb b/test/test_xpath_context.rb index 34d03c27..2b178951 100644 --- a/test/test_xpath_context.rb +++ b/test/test_xpath_context.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' require "tempfile" class TestXPathContext < Minitest::Test @@ -11,8 +11,8 @@ class TestXPathContext < Minitest::Test NS0_URI = 'http://services.somewhere.com' def setup - doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml')) - @context = XML::XPath::Context.new(doc) + doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml')) + @context = LibXML::XML::XPath::Context.new(doc) end def teardown() @@ -79,9 +79,9 @@ def test_cache end def test_require_doc - doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml')) + doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml')) error = assert_raises(TypeError) do - @context = XML::XPath::Context.new(doc.root) + @context = LibXML::XML::XPath::Context.new(doc.root) end assert_equal("Supplied argument must be a document or node.", error.to_s) end diff --git a/test/test_xpath_expression.rb b/test/test_xpath_expression.rb index c92307aa..d8578ffb 100644 --- a/test/test_xpath_expression.rb +++ b/test/test_xpath_expression.rb @@ -1,11 +1,11 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TestXPathExpression < Minitest::Test def setup - xp = XML::Parser.string('onetwo') + xp = LibXML::XML::Parser.string('onetwo') @doc = xp.parse end @@ -14,16 +14,16 @@ def teardown end def test_nodes - expr = XML::XPath::Expression.compile('/ruby_array/fixnum') + expr = LibXML::XML::XPath::Expression.compile('/ruby_array/fixnum') set = @doc.find(expr) - assert_instance_of(XML::XPath::Object, set) + assert_instance_of(LibXML::XML::XPath::Object, set) assert_equal(2, set.size) end def test_find_class - expr = XML::XPath::Expression.new('/ruby_array/fixnum') + expr = LibXML::XML::XPath::Expression.new('/ruby_array/fixnum') set = @doc.find(expr) - assert_instance_of(XML::XPath::Object, set) + assert_instance_of(LibXML::XML::XPath::Object, set) assert_equal(2, set.size) end diff --git a/test/test_xpointer.rb b/test/test_xpointer.rb index 5a75db65..bcd65009 100644 --- a/test/test_xpointer.rb +++ b/test/test_xpointer.rb @@ -1,13 +1,13 @@ # encoding: UTF-8 -require File.expand_path('../test_helper', __FILE__) +require_relative './test_helper' class TC_XML_XPointer < Minitest::Test def setup() - xp = XML::Parser.string(']>onetwothree') + xp = LibXML::XML::Parser.string(']>onetwothree') @doc = xp.parse - assert_instance_of(XML::Document, @doc) + assert_instance_of(LibXML::XML::Document, @doc) @root = @doc.root - assert_instance_of(XML::Node, @root) + assert_instance_of(LibXML::XML::Node, @root) end def teardown() @@ -18,20 +18,20 @@ def teardown() def test_libxml_xpointer_id xptr = @root.pointer('xpointer(id("two"))') - assert_instance_of(XML::XPath::Object, xptr) + assert_instance_of(LibXML::XML::XPath::Object, xptr) xptr.each do |node| # It seems from the spec that the pointer should # be the whole node, rather than just the ID attr. assert_equal('two', node.content) - assert_instance_of(XML::Node, node) + assert_instance_of(LibXML::XML::Node, node) assert_equal('two', node['id']) end # FIXME: Not sure at all about this kind of range if ENV['NOTWORKING'] @xptr = @root.pointer('xpointer(id("two")) xpointer(id("three"))') - assert_instance_of(XML::XPath, @xptr) - assert_instance_of(XML::Node::Set, @xptr.set) + assert_instance_of(LibXML::XML::XPath, @xptr) + assert_instance_of(LibXML::XML::Node::Set, @xptr.set) assert_equal(2, @xptr.set.length) for n in @xptr.set assert_match(/two|three/, n.to_s) @@ -45,13 +45,13 @@ def test_libxml_xpointer_range() nstart = nend = nil @xptr = @root.pointer('xpointer(id("one"))').set @xptr.each{|n| nstart = n} - assert_instance_of(XML::Node, nstart) + assert_instance_of(LibXML::XML::Node, nstart) @xptr = @root.pointer('xpointer(id("three"))').set @xptr.each{|n| nend = n} - assert_instance_of(XML::Node, nend) - range = XML::XPointer.range(nstart, nend) - assert_instance_of(XML::XPath, range) - assert_instance_of(XML::Node::Set, range.set) + assert_instance_of(LibXML::XML::Node, nend) + range = LibXML::XML::XPointer.range(nstart, nend) + assert_instance_of(LibXML::XML::XPath, range) + assert_instance_of(LibXML::XML::Node::Set, range.set) for n in range.set assert_match(/one|two|three/, n.to_s) @@ -62,9 +62,9 @@ def test_libxml_xpointer_range() # def test_libxml_xpointer_start_point() # @xptr = @root.pointer('xpointer(start-point("one"))') -# assert_instance_of(XML::XPath, @xptr) +# assert_instance_of(LibXML::XML::XPath, @xptr) # set = @xptr.set -# assert_instance_of(XML::Node::Set, set) +# assert_instance_of(LibXML::XML::Node::Set, set) # for n in set # assert_match(/one|two|three/, n.to_s) # end From f48991276e99d53aea5105d065db94dac449278b Mon Sep 17 00:00:00 2001 From: Radu Preotiuc <49693472+radupr@users.noreply.github.com> Date: Tue, 27 Apr 2021 23:02:12 -0400 Subject: [PATCH 12/18] Updated libxml2 to version 2.9.10 (latest) [GDSN-998] (#7) * Misc. clean-up. * Downgraded mini_portile2 so we can use it in puddle. --- Rakefile | 21 +++++---------------- ext/libxml/extconf.rb | 17 +++++++---------- salsify_libxml_ruby.gemspec | 1 + 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/Rakefile b/Rakefile index 3221c7f2..64995843 100644 --- a/Rakefile +++ b/Rakefile @@ -18,22 +18,11 @@ spec = Gem::Specification.load("#{GEM_NAME}.gemspec") task :default => [:test] # Setup compile tasks -if RUBY_PLATFORM.match(/mswin32|mswin64|mingw32/) - Rake::ExtensionTask.new do |ext| - ext.gem_spec = spec - ext.name = SO_NAME - ext.ext_dir = "ext/libxml" - ext.lib_dir = "lib/#{RUBY_VERSION.sub(/\.\d$/, '')}" - ext.config_options << "--with-xml2-include=C:/msys64/mingw64/include/libxml2" - end -else - Rake::ExtensionTask.new do |ext| - ext.gem_spec = spec - ext.name = SO_NAME - ext.ext_dir = "ext/libxml" - ext.lib_dir = "lib/#{RUBY_VERSION.sub(/\.\d$/, '')}" - ext.config_options << "--with-xml2-include=/usr/include/libxml2" - end +Rake::ExtensionTask.new do |ext| + ext.gem_spec = spec + ext.name = SO_NAME + ext.ext_dir = "ext/libxml" + ext.lib_dir = "lib/#{RUBY_VERSION.sub(/\.\d$/, '')}" end # Setup generic gem diff --git a/ext/libxml/extconf.rb b/ext/libxml/extconf.rb index bb349dcd..a2d98160 100644 --- a/ext/libxml/extconf.rb +++ b/ext/libxml/extconf.rb @@ -1,9 +1,13 @@ #!/usr/bin/env ruby require 'mkmf' +require 'rubygems' +gem 'mini_portile2', '>= 2.4.0' # Keep this version in sync with the one in the gemspec! +require 'mini_portile2' +message "Using mini_portile2 version #{MiniPortile::VERSION}\n" -LIBXML2_VERSION = '2.9.9'.freeze -LIBXML2_SHA256 = '94fb70890143e3c6549f265cee93ec064c80a84c42ad0f23e85ee1fd6540a871'.freeze +LIBXML2_VERSION = '2.9.10'.freeze +LIBXML2_SHA256 = 'aafee193ffb8fe0c82d4afef6ef91972cbaf5feea100edc2f262750611b4be1f'.freeze def darwin? RbConfig::CONFIG['target_os'] =~ /darwin/ @@ -14,13 +18,6 @@ def crash(str) exit 1 end -# The gem version constraint in the Rakefile is not respected at install time. -# Keep this version in sync with the one in the Rakefile ! -require 'rubygems' -gem 'mini_portile2', '~> 2.4.0' -require 'mini_portile2' -message "Using mini_portile version #{MiniPortile::VERSION}\n" - if darwin? have_header('iconv.h') || crash('missing iconv.h') have_library('iconv') || crash('missing libiconv') @@ -58,7 +55,7 @@ def crash(str) FileUtils.touch checkpoint end libxml2_recipe.activate -# .activate is supposed to do this, but it doesn't +# .activate is supposed to do this, but it doesn't before mini_portile2-2.5.0, can be removed once we update. $LIBPATH = ["#{libxml2_recipe.path}/lib"] | $LIBPATH append_cflags("-I#{File.join(libxml2_recipe.path, 'include', 'libxml2')}") diff --git a/salsify_libxml_ruby.gemspec b/salsify_libxml_ruby.gemspec index 18773147..928ac6b0 100644 --- a/salsify_libxml_ruby.gemspec +++ b/salsify_libxml_ruby.gemspec @@ -37,6 +37,7 @@ Gem::Specification.new do |spec| spec.test_files = Dir.glob('test/test_*.rb') spec.required_ruby_version = '>= 2.5' + spec.add_runtime_dependency("mini_portile2", ">= 2.4.0") # keep version in sync with the one in extconf.rb spec.add_development_dependency 'salsify_gem' spec.add_development_dependency 'rake-compiler' spec.add_development_dependency 'minitest' From c8c98957203727721400dcae03723658d16ac0c9 Mon Sep 17 00:00:00 2001 From: Radu Preotiuc <49693472+radupr@users.noreply.github.com> Date: Thu, 20 May 2021 09:41:10 -0400 Subject: [PATCH 13/18] Bumped libxml2 to version 2.9.12. (#8) --- ext/libxml/extconf.rb | 8 +++----- ext/libxml/ruby_xml_version.h | 6 +++--- salsify_libxml_ruby.gemspec | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ext/libxml/extconf.rb b/ext/libxml/extconf.rb index a2d98160..27850a03 100644 --- a/ext/libxml/extconf.rb +++ b/ext/libxml/extconf.rb @@ -2,12 +2,12 @@ require 'mkmf' require 'rubygems' -gem 'mini_portile2', '>= 2.4.0' # Keep this version in sync with the one in the gemspec! +gem 'mini_portile2', '~> 2.5.0' # Keep this version in sync with the one in the gemspec! require 'mini_portile2' message "Using mini_portile2 version #{MiniPortile::VERSION}\n" -LIBXML2_VERSION = '2.9.10'.freeze -LIBXML2_SHA256 = 'aafee193ffb8fe0c82d4afef6ef91972cbaf5feea100edc2f262750611b4be1f'.freeze +LIBXML2_VERSION = '2.9.12'.freeze +LIBXML2_SHA256 = 'c8d6681e38c56f172892c85ddc0852e1fd4b53b4209e7f4ebf17f7e2eae71d92'.freeze def darwin? RbConfig::CONFIG['target_os'] =~ /darwin/ @@ -55,8 +55,6 @@ def crash(str) FileUtils.touch checkpoint end libxml2_recipe.activate -# .activate is supposed to do this, but it doesn't before mini_portile2-2.5.0, can be removed once we update. -$LIBPATH = ["#{libxml2_recipe.path}/lib"] | $LIBPATH append_cflags("-I#{File.join(libxml2_recipe.path, 'include', 'libxml2')}") have_header('libxml/parser.h') || crash('parser.h not found') diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h index 63e5b019..48fc8271 100644 --- a/ext/libxml/ruby_xml_version.h +++ b/ext/libxml/ruby_xml_version.h @@ -1,9 +1,9 @@ /* Don't nuke this block! It is used for automatically updating the * versions below. VERSION = string formatting, VERNUM = numbered * version for inline testing: increment both or none at all.*/ -#define RUBY_LIBXML_VERSION "3.2.1.1" -#define RUBY_LIBXML_VERNUM 3211 +#define RUBY_LIBXML_VERSION "3.2.1.2" +#define RUBY_LIBXML_VERNUM 3212 #define RUBY_LIBXML_VER_MAJ 3 #define RUBY_LIBXML_VER_MIN 2 #define RUBY_LIBXML_VER_MIC 1 -#define RUBY_LIBXML_VER_PATCH 1 +#define RUBY_LIBXML_VER_PATCH 2 diff --git a/salsify_libxml_ruby.gemspec b/salsify_libxml_ruby.gemspec index 928ac6b0..572f3bae 100644 --- a/salsify_libxml_ruby.gemspec +++ b/salsify_libxml_ruby.gemspec @@ -37,7 +37,7 @@ Gem::Specification.new do |spec| spec.test_files = Dir.glob('test/test_*.rb') spec.required_ruby_version = '>= 2.5' - spec.add_runtime_dependency("mini_portile2", ">= 2.4.0") # keep version in sync with the one in extconf.rb + spec.add_runtime_dependency("mini_portile2", "~> 2.5.0") # keep version in sync with the one in extconf.rb spec.add_development_dependency 'salsify_gem' spec.add_development_dependency 'rake-compiler' spec.add_development_dependency 'minitest' From c43495342ea0a29cd19187a49989bf0a4208c13b Mon Sep 17 00:00:00 2001 From: Nuno Silva Date: Mon, 2 Aug 2021 16:33:30 +0100 Subject: [PATCH 14/18] [GDSN-1143] Dependabot Migration (#9) Add the .github/dependabot.yml base configuration Co-authored-by: Nuno Silva --- .github/dependabot.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..064aada5 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,17 @@ +version: 2 +updates: + - package-ecosystem: "bundler" + directory: "/" + registries: + - rubygems-server-gems-salsify-com + schedule: + interval: daily + time: "10:00" + versioning-strategy: lockfile-only + open-pull-requests-limit: 5 +registries: + rubygems-server-gems-salsify-com: + type: rubygems-server + url: https://gems.salsify.com + username: "${{secrets.RUBYGEMS_SERVER_GEMS_SALSIFY_COM_USERNAME}}" + password: "${{secrets.RUBYGEMS_SERVER_GEMS_SALSIFY_COM_PASSWORD}}" \ No newline at end of file From 78c996dc6b1b92062977e6d0903c76385fd86e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mateus?= Date: Fri, 24 Nov 2023 12:26:43 +0000 Subject: [PATCH 15/18] Add methods to read the minOccurs and maxOccurs attributes --- ext/libxml/ruby_xml_version.h | 4 ++-- lib/libxml/schema/element.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h index 48fc8271..0cdc7f30 100644 --- a/ext/libxml/ruby_xml_version.h +++ b/ext/libxml/ruby_xml_version.h @@ -1,8 +1,8 @@ /* Don't nuke this block! It is used for automatically updating the * versions below. VERSION = string formatting, VERNUM = numbered * version for inline testing: increment both or none at all.*/ -#define RUBY_LIBXML_VERSION "3.2.1.2" -#define RUBY_LIBXML_VERNUM 3212 +#define RUBY_LIBXML_VERSION "3.2.1.3" +#define RUBY_LIBXML_VERNUM 3213 #define RUBY_LIBXML_VER_MAJ 3 #define RUBY_LIBXML_VER_MIN 2 #define RUBY_LIBXML_VER_MIC 1 diff --git a/lib/libxml/schema/element.rb b/lib/libxml/schema/element.rb index a295b6fb..2a230a21 100644 --- a/lib/libxml/schema/element.rb +++ b/lib/libxml/schema/element.rb @@ -14,6 +14,14 @@ def array? def elements type.elements end + + def min_occurs + @min + end + + def max_occurs + @max + end end end end From b0f86391cfb0a3dd4fffc3eba4e43c0bf115714d Mon Sep 17 00:00:00 2001 From: Valter Santos Date: Thu, 30 Nov 2023 13:40:18 +0000 Subject: [PATCH 16/18] Add salsify libxml to the automated library release system --- CHANGELOG.md | 10 ++++++++++ Rakefile | 1 - lib/libxml.rb | 5 ++++- lib/libxml/version.rb | 5 +++++ salsify_libxml_ruby.gemspec | 1 - 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 lib/libxml/version.rb diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..468ff78a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). + +## Unreleased + +## 3.3.0 - 2023-11-30 +- Added this repository to the Salsify Automated Library Release system \ No newline at end of file diff --git a/Rakefile b/Rakefile index 64995843..df193904 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,6 @@ #!/usr/bin/env ruby require "bundler/gem_tasks" -require "salsify_gem" require "rubygems" require "rake/extensiontask" require "rake/testtask" diff --git a/lib/libxml.rb b/lib/libxml.rb index e9390a87..62e8fd8c 100644 --- a/lib/libxml.rb +++ b/lib/libxml.rb @@ -2,4 +2,7 @@ # # This include is deprecated, use libxml-ruby instead! -require 'libxml-ruby' \ No newline at end of file +require 'libxml-ruby' + +module Libxml +end \ No newline at end of file diff --git a/lib/libxml/version.rb b/lib/libxml/version.rb new file mode 100644 index 00000000..0b73e1b4 --- /dev/null +++ b/lib/libxml/version.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +module Libxml + VERSION = '3.3.0' +end diff --git a/salsify_libxml_ruby.gemspec b/salsify_libxml_ruby.gemspec index 572f3bae..1abe7117 100644 --- a/salsify_libxml_ruby.gemspec +++ b/salsify_libxml_ruby.gemspec @@ -38,7 +38,6 @@ Gem::Specification.new do |spec| spec.test_files = Dir.glob('test/test_*.rb') spec.required_ruby_version = '>= 2.5' spec.add_runtime_dependency("mini_portile2", "~> 2.5.0") # keep version in sync with the one in extconf.rb - spec.add_development_dependency 'salsify_gem' spec.add_development_dependency 'rake-compiler' spec.add_development_dependency 'minitest' spec.license = 'MIT' From 1bba89035310dabab593e5e4f6d63743d1af4919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mateus?= Date: Mon, 11 Dec 2023 12:01:11 +0000 Subject: [PATCH 17/18] Fix version --- CHANGELOG.md | 2 +- ext/libxml/ruby_xml_version.h | 4 ++-- lib/libxml/version.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 468ff78a..381ed587 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,5 +6,5 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ## Unreleased -## 3.3.0 - 2023-11-30 +## 3.2.2.0 - 2023-11-30 - Added this repository to the Salsify Automated Library Release system \ No newline at end of file diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h index 0cdc7f30..223d7c8b 100644 --- a/ext/libxml/ruby_xml_version.h +++ b/ext/libxml/ruby_xml_version.h @@ -1,8 +1,8 @@ /* Don't nuke this block! It is used for automatically updating the * versions below. VERSION = string formatting, VERNUM = numbered * version for inline testing: increment both or none at all.*/ -#define RUBY_LIBXML_VERSION "3.2.1.3" -#define RUBY_LIBXML_VERNUM 3213 +#define RUBY_LIBXML_VERSION "3.2.2.0" +#define RUBY_LIBXML_VERNUM 3220 #define RUBY_LIBXML_VER_MAJ 3 #define RUBY_LIBXML_VER_MIN 2 #define RUBY_LIBXML_VER_MIC 1 diff --git a/lib/libxml/version.rb b/lib/libxml/version.rb index 0b73e1b4..7f65a0e6 100644 --- a/lib/libxml/version.rb +++ b/lib/libxml/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Libxml - VERSION = '3.3.0' + VERSION = '3.2.2.0' end From 8ad88e3d010a6f9bc3fc155f3191eca6e3e9aa65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mateus?= Date: Mon, 11 Dec 2023 12:06:43 +0000 Subject: [PATCH 18/18] Delete CHANGELOG --- CHANGELOG.md | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 381ed587..00000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,10 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - -## Unreleased - -## 3.2.2.0 - 2023-11-30 -- Added this repository to the Salsify Automated Library Release system \ No newline at end of file