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

Side by Side 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 unified diff | Download patch
OLDNEW
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 translator 5 package translator
6 6
7 import ( 7 import (
8 "sort" 8 "sort"
9 "testing" 9 "testing"
10 10
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 fileGraph.ResolvedTypes[typeKey] = &mojom_types.UserDefinedTypeStructTyp e{mojomStruct} 205 fileGraph.ResolvedTypes[typeKey] = &mojom_types.UserDefinedTypeStructTyp e{mojomStruct}
206 translator := NewTranslator(&fileGraph) 206 translator := NewTranslator(&fileGraph)
207 207
208 typeRef := &mojom_types.TypeTypeReference{mojom_types.TypeReference{Type Key: &typeKey}} 208 typeRef := &mojom_types.TypeTypeReference{mojom_types.TypeReference{Type Key: &typeKey}}
209 209
210 info := translator.encodingInfo(typeRef) 210 info := translator.encodingInfo(typeRef)
211 211
212 checkEq(t, true, info.IsPointer()) 212 checkEq(t, true, info.IsPointer())
213 checkEq(t, "SomeStruct", info.GoType()) 213 checkEq(t, "SomeStruct", info.GoType())
214 } 214 }
215
216 func TestTranslateMojomUnion(t *testing.T) {
217 field1Name := "f_uint32"
218 field1 := mojom_types.UnionField{
219 DeclData: &mojom_types.DeclarationData{ShortName: &field1Name},
220 Type: &mojom_types.TypeSimpleType{Value: mojom_types.SimpleT ype_Uint32},
221 Tag: 5}
222
223 field2Name := "f_uint16"
224 field2 := mojom_types.UnionField{
225 DeclData: &mojom_types.DeclarationData{ShortName: &field2Name},
226 Type: &mojom_types.TypeSimpleType{Value: mojom_types.SimpleT ype_Uint16},
227 Tag: 6}
228
229 unionName := "foo"
230 union := mojom_types.MojomUnion{
231 DeclData: &mojom_types.DeclarationData{ShortName: &unionName},
232 Fields: []mojom_types.UnionField{field1, field2},
233 }
234
235 graph := mojom_files.MojomFileGraph{}
236 typeKey := "typeKey"
237 graph.ResolvedTypes = map[string]mojom_types.UserDefinedType{
238 typeKey: &mojom_types.UserDefinedTypeUnionType{union},
239 }
240
241 translator := NewTranslator(&graph)
242
243 m := translator.translateMojomUnion(typeKey)
244
245 checkEq(t, "Foo", m.Name)
246 checkEq(t, "FUint32", m.Fields[0].Name)
247 checkEq(t, "uint32", m.Fields[0].Type)
248 checkEq(t, uint32(5), m.Fields[0].Tag)
249 checkEq(t, m, m.Fields[0].Union)
250 checkEq(t, "FUint16", m.Fields[1].Name)
251 checkEq(t, "uint16", m.Fields[1].Type)
252 checkEq(t, uint32(6), m.Fields[1].Tag)
253 checkEq(t, m, m.Fields[1].Union)
254 }
OLDNEW
« mojom/generators/go/templates/templates.go ('K') | « mojom/generators/go/translator/translator.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698