summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py9
-rw-r--r--tests/test_attrs.py178
2 files changed, 120 insertions, 67 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..2091d6f
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,9 @@
+from asciidoc import set_future_compat, set_legacy_compat
+import pytest
+
+
+@pytest.fixture
+def enable_future_compat() -> None:
+ set_future_compat()
+ yield
+ set_legacy_compat()
diff --git a/tests/test_attrs.py b/tests/test_attrs.py
index 9991f7c..c3b90c6 100644
--- a/tests/test_attrs.py
+++ b/tests/test_attrs.py
@@ -2,9 +2,31 @@ from asciidoc import attrs
import pytest
-@pytest.mark.parametrize(
- "input,expected",
- (
+testcases = {
+ # these test cases fail under future mode
+ "pure_legacy": (
+ # In future mode, all values are always strings
+ (
+ 'height=100,caption="",link="images/octocat.png"',
+ {
+ '0': 'height=100,caption="",link="images/octocat.png"',
+ 'height': 100,
+ 'caption': '',
+ 'link': 'images/octocat.png',
+ },
+ ),
+ (
+ "height=100,caption='',link='images/octocat.png'",
+ {
+ '0': "height=100,caption='',link='images/octocat.png'",
+ 'height': 100,
+ 'caption': '',
+ 'link': 'images/octocat.png',
+ },
+ ),
+ ),
+ # these test cases pass under both legacy and future modes
+ "legacy": (
# docstring tests
('', {}),
('hello,world', {'0': 'hello,world', '1': 'hello', '2': 'world'}),
@@ -14,19 +36,13 @@ import pytest
),
# 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',
{
@@ -35,85 +51,113 @@ import pytest
'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'}),
+
+ ('foo=\'bar\'', {'0': 'foo=\'bar\'', 'foo': 'bar'}),
+
+ ),
+ # these tests only pass under future mode
+ # tests taken from
+ # https://github.com/asciidoctor/asciidoctor/blob/main/test/attribute_list_test.rb
+ "future": (
+ ('"ba\"zaar"', {'0': '"ba\"zaar"', '1': 'ba"zaar'}),
+ ('name=\'', {'0': 'name=\'', 'name': '\''}),
+ ('name=\'{val}', {'0': 'name=\'{val}', 'name': '\'{val}'}),
+ ('quote , ', {'0': 'quote , ', '1': 'quote', '2': None}),
+ (', John Smith', {'0': ', John Smith', '1': None, '2': 'John Smith'}),
+ (
+ 'first,,third,',
+ {'0': 'first,,third,', '1': 'first', '2': None, '3': 'third', '4': None}
+ ),
+ ('foo=bar', {'0': 'foo=bar', 'foo': 'bar'}),
+ ('foo=', {'0': 'foo=', 'foo': ''}),
+ ('foo=,bar=baz', {'0': 'foo=,bar=baz', 'foo': '', 'bar': 'baz'}),
(
'height=100,caption="",link="images/octocat.png"',
{
'0': 'height=100,caption="",link="images/octocat.png"',
- 'height': 100,
+ '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,
+ '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',
- # },
- # ),
+ (
+ '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',
+ },
+ ),
)
+}
+
+
+@pytest.mark.parametrize(
+ "input,expected",
+ testcases["legacy"] + testcases["pure_legacy"],
)
def test_parse_attributes(input, expected):
output = dict()
attrs.parse_attributes(input, output)
assert output == expected
+
+
+@pytest.mark.parametrize(
+ "input,expected",
+ testcases['legacy'] + testcases["future"],
+)
+def test_parse_future_attributes(enable_future_compat, input, expected):
+ output = dict()
+ attrs.parse_attributes(input, output)
+ assert output == expected