@@ -440,13 +440,11 @@ void TextFormatConformanceTestSuiteImpl<MessageType>::RunAllTests() {
440
440
absl::StrCat (" FloatFieldLargerThanUint64" , name_suffix), REQUIRED,
441
441
absl::StrCat (" optional_float: 18446744073709551616" , suffix));
442
442
// https://protobuf.dev/reference/protobuf/textformat-spec/#literals says
443
- // "-0" is a valid float literal.
444
- // TODO: Figure out if this should count as not setting
445
- // presence or if -0 should be reflected back.
446
- // RunValidTextFormatTestWithExpected(
447
- // absl::StrCat("FloatFieldNegativeZero", name_suffix), REQUIRED,
448
- // absl::StrCat("optional_float: -0", suffix),
449
- // "" /* implicit presence, so zero means unset*/);
443
+ // "-0" is a valid float literal. -0 should be considered not the same as 0
444
+ // when considering implicit presence, and so should round trip.
445
+ RunValidTextFormatTest (absl::StrCat (" FloatFieldNegativeZero" , name_suffix),
446
+ REQUIRED,
447
+ absl::StrCat (" optional_float: -0" , suffix));
450
448
// https://protobuf.dev/reference/protobuf/textformat-spec/#literals says
451
449
// ".123", "-.123", ".123e2" are a valid float literal.
452
450
RunValidTextFormatTest (absl::StrCat (" FloatFieldNoLeadingZero" , name_suffix),
@@ -502,6 +500,19 @@ void TextFormatConformanceTestSuiteImpl<MessageType>::RunAllTests() {
502
500
RunValidTextFormatTestWithExpected (
503
501
" DoubleFieldOverflowInfinityHugeExponent" , REQUIRED,
504
502
" optional_double: 1e18446744073709551616" , " optional_double: inf" );
503
+ RunValidTextFormatTestWithExpected (
504
+ " DoubleFieldLargeNegativeExponentParsesAsZero" , REQUIRED,
505
+ " optional_double: 1e-18446744073709551616" , " " );
506
+ RunValidTextFormatTestWithExpected (
507
+ " NegDoubleFieldLargeNegativeExponentParsesAsNegZero" , REQUIRED,
508
+ " optional_double: -1e-18446744073709551616" , " optional_double: -0" );
509
+
510
+ RunValidTextFormatTestWithExpected (
511
+ " FloatFieldLargeNegativeExponentParsesAsZero" , REQUIRED,
512
+ " optional_float: 1e-50" , " " );
513
+ RunValidTextFormatTestWithExpected (
514
+ " NegFloatFieldLargeNegativeExponentParsesAsNegZero" , REQUIRED,
515
+ " optional_float: -1e-50" , " optional_float: -0" );
505
516
506
517
// String literals x {Strings, Bytes}
507
518
for (const auto & field_type : std::vector<std::string>{" String" , " Bytes" }) {
0 commit comments