Ejemplo n.º 1
0
    def test_reusing_same_splitter(self):
        c = Chunk('asdf', {'fg': 32})
        s1 = c.splitter()
        self.assertEqual(s1.request(3), (3, Chunk('asd', {'fg': 32})))
        s1.reinit(c)
        self.assertEqual(s1.request(3), (3, Chunk('asd', {'fg': 32})))
        s1.reinit(c)
        self.assertEqual(s1.request(3), (3, Chunk('asd', {'fg': 32})))

        c2 = Chunk('abcdef', {})
        s1.reinit(c2)
        self.assertEqual(s1.request(3), (3, Chunk('abc')))
Ejemplo n.º 2
0
    def test_reusing_same_splitter(self):
        c = Chunk("asdf", {"fg": 32})
        s1 = c.splitter()
        self.assertEqual(s1.request(3), (3, Chunk("asd", {"fg": 32})))
        s1.reinit(c)
        self.assertEqual(s1.request(3), (3, Chunk("asd", {"fg": 32})))
        s1.reinit(c)
        self.assertEqual(s1.request(3), (3, Chunk("asd", {"fg": 32})))

        c2 = Chunk("abcdef", {})
        s1.reinit(c2)
        self.assertEqual(s1.request(3), (3, Chunk("abc")))
Ejemplo n.º 3
0
    def test_width_awareness(self):
        s = Chunk('asdf')
        self.assertEqual(
            Chunk('ab\u0300c').splitter().request(3), (3, Chunk('ab\u0300c')))
        self.assertEqual(
            Chunk('ab\u0300c').splitter().request(2), (2, Chunk('ab\u0300')))

        s = Chunk('ab\u0300c').splitter()
        self.assertEqual(s.request(1), (1, Chunk('a')))
        self.assertEqual(s.request(2), (2, Chunk('b\u0300c')))

        c = Chunk('aEbc')
        self.assertEqual(c.splitter().request(4), (4, Chunk('aEb')))
        s = c.splitter()
        self.assertEqual(s.request(2), (2, Chunk('a ')))
        self.assertEqual(s.request(2), (2, Chunk('E')))
        self.assertEqual(s.request(2), (2, Chunk('bc')))
        self.assertEqual(s.request(2), None)
Ejemplo n.º 4
0
 def test_chunk_splitter(self):
     splitter = Chunk('asdf', {'fg': 32}).splitter()
     self.assertEqual(splitter.request(1), (1, Chunk('a', {'fg': 32})))
     self.assertEqual(splitter.request(4), (3, Chunk('sdf', {'fg': 32})))
     self.assertEqual(splitter.request(4), None)
Ejemplo n.º 5
0
 def test_repr(self):
     c = Chunk('a', {'fg': 32})
     if PY2:
         self.assertEqual(repr(c), """Chunk(u'a', {'fg': 32})""")
     else:
         self.assertEqual(repr(c), """Chunk('a', {'fg': 32})""")
Ejemplo n.º 6
0
 def test_unicode_repr(self):
     repr(Chunk('–'))
     self.assertEqual(repr(fmtstr('–')), repr_without_leading_u('–'))
Ejemplo n.º 7
0
 def test_funny_chars(self):
     fmtstr('⁇', 'blue')
     str(Chunk('⁇', {'fg': 'blue'}))
     str(fmtstr('⁇', 'blue'))
     unicode(fmtstr('⁇', 'blue'))
     self.assertTrue(True)
Ejemplo n.º 8
0
def add_things(n):
    part = Chunk('hi', {'fg': 36})
    whole = FmtStr(part)
    return sum([whole for _ in range(n)], FmtStr())
Ejemplo n.º 9
0
    def test_width_awareness(self):
        s = Chunk("asdf")
        self.assertEqual(
            Chunk("ab\u0300c").splitter().request(3), (3, Chunk("ab\u0300c")))
        self.assertEqual(
            Chunk("ab\u0300c").splitter().request(2), (2, Chunk("ab\u0300")))

        s = Chunk("ab\u0300c").splitter()
        self.assertEqual(s.request(1), (1, Chunk("a")))
        self.assertEqual(s.request(2), (2, Chunk("b\u0300c")))

        c = Chunk("aEbc")
        self.assertEqual(c.splitter().request(4), (4, Chunk("aEb")))
        s = c.splitter()
        self.assertEqual(s.request(2), (2, Chunk("a ")))
        self.assertEqual(s.request(2), (2, Chunk("E")))
        self.assertEqual(s.request(2), (2, Chunk("bc")))
        self.assertEqual(s.request(2), None)
Ejemplo n.º 10
0
 def test_chunk_splitter(self):
     splitter = Chunk("asdf", {"fg": 32}).splitter()
     self.assertEqual(splitter.request(1), (1, Chunk("a", {"fg": 32})))
     self.assertEqual(splitter.request(4), (3, Chunk("sdf", {"fg": 32})))
     self.assertEqual(splitter.request(4), None)
Ejemplo n.º 11
0
 def test_funny_chars(self):
     fmtstr("⁇", "blue")
     str(Chunk("⁇", {"fg": "blue"}))
     str(fmtstr("⁇", "blue"))
     unicode(fmtstr("⁇", "blue"))
     self.assertTrue(True)
Ejemplo n.º 12
0
 def test_repr(self):
     c = Chunk("a", {"fg": 32})
     self.assertEqual(repr(c), """Chunk('a', {'fg': 32})""")
Ejemplo n.º 13
0
 def test_unicode_repr(self):
     repr(Chunk(u'–'))
     self.assertEqual(repr(fmtstr(u'–')), repr(u'–'))