| 1 | #!/usr/bin/env python
|
| 2 | """
|
| 3 | encode_test.py: Tests for encode.py
|
| 4 | """
|
| 5 |
|
| 6 | import unittest
|
| 7 |
|
| 8 | from asdl import encode # module under test
|
| 9 | from asdl import const
|
| 10 |
|
| 11 |
|
| 12 | class 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 |
|
| 36 | if __name__ == '__main__':
|
| 37 | unittest.main()
|