def test_foreground(self): lexer = Lexer(80, 1) lexer.lex('Lorem [31mIpsum') assert lexer.get_line(0) == ('<span foreground="white">Lorem </span>' '<span foreground="%s">Ipsum' '%s' '</span>') % (color[1], ' ' * 69)
def bench_simple_text_single_pass(): for cols, rows in ((10, 10), (50, 25), (50, 100)): for size in (10, 100, 1000, 2000, 5000, 10000): random = os.urandom(size).decode('latin-1') lexer = Lexer(cols, rows) lex_timer = Timer() get_line_timer = Timer() with lex_timer: lexer.lex(random) with get_line_timer: for i in range(rows): lexer.get_line(i) print("Term size: \x1b[31m%d, %d\t" "\x1b[mText size: \x1b[32m%d\x1b[m \x1b[65`" "[lex: \x1b[33m%dms\x1b[m\t get_line: \x1b[34m%dms\x1b[m]" % (cols, rows, size, lex_timer.time, get_line_timer.time))
def test_optimize(self): lexer = Lexer(80, 1) lexer.lex('A[31mB[31mC') assert lexer.get_line(0) == ('<span foreground="white">A</span>' '<span foreground="%s">BC' '%s' '</span>') % (color[1], ' ' * 77)
def test_optimize(self): lexer = Lexer(80, 1) lexer.lex('A[31mB[31mC') assert lexer.get_line(0) == ( '<span foreground="white">A</span>' '<span foreground="%s">BC' '%s' '</span>') % (color[1], ' ' * 77)
def test_foreground(self): lexer = Lexer(80, 1) lexer.lex('Lorem [31mIpsum') assert lexer.get_line(0) == ( '<span foreground="white">Lorem </span>' '<span foreground="%s">Ipsum' '%s' '</span>') % (color[1], ' ' * 69)
def test_reverse(self): lexer = Lexer(80, 1) lexer.lex('A[31m[45mB[7mC[7mD[0m') assert lexer.get_line(0) == ( '<span foreground="white">A</span>' '<span foreground="%s" background="%s">B</span>' '<span foreground="%s" background="%s">CD</span>' '<span foreground="white">' '%s' '</span>') % (color[1], color[5], color[5], color[1], ' ' * 76)
def test_background(self): lexer = Lexer(80, 1) lexer.lex('A[31m[45mB[mC[42mD[0m') assert lexer.get_line(0) == ( '<span foreground="white">A</span>' '<span foreground="%s" background="%s">B</span>' '<span foreground="white">C</span>' '<span foreground="white" background="%s">D</span>' '<span foreground="white">' '%s' '</span>') % (color[1], color[5], color[2], ' ' * 76)
def test_foreground_multi(self): lexer = Lexer(80, 1) lexer.lex('A[31mB[mC[32mD[0m') assert lexer.get_line(0) == ('<span foreground="white">A</span>' '<span foreground="%s">B</span>' '<span foreground="white">C</span>' '<span foreground="%s">D</span>' '<span foreground="white">' '%s' '</span>') % (color[1], color[2], ' ' * 76)