goprotobuf: Make text parsing functions return RequiredNotSetError as appropriate.
This permits a program to ignore unset required fields when decoding text
just as they can already do when decoding the wire format.
It has the downside of no longer always returning a ParseError unfortunately.
LGTM=gmlewis
R=gmlewis
CC=golang-codereviews
https://codereview.appspot.com/159800043
diff --git a/proto/text_parser_test.go b/proto/text_parser_test.go
index d043769..7cdd579 100644
--- a/proto/text_parser_test.go
+++ b/proto/text_parser_test.go
@@ -294,8 +294,11 @@
// Missing required field
{
- in: ``,
- err: `line 1.0: message testdata.MyMessage missing required field "count"`,
+ in: `name: "Pawel"`,
+ err: `proto: required field "testdata.MyMessage.count" not set`,
+ out: &MyMessage{
+ Name: String("Pawel"),
+ },
},
// Repeated non-repeated field
@@ -408,6 +411,9 @@
} else if err.Error() != test.err {
t.Errorf("Test %d: Incorrect error.\nHave: %v\nWant: %v",
i, err.Error(), test.err)
+ } else if _, ok := err.(*RequiredNotSetError); ok && test.out != nil && !reflect.DeepEqual(pb, test.out) {
+ t.Errorf("Test %d: Incorrect populated \nHave: %v\nWant: %v",
+ i, pb, test.out)
}
}
}