Ejemplo n.º 1
0
def test_highlight_existing_compound():
    """Highlight with an existing compound color (multiple SGR's) in the data."""
    config_data = '''rules:
    - regex: World|me
      color: f#aaafff'''
    config = chromaterm.config.parse_config(config_data)

    data = '\x1b[1;38;5;123;38;2;1;1;1;4mHello World\x1b[35;5m It\'s \x1b[32;24mme'
    expected = [
        '\x1b[1m\x1b[38;5;123m\x1b[38;2;1;1;1m\x1b[4m', 'Hello ',
        '\x1b[38;5;153m', 'World', '\x1b[38;2;1;1;1m', '\x1b[35m\x1b[5m',
        ' It\'s ', '\x1b[32m\x1b[24m', '\x1b[38;5;153m', 'me', '\x1b[32m'
    ]

    assert repr(chromaterm.highlight(config, data)) == repr(''.join(expected))
Ejemplo n.º 2
0
def test_highlight_existing_intensity_orphaned():
    """Highlight with an existing intensity (i.e. bold or faint) in the data."""
    config_data = '''rules:
    - description: first
      regex: World
      color: bold'''
    config = chromaterm.config.parse_config(config_data)

    data = ['\x1b[2mHello World', '\x1b[1mHello World']
    expected = [['\x1b[2m', 'Hello ', '\x1b[1m', 'World', '\x1b[2m'],
                ['\x1b[1m', 'Hello ', '\x1b[1m', 'World', '\x1b[1m']]

    for line_data, line_expected in zip(data, expected):
        assert repr(chromaterm.highlight(config, line_data)) == repr(
            ''.join(line_expected))
Ejemplo n.º 3
0
def test_highlight_existing_multiline():
    """Highlight with an existing color in the multi-line data."""
    config_data = '''rules:
    - description: first
      regex: Hello World
      color: f#aaafff'''
    config = chromaterm.config.parse_config(config_data)

    data = ['\x1b[33mHi there', 'Hello World']
    expected = [['\x1b[33m', 'Hi there'],
                ['\x1b[38;5;153m', 'Hello World', '\x1b[33m']]

    for line_data, line_expected in zip(data, expected):
        assert repr(chromaterm.highlight(config, line_data)) == repr(
            ''.join(line_expected))
Ejemplo n.º 4
0
def test_highlight_end_start_overlap_different_type():
    """Two rules of a different target type (e.g. foreground and background)
    overlapping the end of one with the start of the other. Both are applied.
    Also tested in reverse order.
    x: -------
    y:        -------"""
    config_data = '''rules:
    - description: first
      regex: Hello Wo
      color: b#aaafff
    - description: second
      regex: rld
      color: f#fffaaa'''
    config = chromaterm.config.parse_config(config_data)

    data = 'Hello World'
    expected = [
        '\x1b[48;5;153m', 'Hello Wo', '\x1b[49m', '\x1b[38;5;229m', 'rld',
        '\x1b[39m'
    ]

    assert repr(chromaterm.highlight(config, data)) == repr(''.join(expected))
    config['rules'] = list(reversed(config['rules']))
    assert repr(chromaterm.highlight(config, data)) == repr(''.join(expected))
Ejemplo n.º 5
0
def test_highlight_existing_complete_reset():
    """Highlight with an existing complete reset in the data. It should be set
    to our color."""
    config_data = '''rules:
    - description: first
      regex: Hello there, World
      color: f#aaafff'''
    config = chromaterm.config.parse_config(config_data)

    data = 'Hello\x1b[m there, World'
    expected = [
        '\x1b[38;5;153m', 'Hello', '\x1b[38;5;153m', ' there, World',
        '\x1b[39m'
    ]

    assert repr(chromaterm.highlight(config, data)) == repr(''.join(expected))
Ejemplo n.º 6
0
def test_highlight_existing_orphaned():
    """Highlight with two existing colors in the data, the first of which was
    not closed."""
    config_data = '''rules:
    - description: first
      regex: World
      color: f#aaafff'''
    config = chromaterm.config.parse_config(config_data)

    data = '\x1b[33mHello \x1b[34mthere\x1b[m, World'
    expected = [
        '\x1b[33m', 'Hello ', '\x1b[34m', 'there', '\x1b[m', ', ',
        '\x1b[38;5;153m', 'World', '\x1b[m'
    ]

    assert repr(chromaterm.highlight(config, data)) == repr(''.join(expected))
Ejemplo n.º 7
0
def test_highlight_optional_multi_group():
    """Multiple group-specific colors."""
    config_data = '''rules:
    - regex: Hello (World)! It's (me)
      color:
        0: bold
        1: f#f7e08b
        2: f#aaafff'''
    config = chromaterm.config.parse_config(config_data)

    data = 'Hello World! It\'s me'
    expected = [
        '\x1b[1m', 'Hello ', '\x1b[38;5;229m', 'World', '\x1b[39m', '! It\'s ',
        '\x1b[38;5;153m', 'me', '\x1b[39m', '\x1b[22m'
    ]

    assert repr(chromaterm.highlight(config, data)) == repr(''.join(expected))
Ejemplo n.º 8
0
def test_highlight_existing_complete_reset_different_type():
    """Highlight with an existing color and complete reset in the data. The
    color is before the reset. The first rule's match covers both. The second
    rule's match covers the reset only. The rules are of different types."""
    config_data = '''rules:
    - description: first
      regex: Hello there
      color: f#aaafff
    - description: first
      regex: there, World
      color: b#fffaaa'''
    config = chromaterm.config.parse_config(config_data)

    data = '\x1b[44mHello the\x1b[mre, World'
    expected = [
        '\x1b[44m', '\x1b[38;5;153m', 'Hello ', '\x1b[48;5;229m', 'the',
        '\x1b[38;5;153m', 're', '\x1b[39m', ', World', '\x1b[44m'
    ]

    assert repr(chromaterm.highlight(config, data)) == repr(''.join(expected))
Ejemplo n.º 9
0
def test_highlight_full_overlap_different_type():
    """Two rules of a different target type (e.g. foreground and background)
    fully overlapping each other. Both are applied, both ends are kept.
    x: --------------
    y: --------------"""
    config_data = '''rules:
    - description: first
      regex: Hello there, World
      color: b#aaafff
    - description: second
      regex: Hello there, World
      color: f#fffaaa'''
    config = chromaterm.config.parse_config(config_data)

    data = 'Hello there, World'
    expected = [
        '\x1b[48;5;153m', '\x1b[38;5;229m', 'Hello there, World', '\x1b[39m',
        '\x1b[49m'
    ]

    assert repr(chromaterm.highlight(config, data)) == repr(''.join(expected))