blob: 6d6c8fa42de373b7207ccee975e69e0cf17d5a21 [file] [log] [blame]
Phongphan Phuttha7f01e2a2015-11-06 15:46:50 +07001from thrift import Thrift
2from thrift.protocol.TJSONProtocol import TJSONProtocol
3from thrift.transport import TTransport
4
5import sys
6import unittest
7
8#
9# In order to run the test under Windows. We need to create symbolic link
10# name 'thrift' to '../src' folder by using:
11#
12# mklink /D thrift ..\src
13#
14
15class TestJSONString(unittest.TestCase):
16
17 def test_escaped_unicode_string(self):
Phongphan Phuttha369d62e2015-11-09 02:05:09 +070018 unicode_json = b'"hello \\u0e01\\u0e02\\u0e03\\ud835\\udcab\\udb40\\udc70 unicode"'
19 unicode_text = u'hello \u0e01\u0e02\u0e03\U0001D4AB\U000E0070 unicode'
Phongphan Phuttha7f01e2a2015-11-06 15:46:50 +070020
21 buf = TTransport.TMemoryBuffer(unicode_json)
22 transport = TTransport.TBufferedTransportFactory().getTransport(buf)
23 protocol = TJSONProtocol(transport)
24
25 if sys.version_info[0] == 2:
26 unicode_text = unicode_text.encode('utf8')
27 self.assertEqual(protocol.readString(), unicode_text)
28
29if __name__ == '__main__':
30 unittest.main()
31