OLD | NEW |
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 "fmt" | 8 "fmt" |
9 "mojo/public/go/bindings" | 9 "mojo/public/go/bindings" |
10 "mojom/mojom_parser/generated/mojom_files" | 10 "mojom/mojom_parser/generated/mojom_files" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 FileName: test.fileName(), | 81 FileName: test.fileName(), |
82 }} | 82 }} |
83 } | 83 } |
84 | 84 |
85 // TestSingleFileSerialization uses a series of test cases in which the text of
a .mojom | 85 // TestSingleFileSerialization uses a series of test cases in which the text of
a .mojom |
86 // file is specified and the expected MojomFileGraph is specified using Go struc
t literals. | 86 // file is specified and the expected MojomFileGraph is specified using Go struc
t literals. |
87 func TestSingleFileSerialization(t *testing.T) { | 87 func TestSingleFileSerialization(t *testing.T) { |
88 test := singleFileTest{} | 88 test := singleFileTest{} |
89 | 89 |
90 //////////////////////////////////////////////////////////// | 90 //////////////////////////////////////////////////////////// |
| 91 // Test Case: array of int32 |
| 92 //////////////////////////////////////////////////////////// |
| 93 { |
| 94 |
| 95 contents := ` |
| 96 struct Foo{ |
| 97 array<int32> bar1; |
| 98 array<int32, 7> bar2; |
| 99 array<int32>? bar3; |
| 100 array<int32, 8>? bar4; |
| 101 };` |
| 102 |
| 103 test.addTestCase("", contents) |
| 104 |
| 105 // DeclaredMojomObjects |
| 106 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY
PE_KEY:Foo"} |
| 107 |
| 108 // ResolvedTypes |
| 109 |
| 110 // struct Foo |
| 111 test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_type
s.UserDefinedTypeStructType{mojom_types.MojomStruct{ |
| 112 DeclData: test.newDeclData("Foo", "Foo"), |
| 113 Fields: []mojom_types.StructField{ |
| 114 // field bar1 is not nullable and not fixed leng
th |
| 115 { |
| 116 DeclData: test.newDeclData("bar1", ""), |
| 117 Type: &mojom_types.TypeArrayType{mojom_t
ypes.ArrayType{ |
| 118 false, -1, &mojom_types.TypeSimp
leType{mojom_types.SimpleType_InT32}}}, |
| 119 }, |
| 120 // field bar2 is not nullable and fixed length o
f 7 |
| 121 { |
| 122 DeclData: test.newDeclData("bar2", ""), |
| 123 Type: &mojom_types.TypeArrayType{mojom_t
ypes.ArrayType{ |
| 124 false, 7, &mojom_types.TypeSimpl
eType{mojom_types.SimpleType_InT32}}}, |
| 125 }, |
| 126 // field bar3 is nullable and not fixed length |
| 127 { |
| 128 DeclData: test.newDeclData("bar3", ""), |
| 129 Type: &mojom_types.TypeArrayType{mojom_t
ypes.ArrayType{ |
| 130 true, -1, &mojom_types.TypeSimpl
eType{mojom_types.SimpleType_InT32}}}, |
| 131 }, |
| 132 // field bar4 is nullable and fixed length of 8 |
| 133 { |
| 134 DeclData: test.newDeclData("bar4", ""), |
| 135 Type: &mojom_types.TypeArrayType{mojom_t
ypes.ArrayType{ |
| 136 true, 8, &mojom_types.TypeSimple
Type{mojom_types.SimpleType_InT32}}}, |
| 137 }, |
| 138 }, |
| 139 }} |
| 140 |
| 141 test.endTestCase() |
| 142 } |
| 143 |
| 144 //////////////////////////////////////////////////////////// |
| 145 // Test Case: map string to int32 |
| 146 //////////////////////////////////////////////////////////// |
| 147 { |
| 148 |
| 149 contents := ` |
| 150 struct Foo{ |
| 151 map<string, int32> bar1; |
| 152 map<string?, int32> bar2; |
| 153 map<string, int32>? bar3; |
| 154 map<string?, int32>? bar4; |
| 155 };` |
| 156 |
| 157 test.addTestCase("", contents) |
| 158 |
| 159 // DeclaredMojomObjects |
| 160 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY
PE_KEY:Foo"} |
| 161 |
| 162 // ResolvedTypes |
| 163 |
| 164 // struct Foo |
| 165 test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_type
s.UserDefinedTypeStructType{mojom_types.MojomStruct{ |
| 166 DeclData: test.newDeclData("Foo", "Foo"), |
| 167 Fields: []mojom_types.StructField{ |
| 168 // field bar1 is non-nullable with a non-nullabl
e key. |
| 169 { |
| 170 DeclData: test.newDeclData("bar1", ""), |
| 171 Type: &mojom_types.TypeMapType{mojom_typ
es.MapType{ |
| 172 false, |
| 173 &mojom_types.TypeStringType{mojo
m_types.StringType{false}}, |
| 174 &mojom_types.TypeSimpleType{mojo
m_types.SimpleType_InT32}}}, |
| 175 }, |
| 176 // field bar2 is non-nullable with a nullable ke
y. |
| 177 { |
| 178 DeclData: test.newDeclData("bar2", ""), |
| 179 Type: &mojom_types.TypeMapType{mojom_typ
es.MapType{ |
| 180 false, |
| 181 &mojom_types.TypeStringType{mojo
m_types.StringType{true}}, |
| 182 &mojom_types.TypeSimpleType{mojo
m_types.SimpleType_InT32}}}, |
| 183 }, |
| 184 // field bar3 is nullable with a non-nullable ke
y. |
| 185 { |
| 186 DeclData: test.newDeclData("bar3", ""), |
| 187 Type: &mojom_types.TypeMapType{mojom_typ
es.MapType{ |
| 188 true, |
| 189 &mojom_types.TypeStringType{mojo
m_types.StringType{false}}, |
| 190 &mojom_types.TypeSimpleType{mojo
m_types.SimpleType_InT32}}}, |
| 191 }, |
| 192 // field bar4 is nullable with a nullable key. |
| 193 { |
| 194 DeclData: test.newDeclData("bar4", ""), |
| 195 Type: &mojom_types.TypeMapType{mojom_typ
es.MapType{ |
| 196 true, |
| 197 &mojom_types.TypeStringType{mojo
m_types.StringType{true}}, |
| 198 &mojom_types.TypeSimpleType{mojo
m_types.SimpleType_InT32}}}, |
| 199 }, |
| 200 }, |
| 201 }} |
| 202 |
| 203 test.endTestCase() |
| 204 } |
| 205 |
| 206 //////////////////////////////////////////////////////////// |
91 // Test Case | 207 // Test Case |
92 //////////////////////////////////////////////////////////// | 208 //////////////////////////////////////////////////////////// |
93 { | 209 { |
94 | 210 |
95 contents := ` | 211 contents := ` |
96 [go_namespace="go.test", | 212 [go_namespace="go.test", |
97 lucky=true, | 213 lucky=true, |
98 planet=EARTH] | 214 planet=EARTH] |
99 module mojom.test; | 215 module mojom.test; |
100 | 216 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 408 } |
293 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na
ctual=\n*****\n%q\n*****\n"+ | 409 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na
ctual=\n*****\n%q\n*****\n"+ |
294 "match failed at position %d: expected=\n*****\n
%s\n******\nactual=\n*****\n%s\n******\n", | 410 "match failed at position %d: expected=\n*****\n
%s\n******\nactual=\n*****\n%s\n******\n", |
295 expectedString, actualString, diffPos, mismatchE
xpected, mismatchActual) | 411 expectedString, actualString, diffPos, mismatchE
xpected, mismatchActual) |
296 } else { | 412 } else { |
297 return fmt.Errorf("expected != actual but the two printe
d equal.") | 413 return fmt.Errorf("expected != actual but the two printe
d equal.") |
298 } | 414 } |
299 } | 415 } |
300 return nil | 416 return nil |
301 } | 417 } |
OLD | NEW |