Exemple #1
0
 def test_foreground(self):
     lexer = Lexer(80, 1)
     lexer.lex('Lorem Ipsum')
     assert lexer.get_line(0) == ('<span foreground="white">Lorem </span>'
                                  '<span foreground="%s">Ipsum'
                                  '%s'
                                  '</span>') % (color[1], ' ' * 69)
Exemple #2
0
 def test_optimize(self):
     lexer = Lexer(80, 1)
     lexer.lex('ABC')
     assert lexer.get_line(0) == ('<span foreground="white">A</span>'
                                  '<span foreground="%s">BC'
                                  '%s'
                                  '</span>') % (color[1], ' ' * 77)
Exemple #3
0
 def test_optimize(self):
     lexer = Lexer(80, 1)
     lexer.lex('ABC')
     assert lexer.get_line(0) == (
         '<span foreground="white">A</span>'
         '<span foreground="%s">BC'
         '%s'
         '</span>') % (color[1], ' ' * 77)
Exemple #4
0
 def test_foreground(self):
     lexer = Lexer(80, 1)
     lexer.lex('Lorem Ipsum')
     assert lexer.get_line(0) == (
         '<span foreground="white">Lorem </span>'
         '<span foreground="%s">Ipsum'
         '%s'
         '</span>') % (color[1], ' ' * 69)
Exemple #5
0
 def test_reverse(self):
     lexer = Lexer(80, 1)
     lexer.lex('ABCD')
     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)
Exemple #6
0
 def test_background(self):
     lexer = Lexer(80, 1)
     lexer.lex('ABCD')
     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)
Exemple #7
0
 def test_foreground_multi(self):
     lexer = Lexer(80, 1)
     lexer.lex('ABCD')
     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)
Exemple #8
0
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))
Exemple #9
0
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))
Exemple #10
0
def test_cursor():
    lexer = Lexer(10, 3)
    assert lexer.matrix.cols == 10
    assert lexer.matrix.rows == 3
    assert lexer.matrix.scroll == 0
    assert len(lexer.matrix.matrix[0]) == 10
    assert len(lexer.matrix.matrix) == 3
    assert lexer.cursor.x == 0
    assert lexer.cursor.y == 0
    lexer.lex('test')
    assert lexer.cursor.x == 4
    assert lexer.cursor.y == 0
    lexer.lex(' ')
    assert lexer.cursor.x == 5
    assert lexer.cursor.y == 0
    lexer.lex('test')
    assert lexer.cursor.x == 9
    assert lexer.cursor.y == 0
    lexer.lex('...')
    assert lexer.cursor.x == 2
    assert lexer.cursor.y == 1
    lexer.lex('.' * 18)
    assert lexer.cursor.x == 10
    assert lexer.cursor.y == 2
    assert lexer.matrix.scroll == 0
    lexer.lex('.')
    assert lexer.matrix.scroll == 1
    assert lexer.cursor.x == 1
    assert lexer.cursor.y == 2