summaryrefslogtreecommitdiff
path: root/tests/test_groff_formatter.py
blob: 2378a45e6aa6cae2e899a93dce62be51ca77acc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
    Pygments Groff formatter tests
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

from pygments import highlight
from pygments.lexer import RegexLexer
from pygments.lexers import PythonLexer
from pygments.style import Style
from pygments.token import Token
from pygments.formatters import GroffFormatter


# FIXME: more thorough tests

def test_basic():
    code = """
for it in that:
    do(it)

import this
"""
    expected = r""".defcolor 000080 rgb #000080
.defcolor 0000FF rgb #0000FF
.defcolor 0044DD rgb #0044DD
.defcolor 008000 rgb #008000
.defcolor 008400 rgb #008400
.defcolor 19177C rgb #19177C
.defcolor 3D7B7B rgb #3D7B7B
.defcolor 666666 rgb #666666
.defcolor 687822 rgb #687822
.defcolor 717171 rgb #717171
.defcolor 767600 rgb #767600
.defcolor 800080 rgb #800080
.defcolor 880000 rgb #880000
.defcolor 9C6500 rgb #9C6500
.defcolor A00000 rgb #A00000
.defcolor A45A77 rgb #A45A77
.defcolor AA22FF rgb #AA22FF
.defcolor AA5D1F rgb #AA5D1F
.defcolor B00040 rgb #B00040
.defcolor BA2121 rgb #BA2121
.defcolor CB3F38 rgb #CB3F38
.defcolor E40000 rgb #E40000
.defcolor bbbbbb rgb #bbbbbb
.nf
\f[CR]
\m[008000]\f[CB]for\f[CR]\m[] it \m[AA22FF]\f[CB]in\f[CR]\m[] that:
    do(it)

\m[008000]\f[CB]import\f[CR]\m[] \m[0000FF]\f[CB]this\f[CR]\m[]

.fi"""
    assert highlight(code, PythonLexer(), GroffFormatter()) == expected


class ToyLexer(RegexLexer):
    tokens = {
        "root": [
            ("a", Token.Name),
            ("b", Token.Name.Custom),
        ],
    }

class ToyStyle(Style):
    styles = {
        Token.Name: "bold",
    }


def test_inheritance_custom_tokens():
    expected = r""".nf
\f[CR]
\f[CB]a\f[CR]\f[CB]b\f[CR]

.fi"""
    assert highlight("ab", ToyLexer(), GroffFormatter(style=ToyStyle)) == expected