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

Unified Diff: mojom/generators/go/translator/translator_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/translator/translator.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojom/generators/go/translator/translator_test.go
diff --git a/mojom/generators/go/translator/translator_test.go b/mojom/generators/go/translator/translator_test.go
index 88ccdd665f2784b3b09f42805c5e072ef9933946..40d625ba832bf11b5eb77ba097050b6f033c7a2c 100644
--- a/mojom/generators/go/translator/translator_test.go
+++ b/mojom/generators/go/translator/translator_test.go
@@ -213,6 +213,31 @@ func TestStructTypeEncodingInfo(t *testing.T) {
checkEq(t, "SomeStruct", info.GoType())
}
+func TestUnionTypeEncodingInfo(t *testing.T) {
+ fileGraph := mojom_files.MojomFileGraph{}
+ shortName := "SomeUnion"
+ typeKey := "typeKey"
+
+ mojomUnion := mojom_types.MojomUnion{
+ DeclData: &mojom_types.DeclarationData{ShortName: &shortName}}
+ fileGraph.ResolvedTypes = map[string]mojom_types.UserDefinedType{}
+ fileGraph.ResolvedTypes[typeKey] = &mojom_types.UserDefinedTypeUnionType{mojomUnion}
+ translator := NewTranslator(&fileGraph)
+
+ typeRef := &mojom_types.TypeTypeReference{mojom_types.TypeReference{TypeKey: &typeKey}}
+
+ info := translator.encodingInfo(typeRef)
+
+ checkEq(t, true, info.IsUnion())
+ checkEq(t, false, info.IsPointer())
+ checkEq(t, uint32(128), info.BitSize())
+ checkEq(t, "SomeUnion", info.GoType())
+
+ info.(*unionTypeEncodingInfo).nestedUnion = true
+ checkEq(t, true, info.IsPointer())
+ checkEq(t, uint32(64), info.BitSize())
+}
+
func TestTranslateMojomUnion(t *testing.T) {
field1Name := "f_uint32"
field1 := mojom_types.UnionField{
« no previous file with comments | « mojom/generators/go/translator/translator.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698