@@ -1311,6 +1311,81 @@ TEST_F(FeatureResolverPoolTest, CompileDefaultsMinimumTooEarly) {
1311
1311
HasError (HasSubstr (" edition 1_TEST_ONLY is earlier than the oldest" )));
1312
1312
}
1313
1313
1314
+ TEST_F (FeatureResolverPoolTest, CompileDefaultsRemovedOnly) {
1315
+ const FileDescriptor* file = ParseSchema (R"schema(
1316
+ syntax = "proto2";
1317
+ package test;
1318
+ import "google/protobuf/descriptor.proto";
1319
+
1320
+ extend google.protobuf.FeatureSet {
1321
+ optional Foo bar = 9999;
1322
+ }
1323
+ enum Bar {
1324
+ TEST_ENUM_FEATURE_UNKNOWN = 0;
1325
+ VALUE1 = 1;
1326
+ VALUE2 = 2;
1327
+ }
1328
+ message Foo {
1329
+ optional Bar file_feature = 1 [
1330
+ targets = TARGET_TYPE_FIELD,
1331
+ feature_support.edition_introduced = EDITION_2023,
1332
+ feature_support.edition_removed = EDITION_99998_TEST_ONLY,
1333
+ edition_defaults = { edition: EDITION_LEGACY, value: "VALUE1" }
1334
+ ];
1335
+ }
1336
+ )schema" );
1337
+ ASSERT_NE (file, nullptr );
1338
+
1339
+ const FieldDescriptor* ext = file->extension (0 );
1340
+ auto compiled_defaults = FeatureResolver::CompileDefaults (
1341
+ feature_set_, {ext}, EDITION_99997_TEST_ONLY, EDITION_99999_TEST_ONLY);
1342
+ ASSERT_OK (compiled_defaults);
1343
+ const auto & defaults = *compiled_defaults->defaults ().rbegin ();
1344
+ EXPECT_THAT (defaults.edition (), EDITION_99998_TEST_ONLY);
1345
+ EXPECT_THAT (defaults.fixed_features ().GetExtension (pb::test).file_feature (),
1346
+ pb::VALUE1);
1347
+ EXPECT_FALSE (defaults.overridable_features ()
1348
+ .GetExtension (pb::test)
1349
+ .has_file_feature ());
1350
+ }
1351
+
1352
+ TEST_F (FeatureResolverPoolTest, CompileDefaultsIntroducedOnly) {
1353
+ const FileDescriptor* file = ParseSchema (R"schema(
1354
+ syntax = "proto2";
1355
+ package test;
1356
+ import "google/protobuf/descriptor.proto";
1357
+
1358
+ extend google.protobuf.FeatureSet {
1359
+ optional Foo bar = 9999;
1360
+ }
1361
+ enum Bar {
1362
+ TEST_ENUM_FEATURE_UNKNOWN = 0;
1363
+ VALUE1 = 1;
1364
+ VALUE2 = 2;
1365
+ }
1366
+ message Foo {
1367
+ optional Bar file_feature = 1 [
1368
+ targets = TARGET_TYPE_FIELD,
1369
+ feature_support.edition_introduced = EDITION_99998_TEST_ONLY,
1370
+ edition_defaults = { edition: EDITION_LEGACY, value: "VALUE1" }
1371
+ ];
1372
+ }
1373
+ )schema" );
1374
+ ASSERT_NE (file, nullptr );
1375
+
1376
+ const FieldDescriptor* ext = file->extension (0 );
1377
+ auto compiled_defaults = FeatureResolver::CompileDefaults (
1378
+ feature_set_, {ext}, EDITION_99997_TEST_ONLY, EDITION_99999_TEST_ONLY);
1379
+ ASSERT_OK (compiled_defaults);
1380
+ const auto & defaults = *compiled_defaults->defaults ().rbegin ();
1381
+ EXPECT_THAT (defaults.edition (), EDITION_99998_TEST_ONLY);
1382
+ EXPECT_THAT (
1383
+ defaults.overridable_features ().GetExtension (pb::test).file_feature (),
1384
+ pb::VALUE1);
1385
+ EXPECT_FALSE (
1386
+ defaults.fixed_features ().GetExtension (pb::test).has_file_feature ());
1387
+ }
1388
+
1314
1389
TEST_F (FeatureResolverPoolTest, CompileDefaultsMinimumCovered) {
1315
1390
const FileDescriptor* file = ParseSchema (R"schema(
1316
1391
syntax = "proto2";
0 commit comments