Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
f507ff48
Commit
f507ff48
authored
Dec 18, 2019
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`%C` value need not to be saved in `TestVFormat::Native`; close #4868
parent
8bc9a79e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
11 deletions
+5
-11
mrbgems/mruby-test/vformat.c
mrbgems/mruby-test/vformat.c
+0
-7
test/t/vformat.rb
test/t/vformat.rb
+5
-4
No files found.
mrbgems/mruby-test/vformat.c
View file @
f507ff48
...
...
@@ -17,7 +17,6 @@ typedef mrb_int mrb_float;
/* size_t l; */
\
mrb_sym n; \
char *s; \
struct RClass *C
#define NATIVE_DEFINE_TYPE_FUNC(t) \
static mrb_value \
...
...
@@ -39,7 +38,6 @@ typedef enum {
/* ARG_l,*/
ARG_n
,
ARG_s
,
ARG_C
,
ARG_v
,
}
VFArgumentType
;
...
...
@@ -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
);
memcpy
(
data
.
s
,
RSTRING_PTR
(
obj
),
RSTRING_LEN
(
obj
));
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"
);
}
datap
=
(
VFNative
*
)
mrb_malloc
(
mrb
,
sizeof
(
VFNative
));
...
...
@@ -103,7 +100,6 @@ NATIVE_DEFINE_TYPE_FUNC(i)
/*NATIVE_DEFINE_TYPE_FUNC(l)*/
NATIVE_DEFINE_TYPE_FUNC
(
n
)
NATIVE_DEFINE_TYPE_FUNC
(
s
)
NATIVE_DEFINE_TYPE_FUNC
(
C
)
static
VFArgument
*
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, n) : \
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) : \
mrb_nil_value()
/* not reached */
\
)
...
...
@@ -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, n) : \
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) : \
mrb_nil_value()
/* not reached */
#define VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, t) \
...
...
@@ -195,6 +189,5 @@ mrb_init_test_vformat(mrb_state *mrb)
/* NATIVE_DEFINE_TYPE_METHOD(l);*/
NATIVE_DEFINE_TYPE_METHOD
(
n
);
NATIVE_DEFINE_TYPE_METHOD
(
s
);
NATIVE_DEFINE_TYPE_METHOD
(
C
);
mrb_define_method
(
mrb
,
n
,
"initialize"
,
native_initialize
,
MRB_ARGS_REQ
(
2
));
}
test/t/vformat.rb
View file @
f507ff48
# coding: cp932
def
assert_format
(
exp
,
args
)
assert_equal
(
exp
,
TestVFormat
.
format
(
*
args
))
end
...
...
@@ -44,9 +45,9 @@ assert('mrb_vformat') do
# 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
'%C文字列%'
,
[
'%s'
,
n
.
s
(
'%C文字列%'
)]
assert_format
'`C`: Kernel module'
,
[
'`C`: %C module'
,
n
.
C
(
Kernel
)
]
assert_format
'`C`: NilClass'
,
[
'`C`: %C'
,
n
.
C
(
nil
.
class
)
]
assert_format_pattern
'#<Class:#<String:0x*>>'
,
[
'%C'
,
n
.
C
(
sclass
(
""
)
)]
assert_format
'`C`: Kernel module'
,
[
'`C`: %C module'
,
Kernel
]
assert_format
'`C`: NilClass'
,
[
'`C`: %C'
,
n
il
.
class
]
assert_format_pattern
'#<Class:#<String:0x*>>'
,
[
'%C'
,
sclass
(
""
)]
assert_format
'`T`: NilClass'
,
[
'`T`: %T'
,
nil
]
assert_format
'`T`: FalseClass'
,
[
'`T`: %T'
,
false
]
assert_format
'`T`: TrueClass'
,
[
'`T`: %T'
,
true
]
...
...
@@ -69,7 +70,7 @@ assert('mrb_vformat') do
assert_format
':"&.": inspect symbol'
,
[
'%!n: inspect symbol'
,
n
.
n
(
:'&.'
)]
assert_format
'inspect "String"'
,
[
'inspect %!v'
,
'String'
]
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 -> 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
)]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment