"""Test cases for Details."""
from .. import util
class TestFancyLists(util.MdCase):
"""Test fancy lists."""
extension = ['pymdownx.fancylists', 'pymdownx.saneheaders']
extension_configs = {}
def test_fail_case(self):
"""Test failed case."""
self.check_markdown(
"""
1. foo
. bar
1) foo
) bar
""",
"""
- foo
. bar
- foo
) bar
""",
True
)
def test_unordered(self):
"""Test unordered lists."""
self.check_markdown(
R'''
- item 1
* item 2
+ item 3
''',
r'''
''',
True
)
def test_ordered(self):
"""Test ordered lists."""
self.check_markdown(
R'''
1. item 1
2. item 2
3. item 3
''',
r'''
- item 1
- item 2
- item 3
''',
True
)
def test_ordered_paren(self):
"""Test ordered lists with parenthesis."""
self.check_markdown(
R'''
1) item 1
2) item 2
3) item 3
''',
r'''
- item 1
- item 2
- item 3
''',
True
)
def test_ordered_generic(self):
"""Test generic ordered list."""
self.check_markdown(
R'''
#. item 1
#. item 2
#. item 3
''',
r'''
- item 1
- item 2
- item 3
''',
True
)
def test_ordered_generic_paren(self):
"""Test generic ordered list with parenthesis."""
self.check_markdown(
R'''
#) item 1
#) item 2
#) item 3
''',
r'''
- item 1
- item 2
- item 3
''',
True
)
def test_ordered_generic_switch(self):
"""Test generic ordered list switching over to other style."""
self.check_markdown(
R'''
#. item 1
#. item 2
#) item 1
#) item 2
''',
r'''
- item 1
- item 2
- item 1
- item 2
''',
True
)
def test_ordered_generic_inherit(self):
"""Test generic ordered list inheritance."""
self.check_markdown(
R'''
i. item i
#. item ii
#. item iii
I. New list
''',
r'''
- item i
- item ii
- item iii
- New list
''',
True
)
def test_ordered_generic_inherit_no_change(self):
"""Test generic ordered list inheritance no new list if same type."""
self.check_markdown(
R'''
i. item i
#. item ii
#. item iii
iv. item iv
''',
r'''
- item i
- item ii
- item iii
- item iv
''',
True
)
def test_roman(self):
"""Test Roman numeral lists."""
self.check_markdown(
R'''
i. item 1
ii. item 2
iii. item 3
iv. item 4
v. item 5
vi. item 6
''',
r'''
- item 1
- item 2
- item 3
- item 4
- item 5
- item 6
''',
True
)
def test_roman_paren(self):
"""Test Roman numeral lists with parenthesis."""
self.check_markdown(
R'''
i) item 1
ii) item 2
iii) item 3
''',
r'''
- item 1
- item 2
- item 3
''',
True
)
def test_roman_upper(self):
"""Test Roman numeral uppercase lists."""
self.check_markdown(
R'''
I. item 1
II. item 2
III. item 3
''',
r'''
- item 1
- item 2
- item 3
''',
True
)
def test_roman_upper_paren(self):
"""Test Roman numeral uppercase lists with parenthesis."""
self.check_markdown(
R'''
I) item 1
II) item 2
III) item 3
''',
r'''
- item 1
- item 2
- item 3
''',
True
)
def test_alpha(self):
"""Test alphabetical lists."""
self.check_markdown(
R'''
a. item 1
b. item 2
c. item 3
''',
r'''
- item 1
- item 2
- item 3
''',
True
)
def test_alpha_paren(self):
"""Test alphabetical lists with parenthesis."""
self.check_markdown(
R'''
a) item 1
b) item 2
c) item 3
''',
r'''
- item 1
- item 2
- item 3
''',
True
)
def test_alpha_upper(self):
"""Test alphabetical uppercase lists."""
self.check_markdown(
R'''
A. item 1
B. item 2
C. item 3
''',
r'''
- item 1
- item 2
- item 3
''',
True
)
def test_alpha_upper_paren(self):
"""Test alphabetical uppercase lists with parenthesis."""
self.check_markdown(
R'''
A) item 1
B) item 2
C) item 3
''',
r'''
- item 1
- item 2
- item 3
''',
True
)
def test_alpha_two_spaces(self):
"""Test alphabetical two space uppercase requirement."""
self.check_markdown(
R'''
A. item 1
A. item 2
''',
R'''
- item 1
A. item 2
''',
True
)
def test_roman_alpha(self):
"""Test behavior of alphabetical and Roman numeral."""
self.check_markdown(
R'''
v) item 1
a) item 2
i. item 1
a. item 1
b. item 2
''',
r'''
- item 1
- item 2
- item 1
- item 1
- item 2
''',
True
)
def test_bad_roman(self):
"""Test bad Roman numeral."""
self.check_markdown(
R'''
iviv. item 1
''',
R'''
iviv. item 1
''',
True
)
def test_roman_start(self):
"""Test bad Roman numeral."""
self.check_markdown(
R'''
iv. item 1
v. item 2
''',
R'''
- item 1
- item 2
''',
True
)
def test_roman_two_spaces(self):
"""Test Roman numeral two space uppercase requirement."""
self.check_markdown(
R'''
I. item 1
I. item 2
''',
R'''
- item 1
I. item 2
''',
True
)
def test_roman_relaxed(self):
"""Test cases related to our less strict approach."""
self.check_markdown(
R'''
iiii. item 1
MCCCCCCVI. item 1
''',
R'''
- item 1
- item 1
''',
True
)
def test_list_nested_same_line(self):
"""Test list nested on same line."""
self.check_markdown(
R'''
a) a) subitem1
b) subitem2
''',
R'''
-
- subitem1
- subitem2
''',
True
)
def test_indented_content(self):
"""Test indented content."""
self.check_markdown(
R'''
#. A paragraph
that is short.
Another paragraph.
#. A sublist
Another paragraph.
#. A new list item.
''',
R'''
-
A paragraph
that is short.
Another paragraph.
- A sublist
Another paragraph.
-
A new list item.
''',
True
)
def test_unindented_content(self):
"""Test indented content with unindented lines."""
self.check_markdown(
R'''
#. A paragraph
that is short.
Another paragraph
with unindented lines.
#. A sublist
with unindented lines.
#. A new list item.
''',
R'''
-
A paragraph
that is short.
Another paragraph
with unindented lines.
- A sublist
with unindented lines.
-
A new list item.
''',
True
)
def test_header_case(self):
"""Test case where list follows header."""
self.check_markdown(
R'''
Tight List:
* # Header1
Line 1-2 - **not** a header *or* paragraph!
* # Header2
Line 2-2 - not a header or paragraph!
Loose List:
* # Header1
Line 1-2 - *a* paragraph
* # Header2
Line 2-2 - a paragraph
''',
R'''
Tight List:
-
Header1
Line 1-2 - not a header or paragraph!
-
Header2
Line 2-2 - not a header or paragraph!
Loose List:
-
Header1
Line 1-2 - a paragraph
-
Header2
Line 2-2 - a paragraph
''',
True
)
def test_mixed_nesting_case(self):
"""Test mixed nesting case."""
self.check_markdown(
R'''
* item 1
* item 1-1
* item 1-2
* item 1-2-1
* item 2
* item 3
* item 4
* item 4-1
* item 4-2
* item 4-3
Paragraph under item 4-3
Paragraph under item 4
''',
R'''
- item 1
- item 2
- item 3
-
item 4
- item 4-1
- item 4-2
-
item 4-3
Paragraph under item 4-3
Paragraph under item 4
''',
True
)
def test_tight_loose_mix(self):
"""Test inconsistent loose and tight list item spacing."""
self.check_markdown(
R'''
* item 1
* item 2
* item 3
* item 4
''',
R'''
- item 1
-
item 2
-
item 3
- item 4
''',
True
)
def test_roman_mitigation(self):
"""Test mitigation for conflict case with alphabetical lists."""
self.check_markdown(
R'''
IIIII. Roman numeral V
---
VIIIII. Roman numeral X
---
XXXXX. Roman numeral L
---
LXXXXX. Roman numeral C
---
CCCCC. Roman numeral D
---
DCCCCC. Roman numeral M
/// fancylists | start=5 type=I
V. Alternate work around
///
''',
R'''
- Roman numeral V
- Roman numeral X
- Roman numeral L
- Roman numeral C
- Roman numeral D
- Roman numeral M
- Alternate work around
''',
True
)
def test_alpha_mitigation_start(self):
"""Test mitigation for conflict case with Roman numeral lists with explicit start."""
self.check_markdown(
R'''
/// fancylists | start=3 type=a
i. Workaround
j. Workaround
///
''',
R'''
- Workaround
- Workaround
''',
True
)
def test_alpha_mitigation(self):
"""Test mitigation for conflict case with Roman numeral lists with explicit start."""
self.check_markdown(
R'''
/// fancylists | type=a
i. Workaround
j. Workaround
///
/// fancylists | type=a
i) Workaround
j) Workaround
///
''',
R'''
- Workaround
- Workaround
- Workaround
- Workaround
''',
True
)
def test_alpha_mitigation_switch(self):
"""Test mitigation for conflict case with Roman numeral lists."""
self.check_markdown(
R'''
/// fancylists | type=a
i. Workaround
j) Workaround
///
''',
R'''
- Workaround
- Workaround
''',
True
)
def test_alpha_mitigation_complex(self):
"""Test mitigation for complex conflict case with Roman numeral lists."""
self.check_markdown(
R'''
/// fancylists | type=a
i. Workaround
Workaround
j. Workaround
///
''',
R'''
-
Workaround
Workaround
-
Workaround
''',
True
)
def test_alpha_mitigation_ul_ignored(self):
"""Test that mitigation won't target unordered lists."""
self.check_markdown(
R'''
/// fancylists | type=a
- Workaround
Workaround
- Workaround
///
''',
R'''
-
Workaround
Workaround
-
Workaround
''',
True
)
def test_alpha_mitigation_generic(self):
"""Test that mitigation works on generic."""
self.check_markdown(
R'''
/// fancylists | start=9 type=a
#. Workaround
Workaround
#. Workaround
///
''',
R'''
-
Workaround
Workaround
-
Workaround
''',
True
)
def test_alpha_mitigation_generic_no_start(self):
"""Test that mitigation works on generic with no start."""
self.check_markdown(
R'''
/// fancylists | type=a
#. Workaround
Workaround
#. Workaround
///
''',
R'''
-
Workaround
Workaround
-
Workaround
''',
True
)
def test_mitigation_no_force_alpha(self):
"""Test case that can't be forced."""
self.check_markdown(
R'''
/// fancylists | type=a
1. Can't force
///
''',
R'''
- Can't force
''',
True
)
def test_mitigation_bad_type(self):
"""Test bad type in mitigation."""
self.check_markdown(
R'''
/// fancylists | type=j
1. Can't force
///
''',
R'''
/// fancylists | type=j
- Can't force
///
''',
True
)
def test_mitigation_no_type(self):
"""Test no type in mitigation."""
self.check_markdown(
R'''
/// fancylists |
a. Can't force
///
''',
R'''
/// fancylists |
- Can't force
///
''',
True
)
def test_mitigation_only_start(self):
"""Test no type in mitigation."""
self.check_markdown(
R'''
/// fancylists | start=5
a. item 5
///
''',
R'''
- item 5
''',
True
)
class TestFancyListsStyle(util.MdCase):
"""Test fancy lists."""
extension = ['pymdownx.fancylists', 'pymdownx.saneheaders']
extension_configs = {
'pymdownx.fancylists': {
'inject_style': True
}
}
def test_inject_style(self):
"""Test injecting styles."""
self.check_markdown(
R'''
i. Item i
''',
R'''
- Item i
''',
True
)
def test_inject_style_force(self):
"""Test injecting styles in forced lists."""
self.check_markdown(
R'''
/// fancylists | type=i
v. Item v
///
''',
R'''
- Item v
''',
True
)
class TestFancyListsClass(util.MdCase):
"""Test fancy lists."""
extension = ['pymdownx.fancylists', 'pymdownx.saneheaders']
extension_configs = {
'pymdownx.fancylists': {
'inject_class': True
}
}
def test_inject_class(self):
"""Test injecting class."""
self.check_markdown(
R'''
i. Item i
''',
R'''
- Item i
''',
True
)
def test_inject_class_force(self):
"""Test injecting class in forced lists."""
self.check_markdown(
R'''
/// fancylists | type=i
v. Item v
///
''',
R'''
- Item v
''',
True
)
class TestFancyListsDisableAlpha(util.MdCase):
"""Test fancy lists."""
extension = ['pymdownx.fancylists', 'pymdownx.saneheaders']
extension_configs = {
'pymdownx.fancylists': {
'additional_ordered_styles': ['roman', 'generic']
}
}
def test_no_alpha(self):
"""Test lists when alphabetical lists is disabled."""
self.check_markdown(
R'''
i. item 1
ii. item 2
a. item 1
V. item 1
''',
R'''
- item 1
- item 2
a. item 1
- item 1
''',
True
)
def test_no_alpha_force(self):
"""Test attempting to force alphabetical when they are disabled."""
self.check_markdown(
R'''
/// fancylists | type=a
i. item 1
j. item 2
///
''',
R'''
/// fancylists | type=a
- item 1
j. item 2
///
''',
True
)
class TestFancyListsDisableRoman(util.MdCase):
"""Test fancy lists."""
extension = ['pymdownx.fancylists', 'pymdownx.saneheaders']
extension_configs = {
'pymdownx.fancylists': {
'additional_ordered_styles': ['alpha', 'generic']
}
}
def test_no_roman(self):
"""Test lists when Roman numerals lists is disabled."""
self.check_markdown(
R'''
i. item 1
ii. item 2
a. item 2
V. item 1
''',
R'''
-
item 1
ii. item 2
-
item 2
- item 1
''',
True
)
def test_no_roman_force(self):
"""Test attempting to force Roman numerals when they are disabled."""
self.check_markdown(
R'''
/// fancylists | type=i
v. item 1
vi. item 2
///
''',
R'''
/// fancylists | type=i
- item 1
vi. item 2
///
''',
True
)