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

Side by Side Diff: mojom/mojom_tool/serialization/serialization_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
« no previous file with comments | « mojom/mojom_tool/serialization/serialization.go ('k') | no next file » | 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 serialization 5 package serialization
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "compress/gzip" 9 "compress/gzip"
10 "encoding/base64" 10 "encoding/base64"
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 test.expectedGraph().ResolvedValues["TYPE_KEY:d3"] = &mojom_type s.UserDefinedValueDeclaredConstant{mojom_types.DeclaredConstant{ 988 test.expectedGraph().ResolvedValues["TYPE_KEY:d3"] = &mojom_type s.UserDefinedValueDeclaredConstant{mojom_types.DeclaredConstant{
989 DeclData: *test.newDeclData("d3", "d3"), 989 DeclData: *test.newDeclData("d3", "d3"),
990 Type: &mojom_types.TypeSimpleType{mojom_types.Simple Type_Double}, 990 Type: &mojom_types.TypeSimpleType{mojom_types.Simple Type_Double},
991 Value: &mojom_types.ValueBuiltinValue{mojom_types.Bui ltinConstantValue_DoubleNan}, 991 Value: &mojom_types.ValueBuiltinValue{mojom_types.Bui ltinConstantValue_DoubleNan},
992 }} 992 }}
993 993
994 test.endTestCase() 994 test.endTestCase()
995 } 995 }
996 996
997 //////////////////////////////////////////////////////////// 997 ////////////////////////////////////////////////////////////
998 // Test Case: Constants defined in terms of other constants.
999 ////////////////////////////////////////////////////////////
1000 {
1001
1002 contents := `
1003 enum Color{
1004 RED, BLUE
1005 };
1006
1007 const int32 x1 = 42;
1008 const int32 x2 = x1;
1009 const int32 x3 = x2;
1010
1011 const Color c1 = RED;
1012 const Color c2 = c1;
1013 const Color c3 = c2;
1014 `
1015 test.addTestCase("", contents)
1016
1017 // DeclaredMojomObjects
1018 test.expectedFile().DeclaredMojomObjects.TopLevelEnums = &[]stri ng{"TYPE_KEY:Color"}
1019 test.expectedFile().DeclaredMojomObjects.TopLevelConstants = &[] string{"TYPE_KEY:x1", "TYPE_KEY:x2",
1020 "TYPE_KEY:x3", "TYPE_KEY:c1", "TYPE_KEY:c2", "TYPE_KEY:c 3"}
1021
1022 // Resolved Values
1023
1024 // Color.RED
1025 test.expectedGraph().ResolvedValues["TYPE_KEY:Color.RED"] = &moj om_types.UserDefinedValueEnumValue{mojom_types.EnumValue{
1026 DeclData: test.newDeclData("RED", "Color.RED"),
1027 EnumTypeKey: "TYPE_KEY:Color",
1028 IntValue: 0,
1029 }}
1030
1031 // Color.BLUE
1032 test.expectedGraph().ResolvedValues["TYPE_KEY:Color.BLUE"] = &mo jom_types.UserDefinedValueEnumValue{mojom_types.EnumValue{
1033 DeclData: test.newDeclData("BLUE", "Color.BLUE"),
1034 EnumTypeKey: "TYPE_KEY:Color",
1035 IntValue: 1,
1036 }}
1037
1038 // x1
1039 test.expectedGraph().ResolvedValues["TYPE_KEY:x1"] = &mojom_type s.UserDefinedValueDeclaredConstant{mojom_types.DeclaredConstant{
1040 DeclData: *test.newDeclData("x1", "x1"),
1041 Type: &mojom_types.TypeSimpleType{mojom_types.Simple Type_Int32},
1042 Value: &mojom_types.ValueLiteralValue{&mojom_types.Li teralValueInt8Value{42}},
1043 }}
1044
1045 // x2
1046 test.expectedGraph().ResolvedValues["TYPE_KEY:x2"] = &mojom_type s.UserDefinedValueDeclaredConstant{mojom_types.DeclaredConstant{
1047 DeclData: *test.newDeclData("x2", "x2"),
1048 Type: &mojom_types.TypeSimpleType{mojom_types.Simple Type_Int32},
1049 Value: &mojom_types.ValueUserValueReference{mojom_types. UserValueReference{
1050 Identifier: "x1",
1051 ValueKey: stringPointer("TYPE_KEY:x1")}},
1052 ResolvedConcreteValue: &mojom_types.ValueLiteralValue{&m ojom_types.LiteralValueInt8Value{42}},
1053 }}
1054
1055 // x3
1056 test.expectedGraph().ResolvedValues["TYPE_KEY:x3"] = &mojom_type s.UserDefinedValueDeclaredConstant{mojom_types.DeclaredConstant{
1057 DeclData: *test.newDeclData("x3", "x3"),
1058 Type: &mojom_types.TypeSimpleType{mojom_types.Simple Type_Int32},
1059 Value: &mojom_types.ValueUserValueReference{mojom_types. UserValueReference{
1060 Identifier: "x2",
1061 ValueKey: stringPointer("TYPE_KEY:x2")}},
1062 ResolvedConcreteValue: &mojom_types.ValueLiteralValue{&m ojom_types.LiteralValueInt8Value{42}},
1063 }}
1064
1065 // c1
1066 test.expectedGraph().ResolvedValues["TYPE_KEY:c1"] = &mojom_type s.UserDefinedValueDeclaredConstant{mojom_types.DeclaredConstant{
1067 DeclData: *test.newDeclData("c1", "c1"),
1068 Type: &mojom_types.TypeTypeReference{mojom_types.TypeRef erence{
1069 false, false, stringPointer("Color"), stringPoin ter("TYPE_KEY:Color")}},
1070 Value: &mojom_types.ValueUserValueReference{mojom_types. UserValueReference{
1071 Identifier: "RED",
1072 ValueKey: stringPointer("TYPE_KEY:Color.RED")} },
1073 }}
1074
1075 // c2
1076 test.expectedGraph().ResolvedValues["TYPE_KEY:c2"] = &mojom_type s.UserDefinedValueDeclaredConstant{mojom_types.DeclaredConstant{
1077 DeclData: *test.newDeclData("c2", "c2"),
1078 Type: &mojom_types.TypeTypeReference{mojom_types.TypeRef erence{
1079 false, false, stringPointer("Color"), stringPoin ter("TYPE_KEY:Color")}},
1080 Value: &mojom_types.ValueUserValueReference{mojom_types. UserValueReference{
1081 Identifier: "c1",
1082 ValueKey: stringPointer("TYPE_KEY:c1")}},
1083 ResolvedConcreteValue: &mojom_types.ValueUserValueRefere nce{mojom_types.UserValueReference{
1084 ValueKey: stringPointer("TYPE_KEY:Color.RED")}},
1085 }}
1086
1087 // c3
1088 test.expectedGraph().ResolvedValues["TYPE_KEY:c3"] = &mojom_type s.UserDefinedValueDeclaredConstant{mojom_types.DeclaredConstant{
1089 DeclData: *test.newDeclData("c3", "c3"),
1090 Type: &mojom_types.TypeTypeReference{mojom_types.TypeRef erence{
1091 false, false, stringPointer("Color"), stringPoin ter("TYPE_KEY:Color")}},
1092 Value: &mojom_types.ValueUserValueReference{mojom_types. UserValueReference{
1093 Identifier: "c2",
1094 ValueKey: stringPointer("TYPE_KEY:c2")}},
1095 ResolvedConcreteValue: &mojom_types.ValueUserValueRefere nce{mojom_types.UserValueReference{
1096 ValueKey: stringPointer("TYPE_KEY:Color.RED")}},
1097 }}
1098
1099 // ResolvedTypes
1100
1101 // enum Color
1102 test.expectedGraph().ResolvedTypes["TYPE_KEY:Color"] = &mojom_ty pes.UserDefinedTypeEnumType{mojom_types.MojomEnum{
1103 DeclData: test.newDeclData("Color", "Color"),
1104 Values: []mojom_types.EnumValue{
1105 // Note(rudominer) It is a bug that we need to c opy the enum values here.
1106 // See https://github.com/domokit/mojo/issues/51 3.
1107 // value RED
1108 test.expectedGraph().ResolvedValues["TYPE_KEY:Co lor.RED"].(*mojom_types.UserDefinedValueEnumValue).Value,
1109 // value BLUE
1110 test.expectedGraph().ResolvedValues["TYPE_KEY:Co lor.BLUE"].(*mojom_types.UserDefinedValueEnumValue).Value,
1111 },
1112 }}
1113
1114 test.endTestCase()
1115 }
1116
1117 ////////////////////////////////////////////////////////////
998 // Test Case 1118 // Test Case
999 //////////////////////////////////////////////////////////// 1119 ////////////////////////////////////////////////////////////
1000 { 1120 {
1001 1121
1002 contents := ` 1122 contents := `
1003 [go_namespace="go.test", 1123 [go_namespace="go.test",
1004 lucky=true, 1124 lucky=true,
1005 planet=EARTH] 1125 planet=EARTH]
1006 module mojom.test; 1126 module mojom.test;
1007 1127
(...skipping 2369 matching lines...) Expand 10 before | Expand all | Expand 10 after
3377 } 3497 }
3378 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na ctual=\n*****\n%q\n*****\n"+ 3498 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na ctual=\n*****\n%q\n*****\n"+
3379 "match failed at position %d: expected=\n*****\n %q\n******\nactual=\n*****\n%q\n******\n", 3499 "match failed at position %d: expected=\n*****\n %q\n******\nactual=\n*****\n%q\n******\n",
3380 expectedString, actualString, diffPos, mismatchE xpected, mismatchActual) 3500 expectedString, actualString, diffPos, mismatchE xpected, mismatchActual)
3381 } else { 3501 } else {
3382 return fmt.Errorf("expected != actual but the two printe d equal.") 3502 return fmt.Errorf("expected != actual but the two printe d equal.")
3383 } 3503 }
3384 } 3504 }
3385 return nil 3505 return nil
3386 } 3506 }
OLDNEW
« no previous file with comments | « mojom/mojom_tool/serialization/serialization.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698