forked from google/A2UI
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_convert_docs.py
More file actions
104 lines (84 loc) · 3.14 KB
/
test_convert_docs.py
File metadata and controls
104 lines (84 loc) · 3.14 KB
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
import pytest
from convert_docs import to_mkdocs
# --- 1. A2UI Specific Header Cases ---
ADMONITION_CASES = [
('!!! info "Coming soon..."', "Coming soon...", "ℹ️"),
('!!! warning "Status: Early Stage Public Preview"', "Status: Early Stage Public Preview", "⚠️"),
('!!! success "Stable Release"', "Stable Release", "✅"),
('!!! note "Version Compatibility"', "Version Compatibility", "📝"),
('!!! warning "Attention"', "Attention", "⚠️"),
('!!! tip "It\'s Just JSON"', "It's Just JSON", "💡"),
]
@pytest.mark.parametrize("expected_header, title, emoji", ADMONITION_CASES)
def test_standard_a2ui_conversion(expected_header, title, emoji):
"""Verifies that GitHub style converts to expected A2UI headers."""
body = " Line 1\n Line 2"
github_input = f"> {emoji} **{title}**\n>\n> Line 1\n> Line 2\n"
expected = f"{expected_header}\n{body}\n"
# GitHub -> MkDocs
result = to_mkdocs(github_input)
assert result.strip() == expected.strip()
# --- 2. Empty Title Edge Case ---
def test_empty_title_case():
"""
Verifies '> 💡' converts to !!! tip "".
"""
github_input = "> 💡\n>\n> Content.\n"
expected = '!!! tip ""\n Content.\n'
result = to_mkdocs(github_input)
assert result == expected
# --- 3. Spacing & Internal Paragraph Preservation ---
def test_paragraph_spacing_and_trailing_lines():
"""
Ensures:
1. GitHub spacer (header vs content) is removed in MkDocs.
2. Internal blank lines (paragraph breaks) are preserved.
3. Trailing blockquote markers ('>') are cleaned up.
"""
source_github = (
"> ✅ **Stable Release**\n"
">\n" # Spacer line
"> Line 1\n"
">\n" # Internal break
"> Line 2\n"
">\n" # Trailing line 1
">\n" # Trailing line 2
)
result = to_mkdocs(source_github)
expected = (
'!!! success "Stable Release"\n'
' Line 1\n'
'\n'
' Line 2\n'
)
assert result == expected
# --- 4. Multiple Blocks & Isolation ---
def test_multiple_blocks_in_one_file():
"""Ensures multiple blocks are processed without bleeding into each other."""
github_input = (
'> ✅ **Block 1**\n'
'> Content 1\n'
'\n'
'> ℹ️ **Block 2**\n'
'> Content 2\n'
)
expected = (
'!!! success "Block 1"\n'
' Content 1\n'
'\n'
'!!! info "Block 2"\n'
' Content 2\n'
)
result = to_mkdocs(github_input)
assert result == expected
# --- 5. False Positive Prevention ---
def test_regular_blockquote_ignored():
"""Ensures regular quotes are not touched."""
source = "> This is just a quote, not an admonition."
assert to_mkdocs(source) == source
# --- 6. GitHub Official Alert Syntax Support ---
def test_github_alert_to_mkdocs():
"""Verifies official [!TYPE] syntax conversion."""
source = "> [!WARNING]\n> **Security Notice**\n> Do not share keys."
expected = '!!! warning "Security Notice"\n Do not share keys.\n'
assert to_mkdocs(source) == expected