| 1 | #!/usr/bin/env python2
|
| 2 | from __future__ import print_function
|
| 3 |
|
| 4 | import unittest
|
| 5 |
|
| 6 | from data_lang import pyj8 # module under test
|
| 7 | from mycpp import mylib
|
| 8 |
|
| 9 |
|
| 10 | def _EncodeString(s, options):
|
| 11 | # type: (str, int) -> str
|
| 12 | buf = mylib.BufWriter()
|
| 13 | pyj8.WriteString(s, options, buf)
|
| 14 | return buf.getvalue()
|
| 15 |
|
| 16 |
|
| 17 | class PyJ8Test(unittest.TestCase):
|
| 18 |
|
| 19 | def testEncode(self):
|
| 20 | en = _EncodeString('hello', 0)
|
| 21 | print(en)
|
| 22 |
|
| 23 | en = _EncodeString('\xff-\xfe-\xff-\xfe', 0)
|
| 24 | print(en)
|
| 25 |
|
| 26 | # multiple errrors
|
| 27 | en = _EncodeString('hello\xffthere \xfe\xff gah', 0)
|
| 28 | print(en)
|
| 29 |
|
| 30 | # valid mu
|
| 31 | en = _EncodeString('hello \xce\xbc there', 0)
|
| 32 | print(en)
|
| 33 |
|
| 34 | # two first bytes - invalid
|
| 35 | en = _EncodeString('hello \xce\xce there', 0)
|
| 36 | print(en)
|
| 37 |
|
| 38 | # two cont bytes - invalid
|
| 39 | en = _EncodeString('hello \xbc\xbc there', 0)
|
| 40 | print(en)
|
| 41 |
|
| 42 | en = _EncodeString('hello \xbc\xbc there', pyj8.LOSSY_JSON_STRINGS)
|
| 43 | print(en)
|
| 44 |
|
| 45 |
|
| 46 | if __name__ == '__main__':
|
| 47 | unittest.main()
|
| 48 |
|
| 49 | # vim: sw=4
|