コード例 #1
0
 def testLineWrap(self):
   terminal.TerminalSize = lambda: (5, 11)
   text = ''
   self.assertEqual(text, terminal.LineWrap(text))
   text = 'one line'
   self.assertEqual(text, terminal.LineWrap(text))
   text = 'two\nlines'
   self.assertEqual(text, terminal.LineWrap(text))
   text = 'one line that is too long'
   text2 = 'one line th\nat is too l\nong'
   self.assertEqual(text2, terminal.LineWrap(text))
   # Counting ansi characters won't matter if there are none.
   self.assertEqual(text2, terminal.LineWrap(text, False))
   text = 'one line \033[5;32;44mthat\033[0m is too long with ansi'
   text2 = 'one line \033[5;32;44mth\nat\033[0m is too l\nong with an\nsi'
   text3 = 'one line \033[\n5;32;44mtha\nt\033[0m is to\no long with\n ansi'
   # Ansi does not factor and the line breaks stay the same.
   self.assertEqual(text2, terminal.LineWrap(text, True))
   # If we count the ansi escape as characters then the line breaks change.
   self.assertEqual(text3, terminal.LineWrap(text, False))
   # False is implicit default.
   self.assertEqual(text3, terminal.LineWrap(text))
   # Couple of edge cases where we split on token boundary.
   text4 = 'ooone line \033[5;32;44mthat\033[0m is too long with ansi'
   text5 = 'ooone line \033[5;32;44m\nthat\033[0m is too\n long with \nansi'
   self.assertEqual(text5, terminal.LineWrap(text4, True))
   text6 = 'e line \033[5;32;44mthat\033[0m is too long with ansi'
   text7 = 'e line \033[5;32;44mthat\033[0m\n is too lon\ng with ansi'
   self.assertEqual(text7, terminal.LineWrap(text6, True))
コード例 #2
0
 def testIssue1(self):
   self.assertEqual(10, len(terminal.StripAnsiText('boembabies' '\033[0m')))
   terminal.TerminalSize = lambda: (10, 10)
   text1 = terminal.LineWrap('\033[32m' + 'boembabies, ' * 10 + 'boembabies' +
                             '\033[0m', omit_sgr=True)
   text2 = ('\033[32m' +
            terminal.LineWrap('boembabies, ' * 10 + 'boembabies') +
            '\033[0m')
   self.assertEqual(text1, text2)