-
Notifications
You must be signed in to change notification settings - Fork 26
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
Improve oneof
support
#40
Open
m-o-e
wants to merge
11
commits into
jeromegn:master
Choose a base branch
from
m-o-e:improve-oneof-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
82b2f40
Improve `oneof` support
m-o-e 7587e68
Fix comment
m-o-e 8035bd5
Fix potential clash with reserved keywords
m-o-e 53df591
Avoid double-negative
m-o-e 0c22b97
DRY the specs (unify the duplicated tests)
m-o-e 4e8c566
Call setters after deserializing
m-o-e ca66c71
Re-add oneof! invocation (had gotten lost in merge mixup)
m-o-e 83296aa
Add direct getter for oneof value
m-o-e 93f3afc
Restrict return type of oneof-by-name getter
m-o-e 8ae57a8
Fix return type restriction (String/Symbol mixup)
m-o-e 2f015e4
Add *experimental* support for proto3 `optional` (Field Presence)
m-o-e File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#require "protobuf" | ||
|
||
module TestMessagesProto2 | ||
|
||
struct TestOneof1 | ||
include Protobuf::Message | ||
|
||
contract do | ||
optional :a, :int32, 1 | ||
|
||
optional :oo0_a, :int32, 2, oneof_index: 0 | ||
optional :oo0_b, :int32, 3, oneof_index: 0 | ||
optional :oo0_c, :int32, 4, oneof_index: 0 | ||
|
||
optional :b, :int32, 5 | ||
|
||
optional :oo1_a, :int32, 6, oneof_index: 1 | ||
optional :oo1_b, :int32, 7, oneof_index: 1 | ||
optional :oo1_c, :int32, 8, oneof_index: 1 | ||
|
||
oneof 0, "oo0" | ||
oneof 1, "oo1" | ||
end | ||
end | ||
end | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#require "protobuf" | ||
|
||
module TestMessagesProto3 | ||
|
||
struct TestOneof1 | ||
include Protobuf::Message | ||
|
||
contract do | ||
optional :a, :int32, 1 | ||
|
||
optional :oo0_a, :int32, 2, oneof_index: 0 | ||
optional :oo0_b, :int32, 3, oneof_index: 0 | ||
optional :oo0_c, :int32, 4, oneof_index: 0 | ||
|
||
optional :b, :int32, 5 | ||
|
||
optional :oo1_a, :int32, 6, oneof_index: 1 | ||
optional :oo1_b, :int32, 7, oneof_index: 1 | ||
optional :oo1_c, :int32, 8, oneof_index: 1 | ||
|
||
oneof 0, "oo0" | ||
oneof 1, "oo1" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you may have forgotten to commit the
TestOneofMessage.proto
here. That'd be helpful to understand what all of theoo0_*
properties come from. 🙂There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry, I wrote that above file by hand, didn't use an input proto.
(the layout of the fixtures wasn't entirely clear to me so I just did what worked 😅)
The corresponding proto file would look like this:
The goal was to have more than one
oneof
and have itinterleaved with other fields for a meaningful test.
Lemme know if I should add that proto to the repo somewhere
(perhaps as a comment on top of
TestOneofMessage.pb.cr
? 🤔).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, we'd have it there to verify that the generator generates working Crystal code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well
spec/protobuf/generator_spec.cr
is empty. 😬I wasn't sure how these existing fixture files were generated, so I just put mine next to them.
I don't think there's currently anything in the specs that actually invokes the generator,
so not sure where I should put that above proto source. Just drop it into
spec/fixtures/
?