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

Unified Diff: mojom/generators/go/templates/declarations_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
Index: mojom/generators/go/templates/declarations_test.go
diff --git a/mojom/generators/go/templates/declarations_test.go b/mojom/generators/go/templates/declarations_test.go
index 5b4b3329a6096069dcb38968d0a8a7cfd9463828..899ad97cf6917dfd9e43a3f79afc58968718f27e 100644
--- a/mojom/generators/go/templates/declarations_test.go
+++ b/mojom/generators/go/templates/declarations_test.go
@@ -51,3 +51,46 @@ func TestStructDecl(t *testing.T) {
check(t, expected, "StructDecl", s)
}
+
+func TestUnionInterfaceDecl(t *testing.T) {
+ expected := `type SomeUnion interface {
+ Tag() uint32
+ Interface() interface{}
+ __Reflect(__SomeUnionReflect)
+ Encode(encoder *bindings.Encoder) error
+}
+
+type __SomeUnionReflect struct {
+ Alpha string
+ Beta uint32
+}`
+
+ union := translator.UnionTemplate{
+ Name: "SomeUnion",
+ Fields: []translator.UnionFieldTemplate{
+ {Name: "Alpha", Type: "string"},
+ {Name: "Beta", Type: "uint32"},
+ },
+ }
+
+ check(t, expected, "UnionInterfaceDecl", union)
+}
+
+func TestUnionFieldDecl(t *testing.T) {
+ expected := `type SomeUnionAlpha struct{ Value string }
+
+func (u *SomeUnionAlpha) Tag() uint32 { return 5 }
+func (u *SomeUnionAlpha) Interface() interface{} { return u.Value }
+func (u *SomeUnionAlpha) __Reflect(__SomeUnionReflect) {}`
+
+ union := translator.UnionTemplate{Name: "SomeUnion"}
+
+ field := translator.UnionFieldTemplate{
+ Name: "Alpha",
+ Type: "string",
+ Tag: 5,
+ Union: &union,
+ }
+
+ check(t, expected, "UnionFieldDecl", field)
+}

Powered by Google App Engine
This is Rietveld 408576698