@@ -93,7 +93,20 @@ constexpr absl::string_view kEscapeTestStringEscaped =
9393
9494constexpr absl::string_view value_replacement = " \\ [REDACTED\\ ]" ;
9595
96- class TextFormatTest : public testing ::Test {
96+ class TextFormatTestBase : public testing ::Test {
97+ public:
98+ void SetUp () override {
99+ single_line_debug_format_prefix_ = " " ;
100+ multi_line_debug_format_prefix_ = proto_.DebugString ();
101+ }
102+
103+ protected:
104+ unittest::TestAllTypes proto_;
105+ std::string single_line_debug_format_prefix_;
106+ std::string multi_line_debug_format_prefix_;
107+ };
108+
109+ class TextFormatTest : public TextFormatTestBase {
97110 public:
98111 static void SetUpTestSuite () {
99112 ABSL_CHECK_OK (File::GetContents (
@@ -108,8 +121,6 @@ class TextFormatTest : public testing::Test {
108121 protected:
109122 // Text format read from text_format_unittest_data.txt.
110123 const std::string proto_text_format_;
111- unittest::TestAllTypes proto_;
112-
113124 private:
114125 static std::string static_proto_text_format_;
115126};
@@ -157,8 +168,8 @@ TEST_F(TextFormatTest, ShortDebugString) {
157168 proto_.mutable_optional_foreign_message ();
158169
159170 EXPECT_EQ (proto_.ShortDebugString (),
160- absl::StrCat (" optional_int32: " , kDebugStringSilentMarker ,
161- " 1 "
171+ absl::StrCat (single_line_debug_format_prefix_ ,
172+ " optional_int32: 1 "
162173 " optional_string: \" hello\" "
163174 " optional_nested_message { bb: 2 } "
164175 " optional_foreign_message { }" ));
@@ -337,17 +348,18 @@ TEST_F(TextFormatTest, StringEscape) {
337348
338349 // Hardcode a correct value to test against.
339350 std::string correct_string =
340- absl::StrCat (" optional_string: " , kDebugStringSilentMarker ,
341- kEscapeTestStringEscaped , " \n " );
351+ absl::StrCat (multi_line_debug_format_prefix_ ,
352+ " optional_string: " , kEscapeTestStringEscaped , " \n " );
342353
343354 // Compare.
344355 EXPECT_EQ (correct_string, debug_string);
345356 // UTF-8 string is the same as non-UTF-8 because
346357 // the protocol buffer contains no UTF-8 text.
347358 EXPECT_EQ (correct_string, utf8_debug_string);
348359
349- std::string expected_short_debug_string = absl::StrCat (
350- " optional_string: " , kDebugStringSilentMarker , kEscapeTestStringEscaped );
360+ std::string expected_short_debug_string =
361+ absl::StrCat (single_line_debug_format_prefix_,
362+ " optional_string: " , kEscapeTestStringEscaped );
351363 EXPECT_EQ (expected_short_debug_string, proto_.ShortDebugString ());
352364}
353365
@@ -362,12 +374,12 @@ TEST_F(TextFormatTest, Utf8DebugString) {
362374
363375 // Hardcode a correct value to test against.
364376 std::string correct_utf8_string =
365- absl::StrCat (" optional_string: " , kDebugStringSilentMarker ,
366- " \"\350\260\267\346\255\214\"\n "
377+ absl::StrCat (multi_line_debug_format_prefix_ ,
378+ " optional_string: \"\350\260\267\346\255\214\"\n "
367379 " optional_bytes: \"\\ 350\\ 260\\ 267\\ 346\\ 255\\ 214\"\n " );
368380 std::string correct_string =
369- absl::StrCat (" optional_string: " , kDebugStringSilentMarker ,
370- " \"\\ 350\\ 260\\ 267\\ 346\\ 255\\ 214\"\n "
381+ absl::StrCat (multi_line_debug_format_prefix_ ,
382+ " optional_string: \"\\ 350\\ 260\\ 267\\ 346\\ 255\\ 214\"\n "
371383 " optional_bytes: \"\\ 350\\ 260\\ 267\\ 346\\ 255\\ 214\"\n " );
372384
373385 // Compare.
@@ -404,8 +416,9 @@ TEST_F(TextFormatTest, PrintUnknownFields) {
404416 unknown_fields->AddVarint (8 , 2 );
405417 unknown_fields->AddVarint (8 , 3 );
406418
407- EXPECT_EQ (absl::StrCat (" 5: " , kDebugStringSilentMarker ,
408- " 1\n "
419+ std::string message_text;
420+ TextFormat::PrintToString (message, &message_text);
421+ EXPECT_EQ (absl::StrCat (" 5: 1\n "
409422 " 5: 0x00000002\n "
410423 " 5: 0x0000000000000003\n "
411424 " 5: \" 4\"\n "
@@ -415,7 +428,7 @@ TEST_F(TextFormatTest, PrintUnknownFields) {
415428 " 8: 1\n "
416429 " 8: 2\n "
417430 " 8: 3\n " ),
418- message. DebugString () );
431+ message_text );
419432
420433 EXPECT_THAT (absl::StrCat (message), testing::MatchesRegex (absl::Substitute (
421434 " 5: UNKNOWN_VARINT $0\n "
@@ -1012,8 +1025,8 @@ TEST_F(TextFormatTest, PrintUnknownEnumFieldProto3) {
10121025 proto.add_repeated_nested_enum (
10131026 static_cast <proto3_unittest::TestAllTypes::NestedEnum>(-2147483648 ));
10141027
1015- EXPECT_EQ (absl::StrCat (" repeated_nested_enum: " , kDebugStringSilentMarker ,
1016- " 10\n "
1028+ EXPECT_EQ (absl::StrCat (multi_line_debug_format_prefix_ ,
1029+ " repeated_nested_enum: 10\n "
10171030 " repeated_nested_enum: -10\n "
10181031 " repeated_nested_enum: 2147483647\n "
10191032 " repeated_nested_enum: -2147483648\n " ),
@@ -1464,8 +1477,8 @@ TEST_F(TextFormatTest, PrintExotic) {
14641477 // have this problem, so we switched to that instead.
14651478
14661479 EXPECT_EQ (
1467- absl::StrCat (" repeated_int64: " , kDebugStringSilentMarker ,
1468- " -9223372036854775808\n "
1480+ absl::StrCat (multi_line_debug_format_prefix_ ,
1481+ " repeated_int64: -9223372036854775808\n "
14691482 " repeated_uint64: 18446744073709551615\n "
14701483 " repeated_double: 123.456\n "
14711484 " repeated_double: 1.23e+21\n "
@@ -1524,8 +1537,8 @@ TEST_F(TextFormatTest, PrintFloatPrecision) {
15241537 message.add_repeated_double (1.2345678987654e100 );
15251538 message.add_repeated_double (1.23456789876543e100 );
15261539
1527- EXPECT_EQ (absl::StrCat (" repeated_float: " , kDebugStringSilentMarker ,
1528- " 1\n "
1540+ EXPECT_EQ (absl::StrCat (multi_line_debug_format_prefix_ ,
1541+ " repeated_float: 1\n "
15291542 " repeated_float: 1.2\n "
15301543 " repeated_float: 1.23\n "
15311544 " repeated_float: 1.234\n "
0 commit comments