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

Side by Side Diff: mojom/mojom_parser/parser/resolution_test.go

Issue 1767033002: Mojom parser: Compute and validate struct field ordinals. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Maintain the property that the fields of a module.Struct are sorted in declaration order. Created 4 years, 9 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
« no previous file with comments | « mojom/mojom_parser/parser/parsing.go ('k') | mojom/mojom_parser/serialization/serialization.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 parser 5 package parser
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "mojom/mojom_parser/mojom" 9 "mojom/mojom_parser/mojom"
10 "strings" 10 "strings"
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 1038
1039 struct MyStruct { 1039 struct MyStruct {
1040 const Color RED = BLUE; 1040 const Color RED = BLUE;
1041 1041
1042 Color a_color = RED; // This should resolve to the local constant RED, 1042 Color a_color = RED; // This should resolve to the local constant RED,
1043 // and therefore the concrete value should be BLUE. 1043 // and therefore the concrete value should be BLUE.
1044 };` 1044 };`
1045 1045
1046 testFunc := func(descriptor *mojom.MojomDescriptor) error { 1046 testFunc := func(descriptor *mojom.MojomDescriptor) error {
1047 myStructType := descriptor.TypesByKey["TYPE_KEY:MyStruct "].(*mojom.MojomStruct) 1047 myStructType := descriptor.TypesByKey["TYPE_KEY:MyStruct "].(*mojom.MojomStruct)
1048 » » » aColorField := myStructType.Fields[0] 1048 » » » aColorField := myStructType.FieldsInLexicalOrder[0]
1049 concreteValue := aColorField.DefaultValue.ResolvedConcre teValue().(*mojom.EnumValue) 1049 concreteValue := aColorField.DefaultValue.ResolvedConcre teValue().(*mojom.EnumValue)
1050 key := concreteValue.ValueKey() 1050 key := concreteValue.ValueKey()
1051 if key != "TYPE_KEY:Color.BLUE" { 1051 if key != "TYPE_KEY:Color.BLUE" {
1052 return fmt.Errorf("%s != TYPE_KEY:Color.BLUE", k ey) 1052 return fmt.Errorf("%s != TYPE_KEY:Color.BLUE", k ey)
1053 } 1053 }
1054 return nil 1054 return nil
1055 } 1055 }
1056 test.addTestCase("", contents, testFunc) 1056 test.addTestCase("", contents, testFunc)
1057 } 1057 }
1058 1058
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 typeKey = mojom.ComputeTypeKey(t) 1386 typeKey = mojom.ComputeTypeKey(t)
1387 } 1387 }
1388 userDefinedType := descriptor.TypesByKey[typeKey] 1388 userDefinedType := descriptor.TypesByKey[typeKey]
1389 if userDefinedType == nil { 1389 if userDefinedType == nil {
1390 panic(fmt.Sprintf("No type found for: %s", t)) 1390 panic(fmt.Sprintf("No type found for: %s", t))
1391 } 1391 }
1392 typeSet.Add(userDefinedType) 1392 typeSet.Add(userDefinedType)
1393 } 1393 }
1394 return typeSet 1394 return typeSet
1395 } 1395 }
OLDNEW
« no previous file with comments | « mojom/mojom_parser/parser/parsing.go ('k') | mojom/mojom_parser/serialization/serialization.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698