dep-protobuf/python/google/protobuf/internal/text_encoding_test.py

51 lines
1.4 KiB
Python
Raw Permalink Normal View History

2012-09-22 02:40:50 +00:00
# Protocol Buffers - Google's data interchange format
# Copyright 2008 Google Inc. All rights reserved.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
2012-09-22 02:40:50 +00:00
"""Tests for google.protobuf.text_encoding."""
2012-09-22 02:40:50 +00:00
import unittest
2016-03-30 11:39:59 -07:00
from google.protobuf import text_encoding
2012-09-22 02:40:50 +00:00
TEST_VALUES = [
("foo\\rbar\\nbaz\\t", "foo\\rbar\\nbaz\\t", b"foo\rbar\nbaz\t"),
(
'\\\'full of \\"sound\\" and \\"fury\\"\\\'',
'\\\'full of \\"sound\\" and \\"fury\\"\\\'',
b'\'full of "sound" and "fury"\'',
),
(
"signi\\\\fying\\\\ nothing\\\\",
"signi\\\\fying\\\\ nothing\\\\",
b"signi\\fying\\ nothing\\",
),
(
"\\010\\t\\n\\013\\014\\r",
"\\010\\t\\n\\013\\014\\r",
b"\010\011\012\013\014\015",
),
]
2012-09-22 02:40:50 +00:00
class TextEncodingTestCase(unittest.TestCase):
def testCEscape(self):
for escaped, escaped_utf8, unescaped in TEST_VALUES:
self.assertEqual(escaped, text_encoding.CEscape(unescaped, as_utf8=False))
self.assertEqual(
escaped_utf8, text_encoding.CEscape(unescaped, as_utf8=True)
)
2012-09-22 02:40:50 +00:00
def testCUnescape(self):
for escaped, escaped_utf8, unescaped in TEST_VALUES:
2015-01-13 15:47:55 -05:00
self.assertEqual(unescaped, text_encoding.CUnescape(escaped))
self.assertEqual(unescaped, text_encoding.CUnescape(escaped_utf8))
if __name__ == "__main__":
unittest.main()