1import nixos_render_docs as nrd
2import pytest
3
4from markdown_it.token import Token
5
6class Converter(nrd.md.Converter[nrd.docbook.DocBookRenderer]):
7 # actual renderer doesn't matter, we're just parsing.
8 def __init__(self, manpage_urls: dict[str, str]) -> None:
9 super().__init__()
10 self._renderer = nrd.docbook.DocBookRenderer(manpage_urls)
11
12@pytest.mark.parametrize("ordered", [True, False])
13def test_list_wide(ordered: bool) -> None:
14 t, tag, m, e1, e2, i1, i2 = (
15 ("ordered", "ol", ".", "1.", "2.", "1", "2") if ordered else ("bullet", "ul", "-", "-", "-", "", "")
16 )
17 c = Converter({})
18 meta = { 'end': int(e2[:-1]) } if ordered else {}
19 meta['compact'] = False
20 assert c._parse(f"{e1} a\n\n{e2} b") == [
21 Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={}, map=[0, 3], level=0,
22 children=None, content='', markup=m, info='', meta=meta, block=True, hidden=False),
23 Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 2], level=1, children=None,
24 content='', markup=m, info=i1, meta={}, block=True, hidden=False),
25 Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=2, children=None,
26 content='', markup='', info='', meta={}, block=True, hidden=False),
27 Token(type='inline', tag='', nesting=0, attrs={}, map=[0, 1], level=3,
28 content='a', markup='', info='', meta={}, block=True, hidden=False,
29 children=[
30 Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
31 content='a', markup='', info='', meta={}, block=False, hidden=False)
32 ]),
33 Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=2, children=None,
34 content='', markup='', info='', meta={}, block=True, hidden=False),
35 Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
36 content='', markup=m, info='', meta={}, block=True, hidden=False),
37 Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[2, 3], level=1, children=None,
38 content='', markup=m, info=i2, meta={}, block=True, hidden=False),
39 Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[2, 3], level=2, children=None,
40 content='', markup='', info='', meta={}, block=True, hidden=False),
41 Token(type='inline', tag='', nesting=0, attrs={}, map=[2, 3], level=3,
42 content='b', markup='', info='', meta={}, block=True, hidden=False,
43 children=[
44 Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
45 content='b', markup='', info='', meta={}, block=False, hidden=False)
46 ]),
47 Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=2, children=None,
48 content='', markup='', info='', meta={}, block=True, hidden=False),
49 Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
50 content='', markup=m, info='', meta={}, block=True, hidden=False),
51 Token(type=f'{t}_list_close', tag=tag, nesting=-1, attrs={}, map=None, level=0, children=None,
52 content='', markup=m, info='', meta={}, block=True, hidden=False)
53 ]
54
55@pytest.mark.parametrize("ordered", [True, False])
56def test_list_narrow(ordered: bool) -> None:
57 t, tag, m, e1, e2, i1, i2 = (
58 ("ordered", "ol", ".", "1.", "2.", "1", "2") if ordered else ("bullet", "ul", "-", "-", "-", "", "")
59 )
60 c = Converter({})
61 meta = { 'end': int(e2[:-1]) } if ordered else {}
62 meta['compact'] = True
63 assert c._parse(f"{e1} a\n{e2} b") == [
64 Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={}, map=[0, 2], level=0,
65 children=None, content='', markup=m, info='', meta=meta, block=True, hidden=False),
66 Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 1], level=1, children=None,
67 content='', markup=m, info=i1, meta={}, block=True, hidden=False),
68 Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=2, children=None,
69 content='', markup='', info='', meta={}, block=True, hidden=True),
70 Token(type='inline', tag='', nesting=0, attrs={}, map=[0, 1], level=3,
71 content='a', markup='', info='', meta={}, block=True, hidden=False,
72 children=[
73 Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
74 content='a', markup='', info='', meta={}, block=False, hidden=False)
75 ]),
76 Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=2, children=None,
77 content='', markup='', info='', meta={}, block=True, hidden=True),
78 Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
79 content='', markup=m, info='', meta={}, block=True, hidden=False),
80 Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[1, 2], level=1, children=None,
81 content='', markup=m, info=i2, meta={}, block=True, hidden=False),
82 Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[1, 2], level=2, children=None,
83 content='', markup='', info='', meta={}, block=True, hidden=True),
84 Token(type='inline', tag='', nesting=0, attrs={}, map=[1, 2], level=3,
85 content='b', markup='', info='', meta={}, block=True, hidden=False,
86 children=[
87 Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
88 content='b', markup='', info='', meta={}, block=False, hidden=False)
89 ]),
90 Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=2, children=None,
91 content='', markup='', info='', meta={}, block=True, hidden=True),
92 Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
93 content='', markup=m, info='', meta={}, block=True, hidden=False),
94 Token(type=f'{t}_list_close', tag=tag, nesting=-1, attrs={}, map=None, level=0, children=None,
95 content='', markup=m, info='', meta={}, block=True, hidden=False)
96 ]
97 assert c._parse(f"{e1} - a\n{e2} b") == [
98 Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={}, map=[0, 2], level=0,
99 children=None, content='', markup=m, info='', meta=meta, block=True, hidden=False),
100 Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 1], level=1, children=None,
101 content='', markup=m, info=i1, meta={}, block=True, hidden=False),
102 Token(type='bullet_list_open', tag='ul', nesting=1, attrs={}, map=[0, 1], level=2,
103 children=None, content='', markup='-', info='', meta={'compact': True}, block=True, hidden=False),
104 Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 1], level=3, children=None,
105 content='', markup='-', info='', meta={}, block=True, hidden=False),
106 Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=4, children=None,
107 content='', markup='', info='', meta={}, block=True, hidden=True),
108 Token(type='inline', tag='', nesting=0, attrs={}, map=[0, 1], level=5,
109 content='a', markup='', info='', meta={}, block=True, hidden=False,
110 children=[
111 Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
112 content='a', markup='', info='', meta={}, block=False, hidden=False)
113 ]),
114 Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=4, children=None,
115 content='', markup='', info='', meta={}, block=True, hidden=True),
116 Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=3, children=None,
117 content='', markup='-', info='', meta={}, block=True, hidden=False),
118 Token(type='bullet_list_close', tag='ul', nesting=-1, attrs={}, map=None, level=2, children=None,
119 content='', markup='-', info='', meta={}, block=True, hidden=False),
120 Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
121 content='', markup=m, info='', meta={}, block=True, hidden=False),
122 Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[1, 2], level=1, children=None,
123 content='', markup=m, info=i2, meta={}, block=True, hidden=False),
124 Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[1, 2], level=2, children=None,
125 content='', markup='', info='', meta={}, block=True, hidden=True),
126 Token(type='inline', tag='', nesting=0, attrs={}, map=[1, 2], level=3,
127 content='b', markup='', info='', meta={}, block=True, hidden=False,
128 children=[
129 Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
130 content='b', markup='', info='', meta={}, block=False, hidden=False)
131 ]),
132 Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=2, children=None,
133 content='', markup='', info='', meta={}, block=True, hidden=True),
134 Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
135 content='', markup=m, info='', meta={}, block=True, hidden=False),
136 Token(type=f'{t}_list_close', tag=tag, nesting=-1, attrs={}, map=None, level=0, children=None,
137 content='', markup=m, info='', meta={}, block=True, hidden=False)
138 ]
139 assert c._parse(f"{e1} - a\n{e2} - b") == [
140 Token(type=f'{t}_list_open', tag=tag, nesting=1, attrs={}, map=[0, 2], level=0,
141 children=None, content='', markup=m, info='', meta=meta, block=True, hidden=False),
142 Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 1], level=1, children=None,
143 content='', markup=m, info=i1, meta={}, block=True, hidden=False),
144 Token(type='bullet_list_open', tag='ul', nesting=1, attrs={}, map=[0, 1], level=2,
145 children=None, content='', markup='-', info='', meta={'compact': True}, block=True, hidden=False),
146 Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[0, 1], level=3, children=None,
147 content='', markup='-', info='', meta={}, block=True, hidden=False),
148 Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[0, 1], level=4, children=None,
149 content='', markup='', info='', meta={}, block=True, hidden=True),
150 Token(type='inline', tag='', nesting=0, attrs={}, map=[0, 1], level=5,
151 content='a', markup='', info='', meta={}, block=True, hidden=False,
152 children=[
153 Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
154 content='a', markup='', info='', meta={}, block=False, hidden=False)
155 ]),
156 Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=4, children=None,
157 content='', markup='', info='', meta={}, block=True, hidden=True),
158 Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=3, children=None,
159 content='', markup='-', info='', meta={}, block=True, hidden=False),
160 Token(type='bullet_list_close', tag='ul', nesting=-1, attrs={}, map=None, level=2, children=None,
161 content='', markup='-', info='', meta={}, block=True, hidden=False),
162 Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
163 content='', markup=m, info='', meta={}, block=True, hidden=False),
164 Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[1, 2], level=1, children=None,
165 content='', markup=m, info=i2, meta={}, block=True, hidden=False),
166 Token(type='bullet_list_open', tag='ul', nesting=1, attrs={}, map=[1, 2], level=2,
167 children=None, content='', markup='-', info='', meta={'compact': True}, block=True, hidden=False),
168 Token(type='list_item_open', tag='li', nesting=1, attrs={}, map=[1, 2], level=3, children=None,
169 content='', markup='-', info='', meta={}, block=True, hidden=False),
170 Token(type='paragraph_open', tag='p', nesting=1, attrs={}, map=[1, 2], level=4, children=None,
171 content='', markup='', info='', meta={}, block=True, hidden=True),
172 Token(type='inline', tag='', nesting=0, attrs={}, map=[1, 2], level=5,
173 content='b', markup='', info='', meta={}, block=True, hidden=False,
174 children=[
175 Token(type='text', tag='', nesting=0, attrs={}, map=None, level=0, children=None,
176 content='b', markup='', info='', meta={}, block=False, hidden=False)
177 ]),
178 Token(type='paragraph_close', tag='p', nesting=-1, attrs={}, map=None, level=4, children=None,
179 content='', markup='', info='', meta={}, block=True, hidden=True),
180 Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=3, children=None,
181 content='', markup='-', info='', meta={}, block=True, hidden=False),
182 Token(type='bullet_list_close', tag='ul', nesting=-1, attrs={}, map=None, level=2, children=None,
183 content='', markup='-', info='', meta={}, block=True, hidden=False),
184 Token(type='list_item_close', tag='li', nesting=-1, attrs={}, map=None, level=1, children=None,
185 content='', markup=m, info='', meta={}, block=True, hidden=False),
186 Token(type=f'{t}_list_close', tag=tag, nesting=-1, attrs={}, map=None, level=0, children=None,
187 content='', markup=m, info='', meta={}, block=True, hidden=False)
188 ]