1# Protocol Buffers - Google's data interchange format 2# Copyright 2008 Google Inc. All rights reserved. 3# 4# Use of this source code is governed by a BSD-style 5# license that can be found in the LICENSE file or at 6# https://developers.google.com/open-source/licenses/bsd 7 8"""Tests for google.protobuf.text_encoding.""" 9 10import unittest 11 12from google.protobuf import text_encoding 13 14TEST_VALUES = [ 15 ("foo\\rbar\\nbaz\\t", 16 "foo\\rbar\\nbaz\\t", 17 b"foo\rbar\nbaz\t"), 18 ("\\'full of \\\"sound\\\" and \\\"fury\\\"\\'", 19 "\\'full of \\\"sound\\\" and \\\"fury\\\"\\'", 20 b"'full of \"sound\" and \"fury\"'"), 21 ("signi\\\\fying\\\\ nothing\\\\", 22 "signi\\\\fying\\\\ nothing\\\\", 23 b"signi\\fying\\ nothing\\"), 24 ("\\010\\t\\n\\013\\014\\r", 25 "\\010\\t\\n\\013\\014\\r", 26 b"\010\011\012\013\014\015")] 27 28 29class TextEncodingTestCase(unittest.TestCase): 30 def testCEscape(self): 31 for escaped, escaped_utf8, unescaped in TEST_VALUES: 32 self.assertEqual(escaped, text_encoding.CEscape(unescaped, as_utf8=False)) 33 self.assertEqual( 34 escaped_utf8, text_encoding.CEscape(unescaped, as_utf8=True) 35 ) 36 37 def testCUnescape(self): 38 for escaped, escaped_utf8, unescaped in TEST_VALUES: 39 self.assertEqual(unescaped, text_encoding.CUnescape(escaped)) 40 self.assertEqual(unescaped, text_encoding.CUnescape(escaped_utf8)) 41 42 43if __name__ == "__main__": 44 unittest.main() 45