Permalink
Browse files

adding the delete method

  • Loading branch information...
1 parent 38fdb08 commit b631d6796f597aa6a55cdf20c203e9af1a96e0cf @tenderlove tenderlove committed Nov 10, 2009
Showing with 29 additions and 1 deletion.
  1. +14 −1 ext/nokogiri/xml_encoding_handler.c
  2. +15 −0 test/test_encoding_handler.rb
@@ -1,7 +1,7 @@
#include <xml_encoding_handler.h>
/*
- * call-seq: Nokogiri::EncodingHandler#[](name)
+ * call-seq: Nokogiri::EncodingHandler.[](name)
*
* Get the encoding handler for +name+
*/
@@ -17,6 +17,18 @@ static VALUE get(VALUE klass, VALUE key)
}
/*
+ * call-seq: Nokogiri::EncodingHandler.delete(name)
+ *
+ * Delete the encoding alias named +name+
+ */
+static VALUE delete(VALUE klass, VALUE name)
+{
+ if(xmlDelEncodingAlias(StringValuePtr(name))) return Qnil;
+
+ return Qtrue;
+}
+
+/*
* call-seq: Nokogiri::EncodingHandler.alias(from, to)
*
* Alias encoding handler with name +from+ to name +to+
@@ -60,6 +72,7 @@ void init_xml_encoding_handler()
VALUE klass = rb_define_class_under(nokogiri, "EncodingHandler", rb_cObject);
rb_define_singleton_method(klass, "[]", get, 1);
+ rb_define_singleton_method(klass, "delete", delete, 1);
rb_define_singleton_method(klass, "alias", alias, 2);
rb_define_singleton_method(klass, "clear_aliases!", clear_aliases, 0);
rb_define_method(klass, "name", name, 0);
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
require "helper"
class TestEncodingHandler < Nokogiri::TestCase
@@ -28,4 +30,17 @@ def test_cleanup_aliases
Nokogiri::EncodingHandler.clear_aliases!
assert_nil Nokogiri::EncodingHandler['UTF-9']
end
+
+ def test_delete
+ assert_nil Nokogiri::EncodingHandler['UTF-9']
+ Nokogiri::EncodingHandler.alias('UTF-8', 'UTF-9')
+ assert_not_nil Nokogiri::EncodingHandler['UTF-9']
+
+ Nokogiri::EncodingHandler.delete 'UTF-9'
+ assert_nil Nokogiri::EncodingHandler['UTF-9']
+ end
+
+ def test_delete_non_existent
+ assert_nil Nokogiri::EncodingHandler.delete('UTF-9')
+ end
end

0 comments on commit b631d67

Please sign in to comment.