コード例 #1
0
ファイル: test_strings.py プロジェクト: cbisnett/construct
 def test_build_terminator(self):
     s = CString("foo", terminators=six.b("XYZ"), encoding="utf8")
     self.assertEqual(s.build(six.u("hello")), six.b("helloX"))
コード例 #2
0
ファイル: test_strings.py プロジェクト: cbisnett/construct
        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"))



コード例 #3
0
ファイル: test_strings.py プロジェクト: cbisnett/construct
 def test_build(self):
     s = CString("foo", encoding="utf8")
     self.assertEqual(s.build(six.u("hello")), six.b("hello\x00"))
コード例 #4
0
ファイル: test_strings.py プロジェクト: tmr232/construct
 def test_build(self):
     s = CString("foo", encoding="utf8")
     self.assertEqual(s.build(six.u("hello")), six.b("hello\x00"))
コード例 #5
0
ファイル: test_strings.py プロジェクト: tmr232/construct
 def test_build_terminator(self):
     s = CString("foo", terminators=six.b("XYZ"), encoding="utf8")
     self.assertEqual(s.build(six.u("hello")), six.b("helloX"))
コード例 #6
0
ファイル: test_strings.py プロジェクト: tmr232/construct
        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"))
コード例 #7
0
ファイル: test_strings.py プロジェクト: jbremer/construct
 def test_build_terminator(self):
     s = CString("foo", terminators=b"XYZ")
     self.assertEqual(s.build(b"hello"), b"helloX")
コード例 #8
0
ファイル: test_strings.py プロジェクト: jbremer/construct
 def test_build(self):
     s = CString("foo")
     self.assertEqual(s.build(b"hello"), b"hello\x00")
コード例 #9
0
 def test_build_terminator(self):
     s = CString("s", terminators=b"XYZ", encoding="utf8")
     self.assertEqual(s.build(u"hello"), b"helloX")
コード例 #10
0
 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")