@@ -49,10 +49,8 @@ using ::testing::Not;
4949using ::testing::Property;
5050using ::testing::SizeIs;
5151
52- using AstType = ast_internal::Type;
53-
5452MATCHER_P (IsOptionalType, inner_type, " " ) {
55- const ast_internal::Type & type = arg;
53+ const TypeSpec & type = arg;
5654 if (!type.has_abstract_type ()) {
5755 return false ;
5856 }
@@ -100,13 +98,13 @@ TEST(OptionalTest, OptSelectDoesNotAnnotateFieldType) {
10098 EXPECT_NE (field_id, 0 );
10199
102100 EXPECT_THAT (ast_impl.type_map (), Not (Contains (Key (field_id))));
103- EXPECT_THAT (ast_impl.GetType (ast_impl.root_expr ().id ()),
104- IsOptionalType (AstType (ast_internal::PrimitiveType::kInt64 )));
101+ EXPECT_THAT (ast_impl.GetTypeOrDyn (ast_impl.root_expr ().id ()),
102+ IsOptionalType (TypeSpec (ast_internal::PrimitiveType::kInt64 )));
105103}
106104
107105struct TestCase {
108106 std::string expr;
109- testing::Matcher<ast_internal::Type > result_type_matcher;
107+ testing::Matcher<TypeSpec > result_type_matcher;
110108 std::string error_substring;
111109};
112110
@@ -144,7 +142,7 @@ TEST_P(OptionalTest, Runner) {
144142
145143 int64_t root_id = ast_impl.root_expr ().id ();
146144
147- EXPECT_THAT (ast_impl.GetType (root_id), test_case.result_type_matcher )
145+ EXPECT_THAT (ast_impl.GetTypeOrDyn (root_id), test_case.result_type_matcher )
148146 << " for expression: " << test_case.expr ;
149147}
150148
@@ -153,130 +151,132 @@ INSTANTIATE_TEST_SUITE_P(
153151 ::testing::Values (
154152 TestCase{
155153 " optional.of('abc')" ,
156- IsOptionalType (AstType (ast_internal::PrimitiveType::kString )),
154+ IsOptionalType (TypeSpec (ast_internal::PrimitiveType::kString )),
157155 },
158156 TestCase{
159157 " optional.ofNonZeroValue('')" ,
160- IsOptionalType (AstType (ast_internal::PrimitiveType::kString )),
158+ IsOptionalType (TypeSpec (ast_internal::PrimitiveType::kString )),
161159 },
162160 TestCase{
163161 " optional.none()" ,
164- IsOptionalType (AstType (ast_internal::DynamicType ())),
162+ IsOptionalType (TypeSpec (ast_internal::DynamicType ())),
165163 },
166164 TestCase{
167165 " optional.of('abc').hasValue()" ,
168- Eq (AstType (ast_internal::PrimitiveType::kBool )),
166+ Eq (TypeSpec (ast_internal::PrimitiveType::kBool )),
169167 },
170168 TestCase{
171169 " optional.of('abc').value()" ,
172- Eq (AstType (ast_internal::PrimitiveType::kString )),
170+ Eq (TypeSpec (ast_internal::PrimitiveType::kString )),
173171 },
174172 TestCase{
175173 " type(optional.of('abc')) == optional_type" ,
176- Eq (AstType (ast_internal::PrimitiveType::kBool )),
174+ Eq (TypeSpec (ast_internal::PrimitiveType::kBool )),
177175 },
178176 TestCase{
179177 " type(optional.of('abc')) == optional_type" ,
180- Eq (AstType (ast_internal::PrimitiveType::kBool )),
178+ Eq (TypeSpec (ast_internal::PrimitiveType::kBool )),
181179 },
182180 TestCase{
183181 " optional.of('abc').or(optional.of('def'))" ,
184- IsOptionalType (AstType (ast_internal::PrimitiveType::kString )),
182+ IsOptionalType (TypeSpec (ast_internal::PrimitiveType::kString )),
185183 },
186184 TestCase{" optional.of('abc').or(optional.of(1))" , _,
187185 " no matching overload for 'or'" },
188186 TestCase{
189187 " optional.of('abc').orValue('def')" ,
190- Eq (AstType (ast_internal::PrimitiveType::kString )),
188+ Eq (TypeSpec (ast_internal::PrimitiveType::kString )),
191189 },
192190 TestCase{" optional.of('abc').orValue(1)" , _,
193191 " no matching overload for 'orValue'" },
194192 TestCase{
195193 " {'k': 'v'}.?k" ,
196- IsOptionalType (AstType (ast_internal::PrimitiveType::kString )),
194+ IsOptionalType (TypeSpec (ast_internal::PrimitiveType::kString )),
197195 },
198196 TestCase{" 1.?k" , _,
199197 " expression of type 'int' cannot be the operand of a select "
200198 " operation" },
201199 TestCase{
202200 " {'k': {'k': 'v'}}.?k.?k2" ,
203- IsOptionalType (AstType (ast_internal::PrimitiveType::kString )),
201+ IsOptionalType (TypeSpec (ast_internal::PrimitiveType::kString )),
204202 },
205203 TestCase{
206204 " {'k': {'k': 'v'}}.?k.k2" ,
207- IsOptionalType (AstType (ast_internal::PrimitiveType::kString )),
205+ IsOptionalType (TypeSpec (ast_internal::PrimitiveType::kString )),
208206 },
209207 TestCase{" {?'k': optional.of('v')}" ,
210- Eq (AstType (ast_internal::MapType (
211- std::unique_ptr<AstType >(
212- new AstType (ast_internal::PrimitiveType::kString )),
213- std::unique_ptr<AstType> (
214- new AstType ( ast_internal::PrimitiveType::kString )))))},
208+ Eq (TypeSpec (ast_internal::MapType (
209+ std::unique_ptr<TypeSpec >(
210+ new TypeSpec (ast_internal::PrimitiveType::kString )),
211+ std::unique_ptr<TypeSpec>( new TypeSpec (
212+ ast_internal::PrimitiveType::kString )))))},
215213 TestCase{" {'k': 'v', ?'k2': optional.none()}" ,
216- Eq (AstType (ast_internal::MapType (
217- std::unique_ptr<AstType >(
218- new AstType (ast_internal::PrimitiveType::kString )),
219- std::unique_ptr<AstType> (
220- new AstType ( ast_internal::PrimitiveType::kString )))))},
214+ Eq (TypeSpec (ast_internal::MapType (
215+ std::unique_ptr<TypeSpec >(
216+ new TypeSpec (ast_internal::PrimitiveType::kString )),
217+ std::unique_ptr<TypeSpec>( new TypeSpec (
218+ ast_internal::PrimitiveType::kString )))))},
221219 TestCase{" {'k': 'v', ?'k2': 'v'}" , _,
222220 " expected type 'optional_type(string)' but found 'string'" },
223221 TestCase{" [?optional.of('v')]" ,
224- Eq (AstType (ast_internal::ListType (std::unique_ptr<AstType >(
225- new AstType (ast_internal::PrimitiveType::kString )))))},
222+ Eq (TypeSpec (ast_internal::ListType (std::unique_ptr<TypeSpec >(
223+ new TypeSpec (ast_internal::PrimitiveType::kString )))))},
226224 TestCase{" ['v', ?optional.none()]" ,
227- Eq (AstType (ast_internal::ListType (std::unique_ptr<AstType >(
228- new AstType (ast_internal::PrimitiveType::kString )))))},
225+ Eq (TypeSpec (ast_internal::ListType (std::unique_ptr<TypeSpec >(
226+ new TypeSpec (ast_internal::PrimitiveType::kString )))))},
229227 TestCase{" ['v1', ?'v2']" , _,
230228 " expected type 'optional_type(string)' but found 'string'" },
231229 TestCase{" [optional.of(dyn('1')), optional.of('2')][0]" ,
232- IsOptionalType (AstType (ast_internal::DynamicType ()))},
230+ IsOptionalType (TypeSpec (ast_internal::DynamicType ()))},
233231 TestCase{" [optional.of('1'), optional.of(dyn('2'))][0]" ,
234- IsOptionalType (AstType (ast_internal::DynamicType ()))},
232+ IsOptionalType (TypeSpec (ast_internal::DynamicType ()))},
235233 TestCase{" [{1: optional.of(1)}, {1: optional.of(dyn(1))}][0][1]" ,
236- IsOptionalType (AstType (ast_internal::DynamicType ()))},
234+ IsOptionalType (TypeSpec (ast_internal::DynamicType ()))},
237235 TestCase{" [{1: optional.of(dyn(1))}, {1: optional.of(1)}][0][1]" ,
238- IsOptionalType (AstType (ast_internal::DynamicType ()))},
236+ IsOptionalType (TypeSpec (ast_internal::DynamicType ()))},
239237 TestCase{" [optional.of('1'), optional.of(2)][0]" ,
240- Eq (AstType (ast_internal::DynamicType ()))},
238+ Eq (TypeSpec (ast_internal::DynamicType ()))},
241239 TestCase{" ['v1', ?'v2']" , _,
242240 " expected type 'optional_type(string)' but found 'string'" },
243241 TestCase{" cel.expr.conformance.proto3.TestAllTypes{?single_int64: "
244242 " optional.of(1)}" ,
245- Eq (AstType (ast_internal::MessageType (
243+ Eq (TypeSpec (ast_internal::MessageType (
246244 " cel.expr.conformance.proto3.TestAllTypes" )))},
247245 TestCase{" [0][?1]" ,
248- IsOptionalType (AstType (ast_internal::PrimitiveType::kInt64 ))},
246+ IsOptionalType (TypeSpec (ast_internal::PrimitiveType::kInt64 ))},
249247 TestCase{" [[0]][?1][?1]" ,
250- IsOptionalType (AstType (ast_internal::PrimitiveType::kInt64 ))},
248+ IsOptionalType (TypeSpec (ast_internal::PrimitiveType::kInt64 ))},
251249 TestCase{" [[0]][?1][1]" ,
252- IsOptionalType (AstType (ast_internal::PrimitiveType::kInt64 ))},
250+ IsOptionalType (TypeSpec (ast_internal::PrimitiveType::kInt64 ))},
253251 TestCase{" {0: 1}[?1]" ,
254- IsOptionalType (AstType (ast_internal::PrimitiveType::kInt64 ))},
252+ IsOptionalType (TypeSpec (ast_internal::PrimitiveType::kInt64 ))},
255253 TestCase{" {0: {0: 1}}[?1][?1]" ,
256- IsOptionalType (AstType (ast_internal::PrimitiveType::kInt64 ))},
254+ IsOptionalType (TypeSpec (ast_internal::PrimitiveType::kInt64 ))},
257255 TestCase{" {0: {0: 1}}[?1][1]" ,
258- IsOptionalType (AstType (ast_internal::PrimitiveType::kInt64 ))},
256+ IsOptionalType (TypeSpec (ast_internal::PrimitiveType::kInt64 ))},
259257 TestCase{" {0: {0: 1}}[?1]['']" , _, " no matching overload for '_[_]'" },
260258 TestCase{" {0: {0: 1}}[?1][?'']" , _, " no matching overload for '_[?_]'" },
261- TestCase{" optional.of('abc').optMap(x, x + 'def')" ,
262- IsOptionalType (AstType (ast_internal::PrimitiveType::kString ))},
263- TestCase{" optional.of('abc').optFlatMap(x, optional.of(x + 'def'))" ,
264- IsOptionalType (AstType (ast_internal::PrimitiveType::kString ))},
259+ TestCase{
260+ " optional.of('abc').optMap(x, x + 'def')" ,
261+ IsOptionalType (TypeSpec (ast_internal::PrimitiveType::kString ))},
262+ TestCase{
263+ " optional.of('abc').optFlatMap(x, optional.of(x + 'def'))" ,
264+ IsOptionalType (TypeSpec (ast_internal::PrimitiveType::kString ))},
265265 // Legacy nullability behaviors.
266266 TestCase{" cel.expr.conformance.proto3.TestAllTypes{?null_value: "
267267 " optional.of(0)}" ,
268- Eq (AstType (ast_internal::MessageType (
268+ Eq (TypeSpec (ast_internal::MessageType (
269269 " cel.expr.conformance.proto3.TestAllTypes" )))},
270270 TestCase{" cel.expr.conformance.proto3.TestAllTypes{?null_value: null}" ,
271- Eq (AstType (ast_internal::MessageType (
271+ Eq (TypeSpec (ast_internal::MessageType (
272272 " cel.expr.conformance.proto3.TestAllTypes" )))},
273273 TestCase{" cel.expr.conformance.proto3.TestAllTypes{?null_value: "
274274 " optional.of(null)}" ,
275- Eq (AstType (ast_internal::MessageType (
275+ Eq (TypeSpec (ast_internal::MessageType (
276276 " cel.expr.conformance.proto3.TestAllTypes" )))},
277277 TestCase{" cel.expr.conformance.proto3.TestAllTypes{}.?single_int64 "
278278 " == null" ,
279- Eq (AstType (ast_internal::PrimitiveType::kBool ))}));
279+ Eq (TypeSpec (ast_internal::PrimitiveType::kBool ))}));
280280
281281class OptionalStrictNullAssignmentTest
282282 : public testing::TestWithParam<TestCase> {};
@@ -315,7 +315,7 @@ TEST_P(OptionalStrictNullAssignmentTest, Runner) {
315315
316316 int64_t root_id = ast_impl.root_expr ().id ();
317317
318- EXPECT_THAT (ast_impl.GetType (root_id), test_case.result_type_matcher )
318+ EXPECT_THAT (ast_impl.GetTypeOrDyn (root_id), test_case.result_type_matcher )
319319 << " for expression: " << test_case.expr ;
320320}
321321
0 commit comments