1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* encoding.c (rb_obj_encoding): rdoc update. a patch from David

Flanagan <david AT davidflanagan.com>.  [ruby-core:12664]

* encoding.c (enc_dump, enc_load): marshaling feature.  a patch from
  David Flanagan.  [ruby-core:12665]

* encoding.c (Init_Encoding): undefine allocator of Encoding.
  [ruby-core:12665], [ruby-core:12666]

* test/ruby/test_encoding.rb: tests for Encoding from David Flanagan
  [ruby-core:12665]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-10-14 08:31:51 +00:00
parent 9d326d261e
commit b314d3e999
3 changed files with 65 additions and 4 deletions

View file

@ -1,3 +1,17 @@
Sun Oct 14 17:31:48 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* encoding.c (rb_obj_encoding): rdoc update. a patch from David
Flanagan <david AT davidflanagan.com>. [ruby-core:12664]
* encoding.c (enc_dump, enc_load): marshaling feature. a patch from
David Flanagan. [ruby-core:12665]
* encoding.c (Init_Encoding): undefine allocator of Encoding.
[ruby-core:12665], [ruby-core:12666]
* test/ruby/test_encoding.rb: tests for Encoding from David Flanagan
[ruby-core:12665]
Sun Oct 14 11:09:09 2007 Tanaka Akira <akr@fsij.org> Sun Oct 14 11:09:09 2007 Tanaka Akira <akr@fsij.org>
* lib/pp.rb (PP::PPMethods#pp_hash): don't sort keys because hash is * lib/pp.rb (PP::PPMethods#pp_hash): don't sort keys because hash is

View file

@ -2,8 +2,8 @@
encoding.c - encoding.c -
$Author: matz $ $Author$
$Date: 2007-05-24 17:22:33 +0900 (Thu, 24 May 2007) $ $Date$
created at: Thu May 24 17:23:27 JST 2007 created at: Thu May 24 17:23:27 JST 2007
Copyright (C) 2007 Yukihiro Matsumoto Copyright (C) 2007 Yukihiro Matsumoto
@ -372,9 +372,9 @@ rb_enc_copy(VALUE obj1, VALUE obj2)
/* /*
* call-seq: * call-seq:
* obj.encoding => str * obj.encoding => encoding
* *
* Retruns the encoding name. * Returns the Encoding object that represents the encoding of obj.
*/ */
VALUE VALUE
@ -498,12 +498,31 @@ enc_find(VALUE klass, VALUE enc)
return enc_from_encoding(rb_enc_from_index(idx)); return enc_from_encoding(rb_enc_from_index(idx));
} }
/* :nodoc: */
static VALUE
enc_dump(int argc, VALUE *argv, VALUE self)
{
rb_scan_args(argc, argv, "01", 0);
return enc_name(self);
}
/* :nodoc: */
static VALUE
enc_load(VALUE klass, VALUE str)
{
return enc_find(klass, str);
}
void void
Init_Encoding(void) Init_Encoding(void)
{ {
rb_cEncoding = rb_define_class("Encoding", rb_cObject); rb_cEncoding = rb_define_class("Encoding", rb_cObject);
rb_undef_alloc_func(rb_cEncoding);
rb_define_method(rb_cEncoding, "inspect", enc_inspect, 0); rb_define_method(rb_cEncoding, "inspect", enc_inspect, 0);
rb_define_method(rb_cEncoding, "name", enc_name, 0); rb_define_method(rb_cEncoding, "name", enc_name, 0);
rb_define_singleton_method(rb_cEncoding, "list", enc_list, 0); rb_define_singleton_method(rb_cEncoding, "list", enc_list, 0);
rb_define_singleton_method(rb_cEncoding, "find", enc_find, 1); rb_define_singleton_method(rb_cEncoding, "find", enc_find, 1);
rb_define_method(rb_cEncoding, "_dump", enc_dump, -1);
rb_define_singleton_method(rb_cEncoding, "_load", enc_load, 1);
} }

View file

@ -0,0 +1,28 @@
require 'test/unit'
class TestEncoding < Test::Unit::TestCase
# Test basic encoding methods: list, find, name
def test_encoding
encodings = Encoding.list
assert_equal(encodings.empty?, false)
encodings.each do |e|
assert_equal(e, Encoding.find(e.name))
assert_equal(e, Encoding.find(e.name.upcase))
assert_equal(e, Encoding.find(e.name.capitalize))
assert_equal(e, Encoding.find(e.name.downcase))
end
end
# Test that Encoding objects can't be copied
# And that they can be compared by object_id
def test_singleton
encodings = Encoding.list
encodings.each do |e|
assert_raise(TypeError) { e.dup }
assert_raise(TypeError) { e.clone }
assert_equal(e.object_id, Marshal.load(Marshal.dump(e)).object_id)
end
end
end