Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(945)

Unified Diff: mojom/generators/go/templates/decoding_test.go

Issue 2061243002: Encode and decode fields of union type. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojom/generators/go/templates/decoding.go ('k') | mojom/generators/go/templates/encoding.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojom/generators/go/templates/decoding_test.go
diff --git a/mojom/generators/go/templates/decoding_test.go b/mojom/generators/go/templates/decoding_test.go
index 43a8b4060ee10c2ccd0129c7e66af5553d238ec3..2cb652df73cbe30db010df7a5046e364114c0dd3 100644
--- a/mojom/generators/go/templates/decoding_test.go
+++ b/mojom/generators/go/templates/decoding_test.go
@@ -162,3 +162,71 @@ if pointer == 0 {
check(t, expected, "FieldDecodingTmpl", encodingInfo)
}
+
+func TestDecodingUnionFieldDecoding(t *testing.T) {
+ expected := `var err error
+s.FUnion, err = DecodeSomeUnion(decoder)
+if err != nil {
+ return err
+}
+if s.FUnion == nil {
+ return &bindings.ValidationError{bindings.UnexpectedNullUnion, "unexpected null union"}
+}`
+
+ encodingInfo := mockEncodingInfo{
+ isUnion: true,
+ identifier: "s.FUnion",
+ goType: "SomeUnion",
+ }
+
+ check(t, expected, "FieldDecodingTmpl", encodingInfo)
+}
+
+func TestDecodingNullableUnionFieldDecoding(t *testing.T) {
+ expected := `var err error
+s.FUnion, err = DecodeSomeUnion(decoder)
+if err != nil {
+ return err
+}`
+
+ encodingInfo := mockEncodingInfo{
+ isNullable: true,
+ isUnion: true,
+ identifier: "s.FUnion",
+ goType: "SomeUnion",
+ }
+
+ check(t, expected, "FieldDecodingTmpl", encodingInfo)
+}
+
+func TestDecodingNestedUnionFieldDecoding(t *testing.T) {
+ expected := `pointer, err := decoder.ReadPointer()
+if err != nil {
+ return err
+}
+if pointer == 0 {
+ return &bindings.ValidationError{bindings.UnexpectedNullPointer, "unexpected null union pointer"}
+} else {
+ if err := decoder.StartNestedUnion(); err != nil {
+ return err
+ }
+ var err error
+ u.Value, err = DecodeSomeUnion(decoder)
+ if err != nil {
+ return err
+ }
+ if u.Value == nil {
+ return &bindings.ValidationError{bindings.UnexpectedNullUnion, "unexpected null union"}
+ }
+ decoder.Finish()
+}`
+
+ encodingInfo := mockEncodingInfo{
+ isPointer: true,
+ isUnion: true,
+ identifier: "u.Value",
+ goType: "SomeUnion",
+ }
+
+ check(t, expected, "FieldDecodingTmpl", encodingInfo)
+}
« no previous file with comments | « mojom/generators/go/templates/decoding.go ('k') | mojom/generators/go/templates/encoding.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698