Skip to content

Commit 13caa08

Browse files
Enable textproto conformance tests for "-0" and "-0F".
-0 should be treated as distinct from 0 when deciding it is default valued for implicit presence fields. PiperOrigin-RevId: 632162352
1 parent 1b06cef commit 13caa08

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

conformance/text_format_conformance_suite.cc

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,11 @@ void TextFormatConformanceTestSuiteImpl<MessageType>::RunAllTests() {
440440
absl::StrCat("FloatFieldLargerThanUint64", name_suffix), REQUIRED,
441441
absl::StrCat("optional_float: 18446744073709551616", suffix));
442442
// 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));
450448
// https://protobuf.dev/reference/protobuf/textformat-spec/#literals says
451449
// ".123", "-.123", ".123e2" are a valid float literal.
452450
RunValidTextFormatTest(absl::StrCat("FloatFieldNoLeadingZero", name_suffix),
@@ -502,6 +500,19 @@ void TextFormatConformanceTestSuiteImpl<MessageType>::RunAllTests() {
502500
RunValidTextFormatTestWithExpected(
503501
"DoubleFieldOverflowInfinityHugeExponent", REQUIRED,
504502
"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");
505516

506517
// String literals x {Strings, Bytes}
507518
for (const auto& field_type : std::vector<std::string>{"String", "Bytes"}) {

conformance/text_format_failure_list_python.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,23 @@ Required.Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.ProtobufOutput
7777
Required.Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.TextFormatOutput
7878
Required.Proto3.TextFormatInput.StringLiteralBasicEscapesString.ProtobufOutput
7979
Required.Proto3.TextFormatInput.StringLiteralBasicEscapesString.TextFormatOutput
80+
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero.ProtobufOutput
81+
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero.TextFormatOutput
82+
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput
83+
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput
84+
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_f.ProtobufOutput
85+
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_f.TextFormatOutput
86+
Required.Editions_Proto3.TextFormatInput.NegDoubleFieldLargeNegativeExponentParsesAsNegZero.ProtobufOutput
87+
Required.Editions_Proto3.TextFormatInput.NegDoubleFieldLargeNegativeExponentParsesAsNegZero.TextFormatOutput
88+
Required.Editions_Proto3.TextFormatInput.NegFloatFieldLargeNegativeExponentParsesAsNegZero.ProtobufOutput
89+
Required.Editions_Proto3.TextFormatInput.NegFloatFieldLargeNegativeExponentParsesAsNegZero.TextFormatOutput
90+
Required.Proto3.TextFormatInput.FloatFieldNegativeZero.ProtobufOutput
91+
Required.Proto3.TextFormatInput.FloatFieldNegativeZero.TextFormatOutput
92+
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput
93+
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput
94+
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_f.ProtobufOutput
95+
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_f.TextFormatOutput
96+
Required.Proto3.TextFormatInput.NegDoubleFieldLargeNegativeExponentParsesAsNegZero.ProtobufOutput
97+
Required.Proto3.TextFormatInput.NegDoubleFieldLargeNegativeExponentParsesAsNegZero.TextFormatOutput
98+
Required.Proto3.TextFormatInput.NegFloatFieldLargeNegativeExponentParsesAsNegZero.ProtobufOutput
99+
Required.Proto3.TextFormatInput.NegFloatFieldLargeNegativeExponentParsesAsNegZero.TextFormatOutput

conformance/text_format_failure_list_python_cpp.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Required.Editions_Proto3.TextFormatInput.FloatFieldWithVeryPreciseNumber_F.Proto
2828
Required.Editions_Proto3.TextFormatInput.FloatFieldWithVeryPreciseNumber_F.TextFormatOutput
2929
Required.Editions_Proto3.TextFormatInput.FloatFieldZero_F.ProtobufOutput
3030
Required.Editions_Proto3.TextFormatInput.FloatFieldZero_F.TextFormatOutput
31+
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput
32+
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput
3133
Required.Editions_Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.ProtobufOutput
3234
Required.Editions_Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.TextFormatOutput
3335
Required.Editions_Proto3.TextFormatInput.StringLiteralBasicEscapesString.ProtobufOutput
@@ -62,6 +64,8 @@ Required.Proto3.TextFormatInput.FloatFieldWithVeryPreciseNumber_F.ProtobufOutput
6264
Required.Proto3.TextFormatInput.FloatFieldWithVeryPreciseNumber_F.TextFormatOutput
6365
Required.Proto3.TextFormatInput.FloatFieldZero_F.ProtobufOutput
6466
Required.Proto3.TextFormatInput.FloatFieldZero_F.TextFormatOutput
67+
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput
68+
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput
6569
Required.Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.ProtobufOutput
6670
Required.Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.TextFormatOutput
6771
Required.Proto3.TextFormatInput.StringLiteralBasicEscapesString.ProtobufOutput

conformance/text_format_failure_list_python_upb.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Required.Editions_Proto3.TextFormatInput.FloatFieldNegative_F.ProtobufOutput
1515
Required.Editions_Proto3.TextFormatInput.FloatFieldNegative_F.TextFormatOutput
1616
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeNoLeadingZero_F.ProtobufOutput
1717
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeNoLeadingZero_F.TextFormatOutput
18+
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput
19+
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput
1820
Required.Editions_Proto3.TextFormatInput.FloatFieldNoLeadingZero_F.ProtobufOutput
1921
Required.Editions_Proto3.TextFormatInput.FloatFieldNoLeadingZero_F.TextFormatOutput
2022
Required.Editions_Proto3.TextFormatInput.FloatFieldNoLeadingZeroWithExponent_F.ProtobufOutput
@@ -49,6 +51,8 @@ Required.Proto3.TextFormatInput.FloatFieldNegative_F.ProtobufOutput
4951
Required.Proto3.TextFormatInput.FloatFieldNegative_F.TextFormatOutput
5052
Required.Proto3.TextFormatInput.FloatFieldNegativeNoLeadingZero_F.ProtobufOutput
5153
Required.Proto3.TextFormatInput.FloatFieldNegativeNoLeadingZero_F.TextFormatOutput
54+
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput
55+
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput
5256
Required.Proto3.TextFormatInput.FloatFieldNoLeadingZero_F.ProtobufOutput
5357
Required.Proto3.TextFormatInput.FloatFieldNoLeadingZero_F.TextFormatOutput
5458
Required.Proto3.TextFormatInput.FloatFieldNoLeadingZeroWithExponent_F.ProtobufOutput

0 commit comments

Comments
 (0)