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