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

Unified Diff: mojom/mojom_tool/integration_tests/computed_data_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, 8 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 side-by-side diff with in-line comments
Download patch
Index: mojom/mojom_tool/integration_tests/computed_data_test.go
diff --git a/mojom/mojom_tool/integration_tests/computed_data_test.go b/mojom/mojom_tool/integration_tests/computed_data_test.go
index c286efefada7161e1591850e1098d7327e7f1d8a..d18fda2627923d53df570456bd4a6e47de469821 100644
--- a/mojom/mojom_tool/integration_tests/computed_data_test.go
+++ b/mojom/mojom_tool/integration_tests/computed_data_test.go
@@ -913,3 +913,133 @@ func TestInterfaceComputedData(t *testing.T) {
}
}
}
+
+// TestEnumComputedDataErrors test the method MojomEnum.ComputeEnumValueIntegers which
+// is invoked by ComputeFinalData. This phase occurs after resolution
+// and type validation. We test that different types of errors are correctly detected.
+func TestEnumComputedDataErrors(t *testing.T) {
+ test := singleFileTest{}
+
+ ////////////////////////////////////////////////////////////
+ // Test Case: Test that a circular reference of enum value definitions is detected.
+ ////////////////////////////////////////////////////////////
+ {
+ contents := `
+ enum MyEnum {
+ x = FIRST_VALUE,
+ y,
+ z
+ };
+ const MyEnum FIRST_VALUE = MyEnum.x;`
+ test.addTestCase(contents, []string{
+ "The reference FIRST_VALUE is being used as an enum value initializer",
+ "but it has resolved to a different enum value that itself does not yet have an integer value."})
+ }
+
+ ////////////////////////////////////////////////////////////
+ // Execute all of the test cases.
+ ////////////////////////////////////////////////////////////
+ for i, c := range test.cases {
+ // Parse anresolve the mojom input.
+ descriptor := mojom.NewMojomDescriptor()
+ specifiedName := ""
+ if c.importedFrom == nil {
+ specifiedName = c.fileName
+ }
+ parser := parser.MakeParser(c.fileName, specifiedName, c.mojomContents, descriptor, c.importedFrom)
+ parser.Parse()
+ if !parser.OK() {
+ t.Errorf("Parsing error for %s: %s", c.fileName, parser.GetError().Error())
+ continue
+ }
+ err := descriptor.Resolve()
+ if err != nil {
+ t.Errorf("Resolution error for %s: %s", c.fileName, err)
+ continue
+ }
+
+ err = descriptor.ComputeFinalData()
+
+ if err == nil {
+ t.Errorf("Data computation unexpectedly succeeded for test case %d.", i)
+ continue
+ }
+
+ got := err.Error()
+ for _, expected := range c.expectedErrors {
+ if !strings.Contains(got, expected) {
+ t.Errorf("%s:\n*****expected to contain:\n%s\n****actual\n%s", c.fileName, expected, got)
+ }
+ }
+ }
+}
+
+// TestEnumComputedData() iterates through a series of test cases.
+// For each case we expect for parsing, resolution and final data computation to succeed.
+// Then we execute a given callback test function to test that the methods
+// MojomEnum.ComputeFinalData() produced the desired result.
+func TestEnumComputedData(t *testing.T) {
+ test := singleFileSuccessTest{}
+
+ ////////////////////////////////////////////////////////////
+ // Test Case: A non-circular chain of enum value definitions.
+ ////////////////////////////////////////////////////////////
+ {
+ contents := `
+ enum MyEnum {
+ x,
+ y = FIRST_VALUE,
+ z
+ };
+ const MyEnum FIRST_VALUE = MyEnum.x;`
+
+ testFunc := func(descriptor *mojom.MojomDescriptor) error {
+ xValue := descriptor.ValuesByKey["TYPE_KEY:MyEnum.x"].(*mojom.EnumValue)
+ yValue := descriptor.ValuesByKey["TYPE_KEY:MyEnum.y"].(*mojom.EnumValue)
+ zValue := descriptor.ValuesByKey["TYPE_KEY:MyEnum.z"].(*mojom.EnumValue)
+ if xValue.ComputedIntValue != 0 {
+ return fmt.Errorf("xValue.ComputedIntValue=%d", xValue.ComputedIntValue)
+ }
+ if yValue.ComputedIntValue != 0 {
+ return fmt.Errorf("yValue.ComputedIntValue=%d", yValue.ComputedIntValue)
+ }
+ if zValue.ComputedIntValue != 1 {
+ return fmt.Errorf("zValue.ComputedIntValue=%d", zValue.ComputedIntValue)
+ }
+ return nil
+ }
+ test.addTestCase("", contents, testFunc)
+ }
+
+ ////////////////////////////////////////////////////////////
+ // Execute all of the test cases.
+ ////////////////////////////////////////////////////////////
+ for i, c := range test.cases {
+ // Parse and resolve the mojom input.
+ descriptor := mojom.NewMojomDescriptor()
+ fileName := fmt.Sprintf("file%d", i)
+ parser := parser.MakeParser(fileName, fileName, c.mojomContents, descriptor, nil)
+ parser.Parse()
+ if !parser.OK() {
+ t.Errorf("Parsing error for %s: %s", fileName, parser.GetError().Error())
+ continue
+ }
+ err := descriptor.Resolve()
+ if err != nil {
+ t.Errorf("Resolution failed for test case %d: %s", i, err.Error())
+ continue
+ }
+
+ if err := descriptor.ComputeFinalData(); err != nil {
+ t.Errorf("ComputeFinalData error for test case %d: %s", i, err.Error())
+ continue
+ }
+
+ if c.testFunc != nil {
+ if err := c.testFunc(descriptor); err != nil {
+ t.Errorf("%s:\n%s", fileName, err.Error())
+ continue
+ }
+ }
+ }
+}
« no previous file with comments | « mojom/generated/mojom_types/mojom_types.mojom.go ('k') | mojom/mojom_tool/integration_tests/resolution_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698