Index: third_party/protobuf/python/google/protobuf/internal/text_encoding_test.py |
diff --git a/third_party/protobuf/python/google/protobuf/internal/descriptor_database_test.py b/third_party/protobuf/python/google/protobuf/internal/text_encoding_test.py |
old mode 100644 |
new mode 100755 |
similarity index 55% |
copy from third_party/protobuf/python/google/protobuf/internal/descriptor_database_test.py |
copy to third_party/protobuf/python/google/protobuf/internal/text_encoding_test.py |
index d0ca7892244f7bee5913a0231835c56ec124cd54..338a287b1b0bdac469cc4afb907a2c32d0a0d8a9 |
--- a/third_party/protobuf/python/google/protobuf/internal/descriptor_database_test.py |
+++ b/third_party/protobuf/python/google/protobuf/internal/text_encoding_test.py |
@@ -1,8 +1,8 @@ |
-#! /usr/bin/python |
+#! /usr/bin/env python |
# |
# Protocol Buffers - Google's data interchange format |
# Copyright 2008 Google Inc. All rights reserved. |
-# http://code.google.com/p/protobuf/ |
+# https://developers.google.com/protocol-buffers/ |
# |
# Redistribution and use in source and binary forms, with or without |
# modification, are permitted provided that the following conditions are |
@@ -30,34 +30,42 @@ |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-"""Tests for google.protobuf.descriptor_database.""" |
+"""Tests for google.protobuf.text_encoding.""" |
-__author__ = 'matthewtoia@google.com (Matt Toia)' |
+try: |
+ import unittest2 as unittest |
+except ImportError: |
+ import unittest |
+from google.protobuf import text_encoding |
-import unittest |
-from google.protobuf import descriptor_pb2 |
-from google.protobuf.internal import factory_test2_pb2 |
-from google.protobuf import descriptor_database |
+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", |
+ "\x08\\t\\n\x0b\x0c\\r", |
+ b"\010\011\012\013\014\015")] |
-class DescriptorDatabaseTest(unittest.TestCase): |
+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)) |
- def testAdd(self): |
- db = descriptor_database.DescriptorDatabase() |
- file_desc_proto = descriptor_pb2.FileDescriptorProto.FromString( |
- factory_test2_pb2.DESCRIPTOR.serialized_pb) |
- db.Add(file_desc_proto) |
+ def testCUnescape(self): |
+ for escaped, escaped_utf8, unescaped in TEST_VALUES: |
+ self.assertEqual(unescaped, text_encoding.CUnescape(escaped)) |
+ self.assertEqual(unescaped, text_encoding.CUnescape(escaped_utf8)) |
- self.assertEquals(file_desc_proto, db.FindFileByName( |
- 'net/proto2/python/internal/factory_test2.proto')) |
- self.assertEquals(file_desc_proto, db.FindFileContainingSymbol( |
- 'net.proto2.python.internal.Factory2Message')) |
- self.assertEquals(file_desc_proto, db.FindFileContainingSymbol( |
- 'net.proto2.python.internal.Factory2Message.NestedFactory2Message')) |
- self.assertEquals(file_desc_proto, db.FindFileContainingSymbol( |
- 'net.proto2.python.internal.Factory2Enum')) |
- self.assertEquals(file_desc_proto, db.FindFileContainingSymbol( |
- 'net.proto2.python.internal.Factory2Message.NestedFactory2Enum')) |
-if __name__ == '__main__': |
+if __name__ == "__main__": |
unittest.main() |