def test_build_terminator(self): s = CString("foo", terminators=six.b("XYZ"), encoding="utf8") self.assertEqual(s.build(six.u("hello")), six.b("helloX"))
self.assertEqual(s.build(six.u("hello")), six.b("hello\x00")) def test_parse_terminator(self): s = CString("foo", terminators=six.b("XYZ"), encoding="utf8") self.assertEqual(s.parse(six.b("helloX")), six.u("hello")) self.assertEqual(s.parse(six.b("helloY")), six.u("hello")) self.assertEqual(s.parse(six.b("helloZ")), six.u("hello")) def test_build_terminator(self): s = CString("foo", terminators=six.b("XYZ"), encoding="utf8") self.assertEqual(s.build(six.u("hello")), six.b("helloX")) class TestGreedyString(unittest.TestCase): def test_parse(self): s = GreedyString("foo", encoding="utf8") self.assertEqual(s.parse(six.b("hello\x00")), six.u("hello\x00")) def test_build(self): s = GreedyString("foo", encoding="utf8") self.assertEqual(s.build(six.u("hello")), six.b("hello")) if __name__ == "__main__": #unittest.main() s = CString("foo", encoding="utf8") s.build(six.u("hello"))
def test_build(self): s = CString("foo", encoding="utf8") self.assertEqual(s.build(six.u("hello")), six.b("hello\x00"))
s = PascalString("foo", length_field=UBInt16("length"), encoding="utf8") self.assertEqual(s.build(six.u("hello")), six.b("\x00\x05hello")) class TestCString(unittest.TestCase): def test_parse(self): s = CString("foo", encoding="utf8") self.assertEqual(s.parse(six.b("hello\x00")), six.u("hello")) def test_build(self): s = CString("foo", encoding="utf8") self.assertEqual(s.build(six.u("hello")), six.b("hello\x00")) def test_parse_terminator(self): s = CString("foo", terminators=six.b("XYZ"), encoding="utf8") self.assertEqual(s.parse(six.b("helloX")), six.u("hello")) self.assertEqual(s.parse(six.b("helloY")), six.u("hello")) self.assertEqual(s.parse(six.b("helloZ")), six.u("hello")) def test_build_terminator(self): s = CString("foo", terminators=six.b("XYZ"), encoding="utf8") self.assertEqual(s.build(six.u("hello")), six.b("helloX")) if __name__ == "__main__": #unittest.main() s = CString("foo", encoding="utf8") s.build(six.u("hello"))
def test_build_terminator(self): s = CString("foo", terminators=b"XYZ") self.assertEqual(s.build(b"hello"), b"helloX")
def test_build(self): s = CString("foo") self.assertEqual(s.build(b"hello"), b"hello\x00")
def test_build_terminator(self): s = CString("s", terminators=b"XYZ", encoding="utf8") self.assertEqual(s.build(u"hello"), b"helloX")
def test_build(self): s = CString("s", encoding="utf8") self.assertEqual(s.build(u"hello"), b"hello\x00") s = CString("s") self.assertEqual(s.build(b"hello"), b"hello\x00")