Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
39c09478
Commit
39c09478
authored
Feb 12, 2019
by
Joe Bolinger
Committed by
Paul Yang
Feb 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement to_s for message types (#5710)
parent
7fdc45a8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
1 deletion
+4
-1
message.c
ruby/ext/google/protobuf_c/message.c
+1
-0
common_tests.rb
ruby/tests/common_tests.rb
+3
-1
No files found.
ruby/ext/google/protobuf_c/message.c
View file @
39c09478
...
@@ -626,6 +626,7 @@ VALUE build_class_from_descriptor(Descriptor* desc) {
...
@@ -626,6 +626,7 @@ VALUE build_class_from_descriptor(Descriptor* desc) {
rb_define_method
(
klass
,
"to_h"
,
Message_to_h
,
0
);
rb_define_method
(
klass
,
"to_h"
,
Message_to_h
,
0
);
rb_define_method
(
klass
,
"to_hash"
,
Message_to_h
,
0
);
rb_define_method
(
klass
,
"to_hash"
,
Message_to_h
,
0
);
rb_define_method
(
klass
,
"inspect"
,
Message_inspect
,
0
);
rb_define_method
(
klass
,
"inspect"
,
Message_inspect
,
0
);
rb_define_method
(
klass
,
"to_s"
,
Message_inspect
,
0
);
rb_define_method
(
klass
,
"[]"
,
Message_index
,
1
);
rb_define_method
(
klass
,
"[]"
,
Message_index
,
1
);
rb_define_method
(
klass
,
"[]="
,
Message_index_set
,
2
);
rb_define_method
(
klass
,
"[]="
,
Message_index_set
,
2
);
rb_define_singleton_method
(
klass
,
"decode"
,
Message_decode
,
1
);
rb_define_singleton_method
(
klass
,
"decode"
,
Message_decode
,
1
);
...
...
ruby/tests/common_tests.rb
View file @
39c09478
...
@@ -103,7 +103,7 @@ module CommonTests
...
@@ -103,7 +103,7 @@ module CommonTests
assert_equal
3
,
m
.
repeated_msg
.
first
.
sub_child
.
optional_int32
assert_equal
3
,
m
.
repeated_msg
.
first
.
sub_child
.
optional_int32
end
end
def
test_inspect
def
test_inspect
_eq_to_s
m
=
proto_module
::
TestMessage
.
new
(
m
=
proto_module
::
TestMessage
.
new
(
:optional_int32
=>
-
42
,
:optional_int32
=>
-
42
,
:optional_enum
=>
:A
,
:optional_enum
=>
:A
,
...
@@ -111,10 +111,12 @@ module CommonTests
...
@@ -111,10 +111,12 @@ module CommonTests
:repeated_string
=>
[
"hello"
,
"there"
,
"world"
])
:repeated_string
=>
[
"hello"
,
"there"
,
"world"
])
expected
=
"<
#{
proto_module
}
::TestMessage: optional_int32: -42, optional_int64: 0, optional_uint32: 0, optional_uint64: 0, optional_bool: false, optional_float: 0.0, optional_double: 0.0, optional_string:
\"\"
, optional_bytes:
\"\"
, optional_msg: <
#{
proto_module
}
::TestMessage2: foo: 0>, optional_enum: :A, repeated_int32: [], repeated_int64: [], repeated_uint32: [], repeated_uint64: [], repeated_bool: [], repeated_float: [], repeated_double: [], repeated_string: [
\"
hello
\"
,
\"
there
\"
,
\"
world
\"
], repeated_bytes: [], repeated_msg: [], repeated_enum: []>"
expected
=
"<
#{
proto_module
}
::TestMessage: optional_int32: -42, optional_int64: 0, optional_uint32: 0, optional_uint64: 0, optional_bool: false, optional_float: 0.0, optional_double: 0.0, optional_string:
\"\"
, optional_bytes:
\"\"
, optional_msg: <
#{
proto_module
}
::TestMessage2: foo: 0>, optional_enum: :A, repeated_int32: [], repeated_int64: [], repeated_uint32: [], repeated_uint64: [], repeated_bool: [], repeated_float: [], repeated_double: [], repeated_string: [
\"
hello
\"
,
\"
there
\"
,
\"
world
\"
], repeated_bytes: [], repeated_msg: [], repeated_enum: []>"
assert_equal
expected
,
m
.
inspect
assert_equal
expected
,
m
.
inspect
assert_equal
expected
,
m
.
to_s
m
=
proto_module
::
OneofMessage
.
new
(
:b
=>
-
42
)
m
=
proto_module
::
OneofMessage
.
new
(
:b
=>
-
42
)
expected
=
"<
#{
proto_module
}
::OneofMessage: a:
\"\"
, b: -42, c: nil, d: :Default>"
expected
=
"<
#{
proto_module
}
::OneofMessage: a:
\"\"
, b: -42, c: nil, d: :Default>"
assert_equal
expected
,
m
.
inspect
assert_equal
expected
,
m
.
inspect
assert_equal
expected
,
m
.
to_s
end
end
def
test_hash
def
test_hash
...
...
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