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
aec07110
Commit
aec07110
authored
Mar 17, 2017
by
Ewout
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ruby tests compare parsed JSON instead of raw JSON
parent
008dc92c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
12 deletions
+89
-12
basic.rb
ruby/tests/basic.rb
+89
-12
No files found.
ruby/tests/basic.rb
View file @
aec07110
#!/usr/bin/ruby
require
'google/protobuf'
require
'json'
require
'test/unit'
# ------------- generated code --------------
...
...
@@ -1179,9 +1180,33 @@ module BasicTest
return
if
RUBY_PLATFORM
==
"java"
m
=
TestMessage
.
new
expected
=
'{"optionalInt32":0,"optionalInt64":0,"optionalUint32":0,"optionalUint64":0,"optionalBool":false,"optionalFloat":0,"optionalDouble":0,"optionalString":"","optionalBytes":"","optionalEnum":"Default","repeatedInt32":[],"repeatedInt64":[],"repeatedUint32":[],"repeatedUint64":[],"repeatedBool":[],"repeatedFloat":[],"repeatedDouble":[],"repeatedString":[],"repeatedBytes":[],"repeatedMsg":[],"repeatedEnum":[]}'
expected
=
{
optionalInt32:
0
,
optionalInt64:
0
,
optionalUint32:
0
,
optionalUint64:
0
,
optionalBool:
false
,
optionalFloat:
0
,
optionalDouble:
0
,
optionalString:
""
,
optionalBytes:
""
,
optionalEnum:
"Default"
,
repeatedInt32:
[],
repeatedInt64:
[],
repeatedUint32:
[],
repeatedUint64:
[],
repeatedBool:
[],
repeatedFloat:
[],
repeatedDouble:
[],
repeatedString:
[],
repeatedBytes:
[],
repeatedMsg:
[],
repeatedEnum:
[]
}
actual
=
TestMessage
.
encode_json
(
m
,
:emit_defaults
=>
true
)
assert
TestMessage
.
encode_json
(
m
,
:emit_default
s
=>
true
)
==
expected
assert
JSON
.
parse
(
actual
,
:symbolize_name
s
=>
true
)
==
expected
end
def
test_json_emit_defaults_submsg
...
...
@@ -1189,9 +1214,34 @@ module BasicTest
return
if
RUBY_PLATFORM
==
"java"
m
=
TestMessage
.
new
(
optional_msg:
TestMessage2
.
new
)
expected
=
'{"optionalInt32":0,"optionalInt64":0,"optionalUint32":0,"optionalUint64":0,"optionalBool":false,"optionalFloat":0,"optionalDouble":0,"optionalString":"","optionalBytes":"","optionalMsg":{"foo":0},"optionalEnum":"Default","repeatedInt32":[],"repeatedInt64":[],"repeatedUint32":[],"repeatedUint64":[],"repeatedBool":[],"repeatedFloat":[],"repeatedDouble":[],"repeatedString":[],"repeatedBytes":[],"repeatedMsg":[],"repeatedEnum":[]}'
expected
=
{
optionalInt32:
0
,
optionalInt64:
0
,
optionalUint32:
0
,
optionalUint64:
0
,
optionalBool:
false
,
optionalFloat:
0
,
optionalDouble:
0
,
optionalString:
""
,
optionalBytes:
""
,
optionalMsg:
{
foo:
0
},
optionalEnum:
"Default"
,
repeatedInt32:
[],
repeatedInt64:
[],
repeatedUint32:
[],
repeatedUint64:
[],
repeatedBool:
[],
repeatedFloat:
[],
repeatedDouble:
[],
repeatedString:
[],
repeatedBytes:
[],
repeatedMsg:
[],
repeatedEnum:
[]
}
actual
=
TestMessage
.
encode_json
(
m
,
:emit_defaults
=>
true
)
assert
TestMessage
.
encode_json
(
m
,
:emit_default
s
=>
true
)
==
expected
assert
JSON
.
parse
(
actual
,
:symbolize_name
s
=>
true
)
==
expected
end
def
test_json_emit_defaults_repeated_submsg
...
...
@@ -1199,21 +1249,45 @@ module BasicTest
return
if
RUBY_PLATFORM
==
"java"
m
=
TestMessage
.
new
(
repeated_msg:
[
TestMessage2
.
new
])
expected
=
'{"optionalInt32":0,"optionalInt64":0,"optionalUint32":0,"optionalUint64":0,"optionalBool":false,"optionalFloat":0,"optionalDouble":0,"optionalString":"","optionalBytes":"","optionalEnum":"Default","repeatedInt32":[],"repeatedInt64":[],"repeatedUint32":[],"repeatedUint64":[],"repeatedBool":[],"repeatedFloat":[],"repeatedDouble":[],"repeatedString":[],"repeatedBytes":[],"repeatedMsg":[{"foo":0}],"repeatedEnum":[]}'
expected
=
{
optionalInt32:
0
,
optionalInt64:
0
,
optionalUint32:
0
,
optionalUint64:
0
,
optionalBool:
false
,
optionalFloat:
0
,
optionalDouble:
0
,
optionalString:
""
,
optionalBytes:
""
,
optionalEnum:
"Default"
,
repeatedInt32:
[],
repeatedInt64:
[],
repeatedUint32:
[],
repeatedUint64:
[],
repeatedBool:
[],
repeatedFloat:
[],
repeatedDouble:
[],
repeatedString:
[],
repeatedBytes:
[],
repeatedMsg:
[{
foo:
0
}],
repeatedEnum:
[]
}
actual
=
TestMessage
.
encode_json
(
m
,
:emit_defaults
=>
true
)
assert
TestMessage
.
encode_json
(
m
,
:emit_default
s
=>
true
)
==
expected
assert
JSON
.
parse
(
actual
,
:symbolize_name
s
=>
true
)
==
expected
end
def
test_json_maps
# TODO: Fix JSON in JRuby version.
return
if
RUBY_PLATFORM
==
"java"
m
=
MapMessage
.
new
(
:map_string_int32
=>
{
"a"
=>
1
})
expected
=
'{"mapStringInt32":{"a":1},"mapStringMsg":{}}'
expected_preserve
=
'{"map_string_int32":{"a":1},"map_string_msg":{}}'
assert
MapMessage
.
encode_json
(
m
)
==
expected
expected
=
{
mapStringInt32:
{
a:
1
},
mapStringMsg:
{}}
expected_preserve
=
{
map_string_int32:
{
a:
1
},
map_string_msg:
{}}
assert
JSON
.
parse
(
MapMessage
.
encode_json
(
m
),
:symbolize_names
=>
true
)
==
expected
json
=
MapMessage
.
encode_json
(
m
,
:preserve_proto_fieldnames
=>
true
)
assert
json
==
expected_preserve
assert
JSON
.
parse
(
json
,
:symbolize_names
=>
true
)
==
expected_preserve
m2
=
MapMessage
.
decode_json
(
MapMessage
.
encode_json
(
m
))
assert
m
==
m2
...
...
@@ -1223,8 +1297,11 @@ module BasicTest
# TODO: Fix JSON in JRuby version.
return
if
RUBY_PLATFORM
==
"java"
m
=
MapMessage
.
new
(
:map_string_msg
=>
{
"a"
=>
TestMessage2
.
new
})
expected
=
'{"mapStringInt32":{},"mapStringMsg":{"a":{"foo":0}}}'
assert
MapMessage
.
encode_json
(
m
,
:emit_defaults
=>
true
)
==
expected
expected
=
{
mapStringInt32:
{},
mapStringMsg:
{
a:
{
foo:
0
}}}
actual
=
MapMessage
.
encode_json
(
m
,
:emit_defaults
=>
true
)
assert
JSON
.
parse
(
actual
,
:symbolize_names
=>
true
)
==
expected
end
def
test_comparison_with_arbitrary_object
...
...
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