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')))
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")))
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)
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)
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})""")
def test_unicode_repr(self): repr(Chunk('–')) self.assertEqual(repr(fmtstr('–')), repr_without_leading_u('–'))
def test_funny_chars(self): fmtstr('⁇', 'blue') str(Chunk('⁇', {'fg': 'blue'})) str(fmtstr('⁇', 'blue')) unicode(fmtstr('⁇', 'blue')) self.assertTrue(True)
def add_things(n): part = Chunk('hi', {'fg': 36}) whole = FmtStr(part) return sum([whole for _ in range(n)], FmtStr())
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)
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)
def test_funny_chars(self): fmtstr("⁇", "blue") str(Chunk("⁇", {"fg": "blue"})) str(fmtstr("⁇", "blue")) unicode(fmtstr("⁇", "blue")) self.assertTrue(True)
def test_repr(self): c = Chunk("a", {"fg": 32}) self.assertEqual(repr(c), """Chunk('a', {'fg': 32})""")
def test_unicode_repr(self): repr(Chunk(u'–')) self.assertEqual(repr(fmtstr(u'–')), repr(u'–'))