about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/nix/nixos-render-docs/src/tests/test_lists.py
blob: f53442a96d4cffdb6f3e98556007a86f52e464e7 (plain) (blame)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import nixos_render_docs as nrd
import pytest

from markdown_it.token import Token

class Converter(nrd.md.Converter[nrd.docbook.DocBookRenderer]):
    # actual renderer doesn't matter, we're just parsing.
    def __init__(self, manpage_urls: dict[str, str]) -> None:
        super().__init__()
        self._renderer = nrd.docbook.DocBookRenderer(manpage_urls)

@pytest.mark.parametrize("ordered", [True, False])
def test_list_wide(ordered: bool) -> None:
    t, tag, m, e1, e2, i1, i2 = (
        ("ordered", "ol", ".", "1.", "2.", "1", "2") if ordered else ("bullet", "ul", "-", "-", "-", "", "")
    )
    c = Converter({})
    meta = { 'end': int(e2[:-1]) } if ordered else {}
    meta['compact'] = False
    assert c._parse(f"{e1} a\n\n{e2} b") == [
        Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={}, map=[0, 3], level=0,
              children=None, content='', markup=m, info='', meta=meta, block=True, hidden=False),
        Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 2], level=1, children=None,
              content='', markup=m, info=i1, meta={}, block=True, hidden=False),
        Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=2, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=False),
        Token(type='inline', tag='', nesting=0, attrs={}, map=[0, 1], level=3,
              content='a', markup='', info='', meta={}, block=True, hidden=False,
              children=[
                  Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
                        content='a', markup='', info='', meta={}, block=False, hidden=False)
              ]),
        Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=2, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=False),
        Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
              content='', markup=m, info='', meta={}, block=True, hidden=False),
        Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[2, 3], level=1, children=None,
              content='', markup=m, info=i2, meta={}, block=True, hidden=False),
        Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[2, 3], level=2, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=False),
        Token(type='inline', tag='', nesting=0, attrs={}, map=[2, 3], level=3,
              content='b', markup='', info='', meta={}, block=True, hidden=False,
              children=[
                  Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
                        content='b', markup='', info='', meta={}, block=False, hidden=False)
              ]),
        Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=2, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=False),
        Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
              content='', markup=m, info='', meta={}, block=True, hidden=False),
        Token(type=f'{t}_list_close', tag=tag, nesting=-1, attrs={}, map=None, level=0, children=None,
              content='', markup=m, info='', meta={}, block=True, hidden=False)
    ]

@pytest.mark.parametrize("ordered", [True, False])
def test_list_narrow(ordered: bool) -> None:
    t, tag, m, e1, e2, i1, i2 = (
        ("ordered", "ol", ".", "1.", "2.", "1", "2") if ordered else ("bullet", "ul", "-", "-", "-", "", "")
    )
    c = Converter({})
    meta = { 'end': int(e2[:-1]) } if ordered else {}
    meta['compact'] = True
    assert c._parse(f"{e1} a\n{e2} b") == [
        Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={}, map=[0, 2], level=0,
              children=None, content='', markup=m, info='', meta=meta, block=True, hidden=False),
        Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 1], level=1, children=None,
              content='', markup=m, info=i1, meta={}, block=True, hidden=False),
        Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=2, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=True),
        Token(type='inline', tag='', nesting=0, attrs={}, map=[0, 1], level=3,
              content='a', markup='', info='', meta={}, block=True, hidden=False,
              children=[
                  Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
                        content='a', markup='', info='', meta={}, block=False, hidden=False)
              ]),
        Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=2, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=True),
        Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
              content='', markup=m, info='', meta={}, block=True, hidden=False),
        Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[1, 2], level=1, children=None,
              content='', markup=m, info=i2, meta={}, block=True, hidden=False),
        Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[1, 2], level=2, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=True),
        Token(type='inline', tag='', nesting=0, attrs={}, map=[1, 2], level=3,
              content='b', markup='', info='', meta={}, block=True, hidden=False,
              children=[
                  Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
                        content='b', markup='', info='', meta={}, block=False, hidden=False)
              ]),
        Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=2, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=True),
        Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
              content='', markup=m, info='', meta={}, block=True, hidden=False),
        Token(type=f'{t}_list_close', tag=tag, nesting=-1, attrs={}, map=None, level=0, children=None,
              content='', markup=m, info='', meta={}, block=True, hidden=False)
    ]
    assert c._parse(f"{e1} - a\n{e2} b") == [
        Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={}, map=[0, 2], level=0,
              children=None, content='', markup=m, info='', meta=meta, block=True, hidden=False),
        Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 1], level=1, children=None,
              content='', markup=m, info=i1, meta={}, block=True, hidden=False),
        Token(type='bullet_list_open', tag='ul', nesting=1, attrs={}, map=[0, 1], level=2,
              children=None, content='', markup='-', info='', meta={'compact': True}, block=True, hidden=False),
        Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 1], level=3, children=None,
              content='', markup='-', info='', meta={}, block=True, hidden=False),
        Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=4, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=True),
        Token(type='inline', tag='', nesting=0, attrs={}, map=[0, 1], level=5,
              content='a', markup='', info='', meta={}, block=True, hidden=False,
              children=[
                  Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
                        content='a', markup='', info='', meta={}, block=False, hidden=False)
              ]),
        Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=4, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=True),
        Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=3, children=None,
              content='', markup='-', info='', meta={}, block=True, hidden=False),
        Token(type='bullet_list_close', tag='ul', nesting=-1, attrs={}, map=None, level=2, children=None,
              content='', markup='-', info='', meta={}, block=True, hidden=False),
        Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
              content='', markup=m, info='', meta={}, block=True, hidden=False),
        Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[1, 2], level=1, children=None,
              content='', markup=m, info=i2, meta={}, block=True, hidden=False),
        Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[1, 2], level=2, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=True),
        Token(type='inline', tag='', nesting=0, attrs={}, map=[1, 2], level=3,
              content='b', markup='', info='', meta={}, block=True, hidden=False,
              children=[
                  Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
                        content='b', markup='', info='', meta={}, block=False, hidden=False)
              ]),
        Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=2, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=True),
        Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
              content='', markup=m, info='', meta={}, block=True, hidden=False),
        Token(type=f'{t}_list_close', tag=tag, nesting=-1, attrs={}, map=None, level=0, children=None,
              content='', markup=m, info='', meta={}, block=True, hidden=False)
    ]
    assert c._parse(f"{e1} - a\n{e2} - b") == [
        Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={}, map=[0, 2], level=0,
              children=None, content='', markup=m, info='', meta=meta, block=True, hidden=False),
        Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 1], level=1, children=None,
              content='', markup=m, info=i1, meta={}, block=True, hidden=False),
        Token(type='bullet_list_open', tag='ul', nesting=1, attrs={}, map=[0, 1], level=2,
              children=None, content='', markup='-', info='', meta={'compact': True}, block=True, hidden=False),
        Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 1], level=3, children=None,
              content='', markup='-', info='', meta={}, block=True, hidden=False),
        Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=4, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=True),
        Token(type='inline', tag='', nesting=0, attrs={}, map=[0, 1], level=5,
              content='a', markup='', info='', meta={}, block=True, hidden=False,
              children=[
                  Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
                        content='a', markup='', info='', meta={}, block=False, hidden=False)
              ]),
        Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=4, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=True),
        Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=3, children=None,
              content='', markup='-', info='', meta={}, block=True, hidden=False),
        Token(type='bullet_list_close', tag='ul', nesting=-1, attrs={}, map=None, level=2, children=None,
              content='', markup='-', info='', meta={}, block=True, hidden=False),
        Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
              content='', markup=m, info='', meta={}, block=True, hidden=False),
        Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[1, 2], level=1, children=None,
              content='', markup=m, info=i2, meta={}, block=True, hidden=False),
        Token(type='bullet_list_open', tag='ul', nesting=1, attrs={}, map=[1, 2], level=2,
              children=None, content='', markup='-', info='', meta={'compact': True}, block=True, hidden=False),
        Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[1, 2], level=3, children=None,
              content='', markup='-', info='', meta={}, block=True, hidden=False),
        Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[1, 2], level=4, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=True),
        Token(type='inline', tag='', nesting=0, attrs={}, map=[1, 2], level=5,
              content='b', markup='', info='', meta={}, block=True, hidden=False,
              children=[
                  Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
                        content='b', markup='', info='', meta={}, block=False, hidden=False)
              ]),
        Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=4, children=None,
              content='', markup='', info='', meta={}, block=True, hidden=True),
        Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=3, children=None,
              content='', markup='-', info='', meta={}, block=True, hidden=False),
        Token(type='bullet_list_close', tag='ul', nesting=-1, attrs={}, map=None, level=2, children=None,
              content='', markup='-', info='', meta={}, block=True, hidden=False),
        Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
              content='', markup=m, info='', meta={}, block=True, hidden=False),
        Token(type=f'{t}_list_close', tag=tag, nesting=-1, attrs={}, map=None, level=0, children=None,
              content='', markup=m, info='', meta={}, block=True, hidden=False)
    ]