-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Requested in #109
- Loading branch information
Showing
2 changed files
with
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1024,3 +1024,55 @@ unittest | |
assert(proto.a1.foo1 == proto.a2.foo1); | ||
} | ||
|
||
unittest | ||
{ | ||
mixin ProtocolBufferFromString!" | ||
message Person { | ||
required string name = 1; | ||
required int32 id = 2; | ||
optional string email = 3; | ||
enum PhoneType { | ||
MOBILE = 0; | ||
HOME = 0; | ||
WORK = 2; | ||
} | ||
message PhoneNumber { | ||
required string number = 1; | ||
optional PhoneType type = 2 [default = HOME]; | ||
} | ||
repeated PhoneNumber phone = 4; | ||
} | ||
"; | ||
|
||
Person t; | ||
t.name = "Max Musterman"; | ||
t.id = 3; | ||
t.email = "[email protected]"; | ||
|
||
Person.PhoneNumber pn1; | ||
pn1.number = "0123456789"; | ||
pn1.type = Person.PhoneType.WORK; | ||
t.phone ~= pn1; | ||
|
||
Person t2 = t; | ||
t2.id = 5; | ||
t2.email = "[email protected]"; | ||
|
||
Person.PhoneNumber pn2; | ||
pn2.number = "9876543210"; | ||
pn2.type = Person.PhoneType.HOME; | ||
t2.phone = [pn2]; | ||
|
||
import std.stdio; | ||
t.mergeFrom(t2); | ||
assert(t.phone.length == 2); | ||
assert(t.phone[0] == pn1); | ||
assert(t.phone[1] == pn2); | ||
assert(t.id == t.id); | ||
assert(t.email == t2.email); | ||
|
||
} | ||
|