OILS / data_lang / pyj8_test.py View on Github | oilshell.org

52 lines, 26 significant
1#!/usr/bin/env python2
2"""
3pyj8_test.py: Tests for pyj8.py
4"""
5from __future__ import print_function
6
7import unittest
8
9from data_lang import pyj8 # module under test
10from mycpp import mylib
11
12
13def _EncodeString(s, options):
14 # type: (str, int) -> str
15 buf = mylib.BufWriter()
16 pyj8.WriteString(s, options, buf)
17 return buf.getvalue()
18
19
20class 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
49if __name__ == '__main__':
50 unittest.main()
51
52# vim: sw=4