-
Notifications
You must be signed in to change notification settings - Fork 153
Add warning when implicitly casting maps/keywords to struct encode-time #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
ecb3958
72681f2
f348ea4
0de37a4
8d2f0ae
ad89e76
835e11e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,7 +184,10 @@ defmodule Protobuf.EncoderTest do | |
| end | ||
|
|
||
| test "encodes map with oneof" do | ||
| msg = %Google.Protobuf.Struct{fields: %{"valid" => %{kind: {:bool_value, true}}}} | ||
| msg = %Google.Protobuf.Struct{ | ||
| fields: %{"valid" => %Google.Protobuf.Value{kind: {:bool_value, true}}} | ||
| } | ||
|
|
||
| bin = Google.Protobuf.Struct.encode(msg) | ||
|
|
||
| assert Google.Protobuf.Struct.decode(bin) == | ||
|
|
@@ -283,9 +286,7 @@ defmodule Protobuf.EncoderTest do | |
| Encoder.encode(%TestMsg.Foo{c: 123}) | ||
| end | ||
|
|
||
| # For Elixir 1.18+ it's `type Integer`, before, it was just `123` | ||
| # TODO: fix once we require Elixir 1.18+ | ||
| message = ~r/protocol Enumerable not implemented for (123|type Integer)/ | ||
| message = ~r/123 is invalid for type TestMsg.Foo.Bar/ | ||
|
|
||
| assert_raise Protobuf.EncodeError, message, fn -> | ||
| Encoder.encode(%TestMsg.Foo{e: 123}) | ||
|
|
@@ -309,6 +310,15 @@ defmodule Protobuf.EncoderTest do | |
| end | ||
| end | ||
|
|
||
| test "gives a warning for implicitly cast structs" do | ||
| warning = | ||
| ExUnit.CaptureIO.capture_io(:stderr, fn -> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes this test not really async-friendly anymore. Can we turn it to
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great point, added! |
||
| assert <<50, 2, 8, 1>> = Encoder.encode(%TestMsg.Foo{e: %{a: 1}}) | ||
| end) | ||
|
|
||
| assert warning =~ "Implicitly casting from %{a: 1} to TestMsg.Foo.Bar" | ||
| end | ||
|
|
||
| test "encodes with transformer module" do | ||
| msg = %TestMsg.ContainsTransformModule{field: 0} | ||
| assert Encoder.encode(msg) == <<10, 0>> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.