Debian Codegraph @

tests/test_groff_formatter.py

raw
1 """
2 Pygments Groff formatter tests
3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5 :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
6 :license: BSD, see LICENSE for details.
7 """
8
9 from pygments import highlight
10 from pygments.lexer import RegexLexer
11 from pygments.lexers import PythonLexer
12 from pygments.style import Style
13 from pygments.token import Token
14 from pygments.formatters import GroffFormatter
15
16
17 # FIXME: more thorough tests
18
19 def test_basic():
20 code = """
21 for it in that:
22 do(it)
23
24 import this
25 """
26 expected = r""".defcolor 000080 rgb #000080
27 .defcolor 0000FF rgb #0000FF
28 .defcolor 0044DD rgb #0044DD
29 .defcolor 008000 rgb #008000
30 .defcolor 008400 rgb #008400
31 .defcolor 19177C rgb #19177C
32 .defcolor 3D7B7B rgb #3D7B7B
33 .defcolor 666666 rgb #666666
34 .defcolor 687822 rgb #687822
35 .defcolor 717171 rgb #717171
36 .defcolor 767600 rgb #767600
37 .defcolor 800080 rgb #800080
38 .defcolor 880000 rgb #880000
39 .defcolor 9C6500 rgb #9C6500
40 .defcolor A00000 rgb #A00000
41 .defcolor A45A77 rgb #A45A77
42 .defcolor AA22FF rgb #AA22FF
43 .defcolor AA5D1F rgb #AA5D1F
44 .defcolor B00040 rgb #B00040
45 .defcolor BA2121 rgb #BA2121
46 .defcolor CB3F38 rgb #CB3F38
47 .defcolor E40000 rgb #E40000
48 .defcolor bbbbbb rgb #bbbbbb
49 .nf
50 \f[CR]
51 \m[008000]\f[CB]for\f[CR]\m[] it \m[AA22FF]\f[CB]in\f[CR]\m[] that:
52 do(it)
53
54 \m[008000]\f[CB]import\f[CR]\m[]\m[bbbbbb] \m[]\m[0000FF]\f[CB]this\f[CR]\m[]
55
56 .fi"""
57 assert highlight(code, PythonLexer(), GroffFormatter()) == expected
58
59
60 class ToyLexer(RegexLexer):
61 tokens = {
62 "root": [
63 ("a", Token.Name),
64 ("b", Token.Name.Custom),
65 ],
66 }
67
68 class ToyStyle(Style):
69 styles = {
70 Token.Name: "bold",
71 }
72
73
74 def test_inheritance_custom_tokens():
75 expected = r""".nf
76 \f[CR]
77 \f[CB]a\f[CR]\f[CB]b\f[CR]
78
79 .fi"""
80 assert highlight("ab", ToyLexer(), GroffFormatter(style=ToyStyle)) == expected