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

Side by Side Diff: mojom/mojom_tool/integration_tests/resolution_test.go

Issue 1933563002: Mojom frontend: Start populating |resolved_concrete_value| field in mojom_types.mojom (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Grammar fix. Created 4 years, 7 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 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_tool/mojom" 9 "mojom/mojom_tool/mojom"
10 "mojom/mojom_tool/parser" 10 "mojom/mojom_tool/parser"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 };` 100 };`
101 101
102 test.addTestCase(contents, []string{ 102 test.addTestCase(contents, []string{
103 "Undefined type: \"Bar\"", "Undefined type: \"Baz\"", 103 "Undefined type: \"Bar\"", "Undefined type: \"Baz\"",
104 "Undefined value: \"Boom\"", "Undefined value: \"Bing\"" , 104 "Undefined value: \"Boom\"", "Undefined value: \"Bing\"" ,
105 "Use of unresolved value: \"X\"", 105 "Use of unresolved value: \"X\"",
106 "^^^^"}) // There will be four carets in the snippet bec ause of "Boom" 106 "^^^^"}) // There will be four carets in the snippet bec ause of "Boom"
107 } 107 }
108 108
109 //////////////////////////////////////////////////////////// 109 ////////////////////////////////////////////////////////////
110 // Test Case: Circular reference of constants
111 ////////////////////////////////////////////////////////////
112 {
113 contents := `
114 const int32 MyConst1 = MyConst2;
115 const int32 MyConst2 = MyConst3;
116 const int32 MyConst3 = MyConst1;`
117
118 test.addTestCase(contents, []string{
119 "Use of unresolved value: \"MyConst2\"",
120 "Use of unresolved value: \"MyConst3\"",
121 "Use of unresolved value: \"MyConst1\"",
122 })
123 }
124
125 ////////////////////////////////////////////////////////////
110 // Execute all of the test cases. 126 // Execute all of the test cases.
111 //////////////////////////////////////////////////////////// 127 ////////////////////////////////////////////////////////////
112 for i, c := range test.cases { 128 for i, c := range test.cases {
113 // Parse and resolve the mojom input. 129 // Parse and resolve the mojom input.
114 descriptor := mojom.NewMojomDescriptor() 130 descriptor := mojom.NewMojomDescriptor()
115 specifiedName := "" 131 specifiedName := ""
116 if c.importedFrom == nil { 132 if c.importedFrom == nil {
117 specifiedName = c.fileName 133 specifiedName = c.fileName
118 } 134 }
119 parser := parser.MakeParser(c.fileName, specifiedName, c.mojomCo ntents, descriptor, c.importedFrom) 135 parser := parser.MakeParser(c.fileName, specifiedName, c.mojomCo ntents, descriptor, c.importedFrom)
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 key := concreteValue.ValueKey() 1067 key := concreteValue.ValueKey()
1052 if key != "TYPE_KEY:Color.BLUE" { 1068 if key != "TYPE_KEY:Color.BLUE" {
1053 return fmt.Errorf("%s != TYPE_KEY:Color.BLUE", k ey) 1069 return fmt.Errorf("%s != TYPE_KEY:Color.BLUE", k ey)
1054 } 1070 }
1055 return nil 1071 return nil
1056 } 1072 }
1057 test.addTestCase("", contents, testFunc) 1073 test.addTestCase("", contents, testFunc)
1058 } 1074 }
1059 1075
1060 //////////////////////////////////////////////////////////// 1076 ////////////////////////////////////////////////////////////
1077 // Test Case: A non-circular list of constant references.
1078 ////////////////////////////////////////////////////////////
1079 {
1080 contents := `
1081 const int32 MyConst1 = MyConst2;
1082 const int32 MyConst2 = MyConst3;
1083 const int32 MyConst3 = 42;`
1084
1085 testFunc := func(descriptor *mojom.MojomDescriptor) error {
1086 myConst1 := descriptor.ValuesByKey["TYPE_KEY:MyConst1"]. (*mojom.UserDefinedConstant)
1087 value := myConst1.ValueRef().ResolvedConcreteValue().Val ue()
1088 if value != int8(42) {
1089 return fmt.Errorf("%v(%T) != 42", value, value)
1090 }
1091
1092 return nil
1093 }
1094 test.addTestCase("", contents, testFunc)
1095 }
1096
1097 ////////////////////////////////////////////////////////////
1098 // Test Case: Circular reference of enum values
1099 //
1100 // NOTE: Even though we have a circular reference of enum values
1101 // this case passes resolution. But the error will be detected during
1102 // data computation phase when we attempt to produce integer values
1103 // for the enum values. See TestEnumComputedDataError in computed_data_t est.go. The reason this
1104 // passes resoultion is that an enum value is a concrete value and so
1105 // FIRST_VALUE has fully resolved to the concrete value MyEnum.x.
1106 ////////////////////////////////////////////////////////////
1107 {
1108 contents := `
1109 enum MyEnum {
1110 x = FIRST_VALUE,
1111 y,
1112 z
1113 };
1114 const MyEnum FIRST_VALUE = MyEnum.x;`
1115 test.addTestCase("", contents, nil)
1116 }
1117
1118 ////////////////////////////////////////////////////////////
1061 // Execute all of the test cases. 1119 // Execute all of the test cases.
1062 //////////////////////////////////////////////////////////// 1120 ////////////////////////////////////////////////////////////
1063 for i, c := range test.cases { 1121 for i, c := range test.cases {
1064 // Parse and resolve the mojom input. 1122 // Parse and resolve the mojom input.
1065 descriptor := mojom.NewMojomDescriptor() 1123 descriptor := mojom.NewMojomDescriptor()
1066 fileName := fmt.Sprintf("file%d", i) 1124 fileName := fmt.Sprintf("file%d", i)
1067 parser := parser.MakeParser(fileName, fileName, c.mojomContents, descriptor, nil) 1125 parser := parser.MakeParser(fileName, fileName, c.mojomContents, descriptor, nil)
1068 parser.Parse() 1126 parser.Parse()
1069 if !parser.OK() { 1127 if !parser.OK() {
1070 t.Errorf("Parsing error for %s: %s", fileName, parser.Ge tError().Error()) 1128 t.Errorf("Parsing error for %s: %s", fileName, parser.Ge tError().Error())
1071 continue 1129 continue
1072 } 1130 }
1073 err := descriptor.Resolve() 1131 err := descriptor.Resolve()
1074 if err != nil { 1132 if err != nil {
1075 t.Errorf("Resolution failed for test case %d: %s", i, er r.Error()) 1133 t.Errorf("Resolution failed for test case %d: %s", i, er r.Error())
1076 continue 1134 continue
1077 } 1135 }
1078 1136
1079 if c.testFunc != nil { 1137 if c.testFunc != nil {
1080 if err := c.testFunc(descriptor); err != nil { 1138 if err := c.testFunc(descriptor); err != nil {
1081 t.Errorf("%s:\n%s", fileName, err.Error()) 1139 t.Errorf("%s:\n%s", fileName, err.Error())
1082 continue 1140 continue
1083 } 1141 }
1084 } 1142 }
1085 } 1143 }
1086 } 1144 }
OLDNEW
« no previous file with comments | « mojom/mojom_tool/integration_tests/computed_data_test.go ('k') | mojom/mojom_tool/mojom/user_defined_types.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698