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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package templates
6
7 import (
8 "bytes"
9 "fmt"
10 "strings"
11 "testing"
12
13 "mojom/generators/go/gofmt"
14 "mojom/generators/go/translator"
15 )
16
17 func check(t *testing.T, expected string, template string, input interface{}) {
18 buffer := &bytes.Buffer{}
19 if err := goFileTmpl.ExecuteTemplate(buffer, template, input); err != ni l {
20 panic(err)
21 }
22
23 src := buffer.String()
24 actual, err := gofmt.FormatFragment(src)
25 if err != nil {
26 t.Fatalf("Formatting failed: %s\n%s\n", err, src)
27 }
28
29 if expected != actual {
30 errorMsg := fmt.Sprintf("Failed check: Expected\n%s\nActual\n%s\ n", expected, actual)
31 if strings.TrimSpace(expected) == strings.TrimSpace(actual) {
32 errorMsg = fmt.Sprintf("%s\nTrailing or leading spaces d iffer.\n", errorMsg)
33 }
34 t.Fatalf(errorMsg)
35 }
36 }
37
38 func TestStructDecl(t *testing.T) {
39 expected := `type Foo struct {
40 Alpha string
41 Beta uint32
42 }`
43
44 s := translator.StructTemplate{
45 Name: "Foo",
46 Fields: []translator.StructFieldTemplate{
47 {Name: "Alpha", Type: "string"},
48 {Name: "Beta", Type: "uint32"},
49 },
50 }
51
52 check(t, expected, "StructDecl", s)
53 }
OLDNEW
« no previous file with comments | « mojom/generators/go/templates/declarations.go ('k') | mojom/generators/go/templates/decoding.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698