| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package templates | 5 package templates |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "fmt" | 9 "fmt" |
| 10 "strings" | 10 "strings" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 s := translator.StructTemplate{ | 44 s := translator.StructTemplate{ |
| 45 Name: "Foo", | 45 Name: "Foo", |
| 46 Fields: []translator.StructFieldTemplate{ | 46 Fields: []translator.StructFieldTemplate{ |
| 47 {Name: "Alpha", Type: "string"}, | 47 {Name: "Alpha", Type: "string"}, |
| 48 {Name: "Beta", Type: "uint32"}, | 48 {Name: "Beta", Type: "uint32"}, |
| 49 }, | 49 }, |
| 50 } | 50 } |
| 51 | 51 |
| 52 check(t, expected, "StructDecl", s) | 52 check(t, expected, "StructDecl", s) |
| 53 } | 53 } |
| 54 |
| 55 func TestUnionInterfaceDecl(t *testing.T) { |
| 56 expected := `type SomeUnion interface { |
| 57 Tag() uint32 |
| 58 Interface() interface{} |
| 59 __Reflect(__SomeUnionReflect) |
| 60 Encode(encoder *bindings.Encoder) error |
| 61 } |
| 62 |
| 63 type __SomeUnionReflect struct { |
| 64 Alpha string |
| 65 Beta uint32 |
| 66 }` |
| 67 |
| 68 union := translator.UnionTemplate{ |
| 69 Name: "SomeUnion", |
| 70 Fields: []translator.UnionFieldTemplate{ |
| 71 {Name: "Alpha", Type: "string"}, |
| 72 {Name: "Beta", Type: "uint32"}, |
| 73 }, |
| 74 } |
| 75 |
| 76 check(t, expected, "UnionInterfaceDecl", union) |
| 77 } |
| 78 |
| 79 func TestUnionFieldDecl(t *testing.T) { |
| 80 expected := `type SomeUnionAlpha struct{ Value string } |
| 81 |
| 82 func (u *SomeUnionAlpha) Tag() uint32 { return 5 } |
| 83 func (u *SomeUnionAlpha) Interface() interface{} { return u.Value } |
| 84 func (u *SomeUnionAlpha) __Reflect(__SomeUnionReflect) {}` |
| 85 |
| 86 union := translator.UnionTemplate{Name: "SomeUnion"} |
| 87 |
| 88 field := translator.UnionFieldTemplate{ |
| 89 Name: "Alpha", |
| 90 Type: "string", |
| 91 Tag: 5, |
| 92 Union: &union, |
| 93 } |
| 94 |
| 95 check(t, expected, "UnionFieldDecl", field) |
| 96 } |
| OLD | NEW |