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

Unified Diff: mojom/generators/go/translator/translator_test.go

Issue 2045063002: [New go generator] Implement declaring unions. (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 4e9f44eca3f4baa517d95b98edd1525d0bcd8501..88ccdd665f2784b3b09f42805c5e072ef9933946 100644
--- a/mojom/generators/go/translator/translator_test.go
+++ b/mojom/generators/go/translator/translator_test.go
@@ -212,3 +212,43 @@ func TestStructTypeEncodingInfo(t *testing.T) {
checkEq(t, true, info.IsPointer())
checkEq(t, "SomeStruct", info.GoType())
}
+
+func TestTranslateMojomUnion(t *testing.T) {
+ field1Name := "f_uint32"
+ field1 := mojom_types.UnionField{
+ DeclData: &mojom_types.DeclarationData{ShortName: &field1Name},
+ Type: &mojom_types.TypeSimpleType{Value: mojom_types.SimpleType_Uint32},
+ Tag: 5}
+
+ field2Name := "f_uint16"
+ field2 := mojom_types.UnionField{
+ DeclData: &mojom_types.DeclarationData{ShortName: &field2Name},
+ Type: &mojom_types.TypeSimpleType{Value: mojom_types.SimpleType_Uint16},
+ Tag: 6}
+
+ unionName := "foo"
+ union := mojom_types.MojomUnion{
+ DeclData: &mojom_types.DeclarationData{ShortName: &unionName},
+ Fields: []mojom_types.UnionField{field1, field2},
+ }
+
+ graph := mojom_files.MojomFileGraph{}
+ typeKey := "typeKey"
+ graph.ResolvedTypes = map[string]mojom_types.UserDefinedType{
+ typeKey: &mojom_types.UserDefinedTypeUnionType{union},
+ }
+
+ translator := NewTranslator(&graph)
+
+ m := translator.translateMojomUnion(typeKey)
+
+ checkEq(t, "Foo", m.Name)
+ checkEq(t, "FUint32", m.Fields[0].Name)
+ checkEq(t, "uint32", m.Fields[0].Type)
+ checkEq(t, uint32(5), m.Fields[0].Tag)
+ checkEq(t, m, m.Fields[0].Union)
+ checkEq(t, "FUint16", m.Fields[1].Name)
+ checkEq(t, "uint16", m.Fields[1].Type)
+ checkEq(t, uint32(6), m.Fields[1].Tag)
+ checkEq(t, m, m.Fields[1].Union)
+}
« 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