mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/-ext-/test_printf.rb: tests for [Feature #5896].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
38f0dd0aba
commit
26f96fe1ce
3 changed files with 56 additions and 0 deletions
1
ext/-test-/printf/extconf.rb
Normal file
1
ext/-test-/printf/extconf.rb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
create_makefile("-test-/printf")
|
31
ext/-test-/printf/printf.c
Normal file
31
ext/-test-/printf/printf.c
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#include <ruby.h>
|
||||||
|
#include <ruby/encoding.h>
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
printf_i(VALUE self, VALUE obj)
|
||||||
|
{
|
||||||
|
char buf[256];
|
||||||
|
snprintf(buf, sizeof(buf), "<%"PRIsVALUE">", obj);
|
||||||
|
return rb_usascii_str_new2(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
printf_s(VALUE self, VALUE obj)
|
||||||
|
{
|
||||||
|
return rb_enc_sprintf(rb_usascii_encoding(), "<%"PRIsVALUE">", obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
printf_v(VALUE self, VALUE obj)
|
||||||
|
{
|
||||||
|
return rb_enc_sprintf(rb_usascii_encoding(), "{%+"PRIsVALUE"}", obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Init_printf(void)
|
||||||
|
{
|
||||||
|
VALUE m = rb_define_module_under(rb_define_module("Bug"), "Printf");
|
||||||
|
rb_define_singleton_method(m, "i", printf_i, 1);
|
||||||
|
rb_define_singleton_method(m, "s", printf_s, 1);
|
||||||
|
rb_define_singleton_method(m, "v", printf_v, 1);
|
||||||
|
}
|
24
test/-ext-/test_printf.rb
Normal file
24
test/-ext-/test_printf.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
require 'test/unit'
|
||||||
|
require "-test-/printf"
|
||||||
|
|
||||||
|
class Test_SPrintf < Test::Unit::TestCase
|
||||||
|
def to_s
|
||||||
|
"#{self.class}:#{object_id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def inspect
|
||||||
|
"<#{self.class}:#{object_id}>"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_int
|
||||||
|
assert_match(/\A<-?\d+>\z/, Bug::Printf.i(self))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_to_str
|
||||||
|
assert_equal("<#{self.class}:#{object_id}>", Bug::Printf.s(self))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_inspect
|
||||||
|
assert_equal("{<#{self.class}:#{object_id}>}", Bug::Printf.v(self))
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue