`%C` value need not to be saved in `TestVFormat::Native`; close #4868

parent 8bc9a79e
...@@ -17,7 +17,6 @@ typedef mrb_int mrb_float; ...@@ -17,7 +17,6 @@ typedef mrb_int mrb_float;
/* size_t l; */\ /* size_t l; */\
mrb_sym n; \ mrb_sym n; \
char *s; \ char *s; \
struct RClass *C
#define NATIVE_DEFINE_TYPE_FUNC(t) \ #define NATIVE_DEFINE_TYPE_FUNC(t) \
static mrb_value \ static mrb_value \
...@@ -39,7 +38,6 @@ typedef enum { ...@@ -39,7 +38,6 @@ typedef enum {
/* ARG_l,*/ /* ARG_l,*/
ARG_n, ARG_n,
ARG_s, ARG_s,
ARG_C,
ARG_v, ARG_v,
} VFArgumentType; } VFArgumentType;
...@@ -87,7 +85,6 @@ native_initialize(mrb_state *mrb, mrb_value self) ...@@ -87,7 +85,6 @@ native_initialize(mrb_state *mrb, mrb_value self)
case ARG_s: data.s = (char*)mrb_malloc(mrb, RSTRING_LEN(obj) + 1); case ARG_s: data.s = (char*)mrb_malloc(mrb, RSTRING_LEN(obj) + 1);
memcpy(data.s, RSTRING_PTR(obj), RSTRING_LEN(obj)); memcpy(data.s, RSTRING_PTR(obj), RSTRING_LEN(obj));
data.s[RSTRING_LEN(obj)] = '\0'; break; data.s[RSTRING_LEN(obj)] = '\0'; break;
case ARG_C: data.C = mrb_class_ptr(obj); break;
default: mrb_raise(mrb, E_ARGUMENT_ERROR, "unknown type"); default: mrb_raise(mrb, E_ARGUMENT_ERROR, "unknown type");
} }
datap = (VFNative*)mrb_malloc(mrb, sizeof(VFNative)); datap = (VFNative*)mrb_malloc(mrb, sizeof(VFNative));
...@@ -103,7 +100,6 @@ NATIVE_DEFINE_TYPE_FUNC(i) ...@@ -103,7 +100,6 @@ NATIVE_DEFINE_TYPE_FUNC(i)
/*NATIVE_DEFINE_TYPE_FUNC(l)*/ /*NATIVE_DEFINE_TYPE_FUNC(l)*/
NATIVE_DEFINE_TYPE_FUNC(n) NATIVE_DEFINE_TYPE_FUNC(n)
NATIVE_DEFINE_TYPE_FUNC(s) NATIVE_DEFINE_TYPE_FUNC(s)
NATIVE_DEFINE_TYPE_FUNC(C)
static VFArgument* static VFArgument*
arg_from_obj(mrb_state *mrb, mrb_value obj, struct RClass *native_class, arg_from_obj(mrb_state *mrb, mrb_value obj, struct RClass *native_class,
...@@ -140,7 +136,6 @@ arg_from_obj(mrb_state *mrb, mrb_value obj, struct RClass *native_class, ...@@ -140,7 +136,6 @@ arg_from_obj(mrb_state *mrb, mrb_value obj, struct RClass *native_class,
/* VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, l) : */\ /* VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, l) : */\
VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, n) : \ VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, n) : \
VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, s) : \ VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, s) : \
VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, C) : \
VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, v) : \ VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, v) : \
mrb_nil_value() /* not reached */ \ mrb_nil_value() /* not reached */ \
) )
...@@ -154,7 +149,6 @@ arg_from_obj(mrb_state *mrb, mrb_value obj, struct RClass *native_class, ...@@ -154,7 +149,6 @@ arg_from_obj(mrb_state *mrb, mrb_value obj, struct RClass *native_class,
/* VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, l) : */\ /* VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, l) : */\
VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, n) : \ VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, n) : \
VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, s) : \ VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, s) : \
VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, C) : \
VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, v) : \ VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, v) : \
mrb_nil_value() /* not reached */ mrb_nil_value() /* not reached */
#define VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, t) \ #define VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, t) \
...@@ -195,6 +189,5 @@ mrb_init_test_vformat(mrb_state *mrb) ...@@ -195,6 +189,5 @@ mrb_init_test_vformat(mrb_state *mrb)
/* NATIVE_DEFINE_TYPE_METHOD(l);*/ /* NATIVE_DEFINE_TYPE_METHOD(l);*/
NATIVE_DEFINE_TYPE_METHOD(n); NATIVE_DEFINE_TYPE_METHOD(n);
NATIVE_DEFINE_TYPE_METHOD(s); NATIVE_DEFINE_TYPE_METHOD(s);
NATIVE_DEFINE_TYPE_METHOD(C);
mrb_define_method(mrb, n, "initialize", native_initialize, MRB_ARGS_REQ(2)); mrb_define_method(mrb, n, "initialize", native_initialize, MRB_ARGS_REQ(2));
} }
# coding: cp932
def assert_format(exp, args) def assert_format(exp, args)
assert_equal(exp, TestVFormat.format(*args)) assert_equal(exp, TestVFormat.format(*args))
end end
...@@ -44,9 +45,9 @@ assert('mrb_vformat') do ...@@ -44,9 +45,9 @@ assert('mrb_vformat') do
# assert_format 'string and length', ['string %l length', n.s('andante'), n.l(3)] # assert_format 'string and length', ['string %l length', n.s('andante'), n.l(3)]
assert_format '`n`: sym', ['`n`: %n', n.n(:sym)] assert_format '`n`: sym', ['`n`: %n', n.n(:sym)]
assert_format '%C文字列%', ['%s', n.s('%C文字列%')] assert_format '%C文字列%', ['%s', n.s('%C文字列%')]
assert_format '`C`: Kernel module', ['`C`: %C module', n.C(Kernel)] assert_format '`C`: Kernel module', ['`C`: %C module', Kernel]
assert_format '`C`: NilClass', ['`C`: %C', n.C(nil.class)] assert_format '`C`: NilClass', ['`C`: %C', nil.class]
assert_format_pattern '#<Class:#<String:0x*>>', ['%C', n.C(sclass(""))] assert_format_pattern '#<Class:#<String:0x*>>', ['%C', sclass("")]
assert_format '`T`: NilClass', ['`T`: %T', nil] assert_format '`T`: NilClass', ['`T`: %T', nil]
assert_format '`T`: FalseClass', ['`T`: %T', false] assert_format '`T`: FalseClass', ['`T`: %T', false]
assert_format '`T`: TrueClass', ['`T`: %T', true] assert_format '`T`: TrueClass', ['`T`: %T', true]
...@@ -69,7 +70,7 @@ assert('mrb_vformat') do ...@@ -69,7 +70,7 @@ assert('mrb_vformat') do
assert_format ':"&.": inspect symbol', ['%!n: inspect symbol', n.n(:'&.')] assert_format ':"&.": inspect symbol', ['%!n: inspect symbol', n.n(:'&.')]
assert_format 'inspect "String"', ['inspect %!v', 'String'] assert_format 'inspect "String"', ['inspect %!v', 'String']
assert_format 'inspect Array: [1, :x, {}]', ['inspect Array: %!v', [1,:x,{}]] assert_format 'inspect Array: [1, :x, {}]', ['inspect Array: %!v', [1,:x,{}]]
assert_format_pattern '`!C`: #<Class:0x*>', ['`!C`: %!C', n.C(Class.new)] assert_format_pattern '`!C`: #<Class:0x*>', ['`!C`: %!C', Class.new]
assert_format 'to_s -> to_s: ab,cd', ['to_s -> to_s: %n,%v', n.n(:ab), 'cd'] assert_format 'to_s -> to_s: ab,cd', ['to_s -> to_s: %n,%v', n.n(:ab), 'cd']
assert_format 'to_s -> inspect: x:y', ['to_s -> inspect: %v%!v', 'x', :y] assert_format 'to_s -> inspect: x:y', ['to_s -> inspect: %v%!v', 'x', :y]
assert_format 'inspect -> to_s: "a"b', ['inspect -> to_s: %!v%n', 'a', n.n(:b)] assert_format 'inspect -> to_s: "a"b', ['inspect -> to_s: %!v%n', 'a', n.n(:b)]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment