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
|
from asciidoc import attrs
import pytest
@pytest.mark.parametrize(
"input,expected",
(
# docstring tests
('', {}),
('hello,world', {'0': 'hello,world', '1': 'hello', '2': 'world'}),
(
'"hello", planet="earth"',
{'0': '"hello", planet="earth"', '1': 'hello', 'planet': 'earth'}
),
# tests taken from
# https://github.com/asciidoctor/asciidoctor/blob/main/test/attribute_list_test.rb
# commented out tests are currently supported by asciidoc.py
('quote', {'0': 'quote', '1': 'quote'}),
('"quote"', {'0': '"quote"', '1': 'quote'}),
('""', {'0': '""', '1': ''}),
# ('"ba\"zaar"', {'0': '"ba\"zaar"', '1': 'ba"zaar'}),
("'quote'", {'0': "'quote'", '1': 'quote'}),
("''", {'0': "''", '1': ''}),
('\'', {'0': '\'', '1': '\''}),
# ('name=\'', {'0': 'name=\'', 'name': '\''}),
# ('name=\'{val}', {'0': 'name=\'{val}', 'name': '\'{val}'}),
('\'ba\\\'zaar\'', {'0': '\'ba\\\'zaar\'', '1': 'ba\'zaar'}),
# ('quote , ', {'0': 'quote , ', '1': 'quote', '2': None}),
# (', John Smith', {'0': ', John Smith', '1': None, '2': 'John Smith'}),
(
'first, second one, third',
{
'0': 'first, second one, third',
'1': 'first',
'2': 'second one', '3': 'third',
},
),
# (
# 'first,,third,',
# {'0': 'first,,third,', '1': 'first', '2': None, '3': 'third', '4': None}
# ),
('=foo=', {'0': '=foo=', '1': '=foo='}),
# ('foo=bar', {'0': 'foo=bar', 'foo': 'bar'}),
('foo="bar"', {'0': 'foo="bar"', 'foo': 'bar'}),
(
'height=100,caption="",link="images/octocat.png"',
{
'0': 'height=100,caption="",link="images/octocat.png"',
'height': 100,
'caption': '',
'link': 'images/octocat.png',
},
),
('foo=\'bar\'', {'0': 'foo=\'bar\'', 'foo': 'bar'}),
(
"height=100,caption='',link='images/octocat.png'",
{
'0': "height=100,caption='',link='images/octocat.png'",
'height': 100,
'caption': '',
'link': 'images/octocat.png',
},
),
# ('foo=', {'0': 'foo=', 'foo': ''}),
# ('foo=,bar=baz', {'0': 'foo=,bar=baz', 'foo': '', 'bar': 'baz'}),
# (
# 'first=value, second=two, third=3',
# {
# '0': 'first=value, second=two, third=3',
# 'first': 'value',
# 'second': 'two',
# 'third': '3',
# },
# ),
# (
# 'first=\'value\', second="value two", third=three',
# {
# '0': 'first=\'value\', second="value two", third=three',
# 'first': 'value',
# 'second': 'value two',
# 'third': 'three',
# },
# ),
# (
# " first = 'value', second =\"value two\" , third= three ", # noqa: E501
# {
# '0': " first = 'value', second =\"value two\" , third= three ", # noqa: E501
# 'first': 'value',
# 'second': 'value two',
# 'third': 'three',
# },
# ),
# (
# 'first, second="value two", third=three, Sherlock Holmes',
# {
# '0': 'first, second="value two", third=three, Sherlock Holmes',
# '1': 'first',
# 'second': 'value two',
# 'third': 'three',
# '4': 'Sherlock Holmes',
# },
# ),
# (
# 'first,,third=,,fifth=five',
# {
# '0': 'first,,third=,,fifth=five',
# '1': 'first',
# '2': None,
# 'third': '',
# '4': None,
# 'fifth': 'five',
# },
# ),
)
)
def test_parse_attributes(input, expected):
output = dict()
attrs.parse_attributes(input, output)
assert output == expected
|