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

Unified Diff: mojom/generators/go/templates/structs_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/templates/structs.go ('k') | mojom/generators/go/templates/templates.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojom/generators/go/templates/structs_test.go
diff --git a/mojom/generators/go/templates/structs_test.go b/mojom/generators/go/templates/structs_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..e42f8cb80fa1185e71b8bef0cad98d34d4155eb9
--- /dev/null
+++ b/mojom/generators/go/templates/structs_test.go
@@ -0,0 +1,55 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package templates
+
+import (
+ "testing"
+
+ "mojom/generators/go/translator"
+)
+
+func TestStructDecl(t *testing.T) {
+ expected := `type Foo struct {
+ Alpha string
+ Beta uint32
+}`
+
+ s := translator.StructTemplate{
+ Name: "Foo",
+ Fields: []translator.StructFieldTemplate{
+ {Name: "Alpha", Type: "string"},
+ {Name: "Beta", Type: "uint32"},
+ },
+ }
+
+ check(t, expected, "StructDecl", s)
+}
+
+func TestDecodingStructVersions(t *testing.T) {
+ expected := `var someStruct_Versions []bindings.DataHeader = []bindings.DataHeader{
+ bindings.DataHeader{80, 0},
+ bindings.DataHeader{100, 1},
+ bindings.DataHeader{120, 2},
+}`
+
+ type structVersion struct {
+ NumBytes uint32
+ Version uint32
+ }
+
+ s := struct {
+ PrivateName string
+ Versions []structVersion
+ }{
+ PrivateName: "someStruct",
+ Versions: []structVersion{
+ {80, 0},
+ {100, 1},
+ {120, 2},
+ },
+ }
+
+ check(t, expected, "StructVersions", s)
+}
« no previous file with comments | « mojom/generators/go/templates/structs.go ('k') | mojom/generators/go/templates/templates.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698