Skip to content

Commit

Permalink
Accept 'F' suffix for floats in python text-format parser.
Browse files Browse the repository at this point in the history
As per the spec, these floats should be accepted.

PiperOrigin-RevId: 705227307
  • Loading branch information
mkruskal-google authored and copybara-github committed Dec 13, 2024
1 parent e4c78ee commit ce0cf76
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 91 deletions.
34 changes: 4 additions & 30 deletions conformance/text_format_failure_list_python.txt
Original file line number Diff line number Diff line change
@@ -1,42 +1,14 @@
# This is the list of text format conformance tests that are known to fail right
# now.
# TODO: These should be fixed.
Required.*.TextFormatInput.FloatFieldLargerThanInt64_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldLargerThanInt64_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldLargerThanUint64_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldLargerThanUint64_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldMaxValue_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldMaxValue_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldMinValue_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldMinValue_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegativeNoLeadingZero_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegativeNoLeadingZero_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegativeZero.ProtobufOutput # Output was not equivalent to reference message: deleted: optional_float: -0
Required.*.TextFormatInput.FloatFieldNegativeZero.TextFormatOutput # Output was not equivalent to reference message: deleted: optional_float: -0
Required.*.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput # Output was not equivalent to reference message: deleted: optional_float: -0
Required.*.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput # Output was not equivalent to reference message: deleted: optional_float: -0
Required.*.TextFormatInput.FloatFieldNegativeZero_f.ProtobufOutput # Output was not equivalent to reference message: deleted: optional_float: -0
Required.*.TextFormatInput.FloatFieldNegativeZero_f.TextFormatOutput # Output was not equivalent to reference message: deleted: optional_float: -0
Required.*.TextFormatInput.FloatFieldNegative_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegative_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNoLeadingZeroWithExponent_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNoLeadingZeroWithExponent_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNoLeadingZero_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNoLeadingZero_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNoNegativeOctal # Should have failed to parse, but didn't.
Required.*.TextFormatInput.FloatFieldNoOctal # Should have failed to parse, but didn't.
Required.*.TextFormatInput.FloatFieldTooLarge_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldTooLarge_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldTooSmall_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldTooSmall_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldWithInt32Max_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldWithInt32Max_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldWithVeryPreciseNumber_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldWithVeryPreciseNumber_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldZero_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldZero_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatField_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatField_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.NegDoubleFieldLargeNegativeExponentParsesAsNegZero.ProtobufOutput # Output was not equivalent to reference message: deleted: optional_double: -0
Required.*.TextFormatInput.NegDoubleFieldLargeNegativeExponentParsesAsNegZero.TextFormatOutput # Output was not equivalent to reference message: deleted: optional_double: -0
Required.*.TextFormatInput.NegFloatFieldLargeNegativeExponentParsesAsNegZero.ProtobufOutput # Output was not equivalent to reference message: deleted: optional_float: -0
Expand All @@ -51,4 +23,6 @@ Required.*.TextFormatInput.FloatFieldMaxValue.ProtobufOutput
Required.*.TextFormatInput.FloatFieldMaxValue.TextFormatOutput # Output was not equivalent to reference message
Required.*.TextFormatInput.FloatFieldMaxValue_f.ProtobufOutput # Output was not equivalent to reference message
Required.*.TextFormatInput.FloatFieldMaxValue_f.TextFormatOutput # Output was not equivalent to reference message
Required.*.TextFormatInput.FloatFieldMaxValue_F.ProtobufOutput # Output was not equivalent to reference message
Required.*.TextFormatInput.FloatFieldMaxValue_F.TextFormatOutput # Output was not equivalent to reference message

30 changes: 0 additions & 30 deletions conformance/text_format_failure_list_python_cpp.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,5 @@
Required.*.TextFormatInput.FloatFieldLargerThanInt64_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldLargerThanInt64_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldLargerThanUint64_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldLargerThanUint64_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldMaxValue_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldMaxValue_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldMinValue_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldMinValue_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegativeNoLeadingZero_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegativeNoLeadingZero_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegative_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegative_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNoLeadingZeroWithExponent_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNoLeadingZeroWithExponent_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNoLeadingZero_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNoLeadingZero_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNoNegativeOctal # Should have failed to parse, but didn't.
Required.*.TextFormatInput.FloatFieldNoOctal # Should have failed to parse, but didn't.
Required.*.TextFormatInput.FloatFieldTooLarge_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldTooLarge_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldTooSmall_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldTooSmall_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldWithInt32Max_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldWithInt32Max_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldWithVeryPreciseNumber_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldWithVeryPreciseNumber_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldZero_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldZero_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatField_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatField_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.StringLiteralBasicEscapesBytes.ProtobufOutput # Output was not equivalent to reference message: modified: optional_bytes: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\t
Required.*.TextFormatInput.StringLiteralBasicEscapesBytes.TextFormatOutput # Output was not equivalent to reference message: modified: optional_bytes: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\t
Required.*.TextFormatInput.StringLiteralBasicEscapesString.ProtobufOutput # Output was not equivalent to reference message: modified: optional_string: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\
Expand Down
30 changes: 0 additions & 30 deletions conformance/text_format_failure_list_python_upb.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,8 @@
# This is the list of text format conformance tests that are known to fail right
# now.
# TODO: These should be fixed.
Required.*.TextFormatInput.FloatFieldLargerThanInt64_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldLargerThanInt64_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldLargerThanUint64_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldLargerThanUint64_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldMaxValue_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldMaxValue_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldMinValue_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldMinValue_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegativeNoLeadingZero_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegativeNoLeadingZero_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegative_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNegative_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNoLeadingZeroWithExponent_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNoLeadingZeroWithExponent_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNoLeadingZero_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNoLeadingZero_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldNoNegativeOctal # Should have failed to parse, but didn't.
Required.*.TextFormatInput.FloatFieldNoOctal # Should have failed to parse, but didn't.
Required.*.TextFormatInput.FloatFieldTooLarge_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldTooLarge_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldTooSmall_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldTooSmall_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldWithInt32Max_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldWithInt32Max_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldWithVeryPreciseNumber_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldWithVeryPreciseNumber_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldZero_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatFieldZero_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatField_F.ProtobufOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.FloatField_F.TextFormatOutput # Failed to parse input or produce output.
Required.*.TextFormatInput.StringLiteralBasicEscapesBytes.ProtobufOutput # Output was not equivalent to reference message: modified: optional_bytes: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\t
Required.*.TextFormatInput.StringLiteralBasicEscapesBytes.TextFormatOutput # Output was not equivalent to reference message: modified: optional_bytes: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\t
Required.*.TextFormatInput.StringLiteralBasicEscapesString.ProtobufOutput # Output was not equivalent to reference message: modified: optional_string: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\
Expand Down
9 changes: 9 additions & 0 deletions python/google/protobuf/internal/text_format_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,15 @@ class TokenizerTest(_parameterized.TestCase):
(text_format.Tokenizer.ConsumeFloat, 1.23456),
],
),
dict(
testcase_name='_float_capital_suffix',
text='ID13: 1.23456F ',
expected=[
(text_format.Tokenizer.ConsumeIdentifier, 'ID13'),
_CreateConsumeLiteralToken(':'),
(text_format.Tokenizer.ConsumeFloat, 1.23456),
],
),
dict(
testcase_name='_float_exponent_suffix',
text='ID14: 1.2e+2f ',
Expand Down
Loading

0 comments on commit ce0cf76

Please sign in to comment.