Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: third_party/protobuf/ruby/tests/basic.rb

Issue 1983203003: Update third_party/protobuf to protobuf-v3.0.0-beta-3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: owners Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/ruby 1 #!/usr/bin/ruby
2 2
3 require 'google/protobuf' 3 require 'google/protobuf'
4 require 'test/unit' 4 require 'test/unit'
5 5
6 # ------------- generated code -------------- 6 # ------------- generated code --------------
7 7
8 module BasicTest 8 module BasicTest
9 pool = Google::Protobuf::DescriptorPool.new 9 pool = Google::Protobuf::DescriptorPool.new
10 pool.build do 10 pool.build do
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 def test_hash 184 def test_hash
185 m1 = TestMessage.new(:optional_int32 => 42) 185 m1 = TestMessage.new(:optional_int32 => 42)
186 m2 = TestMessage.new(:optional_int32 => 102) 186 m2 = TestMessage.new(:optional_int32 => 102)
187 assert m1.hash != 0 187 assert m1.hash != 0
188 assert m2.hash != 0 188 assert m2.hash != 0
189 # relying on the randomness here -- if hash function changes and we are 189 # relying on the randomness here -- if hash function changes and we are
190 # unlucky enough to get a collision, then change the values above. 190 # unlucky enough to get a collision, then change the values above.
191 assert m1.hash != m2.hash 191 assert m1.hash != m2.hash
192 end 192 end
193 193
194 def test_unknown_field_errors
195 e = assert_raise NoMethodError do
196 TestMessage.new.hello
197 end
198 assert_match(/hello/, e.message)
199
200 e = assert_raise NoMethodError do
201 TestMessage.new.hello = "world"
202 end
203 assert_match(/hello/, e.message)
204 end
205
206 def test_initialization_map_errors
207 e = assert_raise ArgumentError do
208 TestMessage.new(:hello => "world")
209 end
210 assert_match(/hello/, e.message)
211
212 e = assert_raise ArgumentError do
213 MapMessage.new(:map_string_int32 => "hello")
214 end
215 assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32'."
216
217 e = assert_raise ArgumentError do
218 TestMessage.new(:repeated_uint32 => "hello")
219 end
220 assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32'."
221 end
222
194 def test_type_errors 223 def test_type_errors
195 m = TestMessage.new 224 m = TestMessage.new
196 assert_raise TypeError do 225 assert_raise TypeError do
197 m.optional_int32 = "hello" 226 m.optional_int32 = "hello"
198 end 227 end
199 assert_raise TypeError do 228 assert_raise TypeError do
200 m.optional_string = 42 229 m.optional_string = 42
201 end 230 end
202 assert_raise TypeError do 231 assert_raise TypeError do
203 m.optional_string = nil 232 m.optional_string = nil
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 baz2 = Baz.new(msg: "quux") 1153 baz2 = Baz.new(msg: "quux")
1125 Foo.encode_json(Foo.new) 1154 Foo.encode_json(Foo.new)
1126 Foo.encode_json(Foo.new(bar: bar)) 1155 Foo.encode_json(Foo.new(bar: bar))
1127 Foo.encode_json(Foo.new(bar: bar, baz: [baz1, baz2])) 1156 Foo.encode_json(Foo.new(bar: bar, baz: [baz1, baz2]))
1128 end 1157 end
1129 1158
1130 def test_json_maps 1159 def test_json_maps
1131 # TODO: Fix JSON in JRuby version. 1160 # TODO: Fix JSON in JRuby version.
1132 return if RUBY_PLATFORM == "java" 1161 return if RUBY_PLATFORM == "java"
1133 m = MapMessage.new(:map_string_int32 => {"a" => 1}) 1162 m = MapMessage.new(:map_string_int32 => {"a" => 1})
1134 expected = '{"map_string_int32":{"a":1},"map_string_msg":{}}' 1163 expected = '{"mapStringInt32":{"a":1},"mapStringMsg":{}}'
1164 expected_preserve = '{"map_string_int32":{"a":1},"map_string_msg":{}}'
1135 assert MapMessage.encode_json(m) == expected 1165 assert MapMessage.encode_json(m) == expected
1166
1167 json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true)
1168 assert json == expected_preserve
1169
1136 m2 = MapMessage.decode_json(MapMessage.encode_json(m)) 1170 m2 = MapMessage.decode_json(MapMessage.encode_json(m))
1137 assert m == m2 1171 assert m == m2
1138 end 1172 end
1139 end 1173 end
1140 end 1174 end
OLDNEW
« no previous file with comments | « third_party/protobuf/ruby/src/main/sentinel.proto ('k') | third_party/protobuf/ruby/tests/generated_code.rb » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698