diff options
author | Harshit Chopra <harshit@squareup.com> | 2017-08-25 12:11:15 -0700 |
---|---|---|
committer | Harshit Chopra <harshit@squareup.com> | 2018-09-27 14:21:16 -0400 |
commit | d0535cc09e6eac1bddddd51c20b5738c0e841765 (patch) | |
tree | f712febe270ba656970f65b952114e14650103b6 /ruby/tests/gc_test.rb | |
parent | 048f5c26a783f5f92061aec3aab19986e5c8d435 (diff) | |
download | protobuf-d0535cc09e6eac1bddddd51c20b5738c0e841765.tar.gz protobuf-d0535cc09e6eac1bddddd51c20b5738c0e841765.tar.bz2 protobuf-d0535cc09e6eac1bddddd51c20b5738c0e841765.zip |
Adds support for proto2 syntax for Ruby gem.
This change only adds basic proto2 support without advanced features
like extensions, custom options, maps, etc.
The protoc binary now generates ruby code for proto2 syntax.
However, for now, it is restricted to proto2 files without advanced features
like extensions, in which case it still errors out.
This change also modifies the DSL to add proto messages to the DescriptorPool.
There is a new DSL Builder#add_file to create a new FileDescriptor. With this,
the generated ruby DSL looks something like:
Google::Protobuf::DescriptorPool.generated_pool.build do
add_file "test.proto" do
add_message "foo" do
optional :val, :int32, 1
end
end
end
Diffstat (limited to 'ruby/tests/gc_test.rb')
-rw-r--r-- | ruby/tests/gc_test.rb | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/ruby/tests/gc_test.rb b/ruby/tests/gc_test.rb index f3470cca..55b96289 100644 --- a/ruby/tests/gc_test.rb +++ b/ruby/tests/gc_test.rb @@ -6,12 +6,13 @@ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) old_gc = GC.stress GC.stress = 0x01 | 0x04 require 'generated_code_pb' +require 'generated_code_proto2_pb' GC.stress = old_gc require 'test/unit' class GCTest < Test::Unit::TestCase - def get_msg + def get_msg_proto3 A::B::C::TestMessage.new( :optional_int32 => 1, :optional_int64 => 1, @@ -46,12 +47,55 @@ class GCTest < Test::Unit::TestCase :map_string_bool => {"a" => true}, ) end + + def get_msg_proto2 + A::B::Proto2::TestMessage.new( + :optional_int32 => 1, + :optional_int64 => 1, + :optional_uint32 => 1, + :optional_uint64 => 1, + :optional_bool => true, + :optional_double => 1.0, + :optional_float => 1.0, + :optional_string => "a", + :optional_bytes => "b", + :optional_enum => A::B::Proto2::TestEnum::A, + :optional_msg => A::B::Proto2::TestMessage.new(), + :repeated_int32 => [1], + :repeated_int64 => [1], + :repeated_uint32 => [1], + :repeated_uint64 => [1], + :repeated_bool => [true], + :repeated_double => [1.0], + :repeated_float => [1.0], + :repeated_string => ["a"], + :repeated_bytes => ["b"], + :repeated_enum => [A::B::Proto2::TestEnum::A], + :repeated_msg => [A::B::Proto2::TestMessage.new()], + :required_int32 => 1, + :required_int64 => 1, + :required_uint32 => 1, + :required_uint64 => 1, + :required_bool => true, + :required_double => 1.0, + :required_float => 1.0, + :required_string => "a", + :required_bytes => "b", + :required_enum => A::B::Proto2::TestEnum::A, + :required_msg => A::B::Proto2::TestMessage.new(), + ) + end + def test_generated_msg old_gc = GC.stress GC.stress = 0x01 | 0x04 - from = get_msg + from = get_msg_proto3 data = A::B::C::TestMessage.encode(from) to = A::B::C::TestMessage.decode(data) + + from = get_msg_proto2 + data = A::B::Proto2::TestMessage.encode(from) + to = A::B::Proto2::TestMessage.decode(data) GC.stress = old_gc puts "passed" end |