コード例 #1
0
    def test_trim(self):
        c = BufClass()
        c.append("ab")
        c.append("c")
        c.trim(1)
        self.failUnlessEqual(str(c.copy()), "bc")
        c.trim(1)
        self.failUnlessEqual(str(c.copy()), "c")
        c.trim(1)
        self.failUnlessEqual(str(c.copy()), "")
        c.append("ab")
        c.append("c")
        c.trim(2)
        self.failUnlessEqual(str(c.copy()), "c")
        c.trim(1)
        self.failUnlessEqual(str(c.copy()), "")
        c.append("a")
        c.append("bc")
        c.trim(2)
        self.failUnlessEqual(str(c.copy()), "c")
        c.trim(1)
        self.failUnlessEqual(str(c.copy()), "")

        c.append("abc")
        c.trim(4) # We just silently trim all.
        self.failUnlessEqual(str(c.copy()), "")
コード例 #2
0
    def test_appendleft(self):
        c1 = BufClass()
        c1.append("abcd")
        c1.appendleft("ef")
        self.failUnlessEqual(str(c1.copy()), "efabcd")
        s = c1.popleft(1)
        self.failUnlessEqual(s, "e")
        s = c1.popleft(2)
        self.failUnlessEqual(s, "fa")
        s = c1.popleft(3)
        self.failUnlessEqual(s, "bcd")

        c1 = BufClass()
        c1.append("abcd")
        c1.popleft(1)
        c1.appendleft("ef")
        self.failUnlessEqual(str(c1.copy()), "efbcd")
        s = c1.popleft(1)
        self.failUnlessEqual(s, "e")
        s = c1.popleft(2)
        self.failUnlessEqual(s, "fb")
        s = c1.popleft(3)
        self.failUnlessEqual(s, "cd")
コード例 #3
0
    def test_popleft(self):
        c = BufClass()
        c.append("ab")
        s = c.popleft(1)
        self.failUnlessEqual(s, "a")
        self.failUnlessEqual(str(c.copy()), "b")
        s = c.popleft(1)
        self.failUnlessEqual(s, "b")
        self.failUnlessEqual(str(c.copy()), "")

        c.append("abc")
        s = c.popleft(1)
        self.failUnlessEqual(s, "a")
        self.failUnlessEqual(str(c.copy()), "bc")
        s = c.popleft(1)
        self.failUnlessEqual(s, "b")
        self.failUnlessEqual(str(c.copy()), "c")
        s = c.popleft(1)
        self.failUnlessEqual(s, "c")
        self.failUnlessEqual(str(c.copy()), "")

        c.append("abc")
        s = c.popleft(2)
        self.failUnlessEqual(s, "ab")
        self.failUnlessEqual(str(c.copy()), "c")
        s = c.popleft(1)
        self.failUnlessEqual(s, "c")
        self.failUnlessEqual(str(c.copy()), "")

        c.append("ab")
        c.append("c")
        s = c.popleft(2)
        self.failUnlessEqual(s, "ab")
        self.failUnlessEqual(str(c.copy()), "c")
        s = c.popleft(1)
        self.failUnlessEqual(s, "c")
        self.failUnlessEqual(str(c.copy()), "")

        c.append("a")
        c.append("bc")
        s = c.popleft(2)
        self.failUnlessEqual(s, "ab")
        self.failUnlessEqual(str(c.copy()), "c")
        s = c.popleft(1)
        self.failUnlessEqual(s, "c")
        self.failUnlessEqual(str(c.copy()), "")

        c.append("abc")
        s = c.popleft(4) # We just silently pop them all.
        self.failUnlessEqual(s, "abc")
        self.failUnlessEqual(str(c.copy()), "")
コード例 #4
0
 def test_clear(self):
     c1 = BufClass()
     c1.append("abcd")
     c1.clear()
     self.failUnlessEqual(str(c1.copy()), '')