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:
parent
9d326d261e
commit
b314d3e999
3 changed files with 65 additions and 4 deletions
14
ChangeLog
14
ChangeLog
|
@ -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>
|
||||
|
||||
* lib/pp.rb (PP::PPMethods#pp_hash): don't sort keys because hash is
|
||||
|
|
27
encoding.c
27
encoding.c
|
@ -2,8 +2,8 @@
|
|||
|
||||
encoding.c -
|
||||
|
||||
$Author: matz $
|
||||
$Date: 2007-05-24 17:22:33 +0900 (Thu, 24 May 2007) $
|
||||
$Author$
|
||||
$Date$
|
||||
created at: Thu May 24 17:23:27 JST 2007
|
||||
|
||||
Copyright (C) 2007 Yukihiro Matsumoto
|
||||
|
@ -372,9 +372,9 @@ rb_enc_copy(VALUE obj1, VALUE obj2)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* obj.encoding => str
|
||||
* obj.encoding => encoding
|
||||
*
|
||||
* Retruns the encoding name.
|
||||
* Returns the Encoding object that represents the encoding of obj.
|
||||
*/
|
||||
|
||||
VALUE
|
||||
|
@ -498,12 +498,31 @@ enc_find(VALUE klass, VALUE enc)
|
|||
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
|
||||
Init_Encoding(void)
|
||||
{
|
||||
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, "name", enc_name, 0);
|
||||
rb_define_singleton_method(rb_cEncoding, "list", enc_list, 0);
|
||||
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);
|
||||
}
|
||||
|
|
28
test/ruby/test_encoding.rb
Normal file
28
test/ruby/test_encoding.rb
Normal 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
|
Loading…
Reference in a new issue