File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -392,6 +392,7 @@ defmodule Protobuf.JSON.Decode do
392
392
end
393
393
394
394
defp decode_float ( float ) when is_float ( float ) , do: { :ok , float }
395
+ defp decode_float ( integer ) when is_integer ( integer ) , do: { :ok , integer / 1 }
395
396
defp decode_float ( string ) when is_binary ( string ) , do: parse_float ( string )
396
397
defp decode_float ( _bad ) , do: :error
397
398
Original file line number Diff line number Diff line change @@ -238,6 +238,10 @@ defmodule Protobuf.JSON.DecodeTest do
238
238
data = % { "float" => 1.23e3 , "double" => 1.23e-2 }
239
239
decoded = % Scalars { float: 1230.0 , double: 0.0123 }
240
240
assert decode ( data , Scalars ) == { :ok , decoded }
241
+
242
+ data = % { "float" => 5 , "double" => 9 }
243
+ decoded = % Scalars { float: 5.0 , double: 9.0 }
244
+ assert decode ( data , Scalars ) == { :ok , decoded }
241
245
end
242
246
243
247
test "constants are valid" do
@@ -279,8 +283,8 @@ defmodule Protobuf.JSON.DecodeTest do
279
283
end
280
284
281
285
test "other types are invalid" do
282
- data = % { "float" => 5 }
283
- msg = "Field 'float' has an invalid floating point (5 )"
286
+ data = % { "float" => << 1 :: 15 >> }
287
+ msg = "Field 'float' has an invalid floating point (<<0, 1::size(7)>> )"
284
288
assert decode ( data , Scalars ) == error ( msg )
285
289
286
290
data = % { "double" => true }
You can’t perform that action at this time.
0 commit comments