OILS / opy / _regtest / src / asdl / encode_test.py View on Github | oilshell.org

37 lines, 18 significant
1#!/usr/bin/env python
2"""
3encode_test.py: Tests for encode.py
4"""
5
6import unittest
7
8from asdl import encode # module under test
9from asdl import const
10
11
12class EncoderTest(unittest.TestCase):
13
14 def testEncoder(self):
15 p = encode.Params(16)
16
17 chunk = bytearray()
18 p.Int(1, chunk)
19 self.assertEqual(b'\x01\x00\x00', chunk)
20
21 chunk = bytearray()
22 p.Int(const.NO_INTEGER, chunk)
23 self.assertEqual(b'\xff\xff\xff', chunk)
24
25 chunk = p.PaddedBytes('0123456789')
26 # 2 byte length -- max 64K entries
27 self.assertEqual(b'\x0A\x000123456789\x00\x00\x00\x00', bytes(chunk))
28
29 chunk = p.PaddedStr('0123456789')
30 # 2 byte length -- max 64K entries
31 self.assertEqual(b'0123456789\x00\x00\x00\x00\x00\x00', bytes(chunk))
32
33 #p.Block([b'a', b'bc'])
34
35
36if __name__ == '__main__':
37 unittest.main()