forked from google/starlark-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib/proto: Allow replacing repeated fields, instead of appending. (go…
…ogle#440) * lib/proto: Allow replacing repeated fields, instead of appending. Consider the following Stralark line: msg.repeated = [1,2,3] Without this commit, that line appends three elements to the previous existing repeated values. With this commit, that line replaces the previous repeated values with new three items. I believe the old semantics is simply a bug, and that most users would expect an assignment to overwrite the previous value. * Add a small test for lib/proto * Use list.Truncate(0) instead of msg.Clear Co-authored-by: Wojciech Ptak <[email protected]>
- Loading branch information
Showing
3 changed files
with
24 additions
and
0 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Tests of the experimental 'lib/proto' module. | ||
|
||
load("assert.star", "assert") | ||
load("proto.star", "proto") | ||
|
||
schema = proto.file("google/protobuf/descriptor.proto") | ||
|
||
m = schema.FileDescriptorProto(name = "somename.proto", dependency = ["a", "b", "c"]) | ||
assert.eq(type(m), "proto.Message") | ||
assert.eq(m.name, "somename.proto") | ||
assert.eq(list(m.dependency), ["a", "b", "c"]) | ||
m.dependency = ["d", "e"] | ||
assert.eq(list(m.dependency), ["d", "e"]) | ||
|