Files
wehub-resource-sync b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:56:03 +08:00

138 lines
4.2 KiB
Python

"""Shared GFM table → bullet conversion helpers."""
from gateway.platforms.helpers import (
TABLE_SEPARATOR_RE,
is_table_row,
split_markdown_table_row,
convert_table_to_bullets,
)
class TestTablePrimitives:
def test_separator_re_matches_basic(self):
assert TABLE_SEPARATOR_RE.match("|---|---|")
def test_separator_re_matches_alignment(self):
assert TABLE_SEPARATOR_RE.match("|:-----|----:|:----:|")
def test_separator_re_rejects_lone_rule(self):
assert not TABLE_SEPARATOR_RE.match("---")
def test_is_table_row_with_pipe(self):
assert is_table_row("| Alice | 150 |")
def test_is_table_row_blank(self):
assert not is_table_row("")
def test_split_row_strips_outer_pipes(self):
assert split_markdown_table_row("| a | b | c |") == ["a", "b", "c"]
def test_split_row_no_outer_pipes(self):
assert split_markdown_table_row("a | b | c") == ["a", "b", "c"]
class TestConvertTableToBullets:
def test_basic_table(self):
text = (
"| Player | Score |\n"
"|--------|-------|\n"
"| Alice | 150 |\n"
"| Bob | 120 |"
)
out = convert_table_to_bullets(text)
assert "**Alice**" in out
assert "• Score: 150" in out
assert "**Bob**" in out
assert "• Score: 120" in out
assert "• Player: Alice" not in out
def test_three_column_table(self):
text = (
"| Name | Age | City |\n"
"|:-----|----:|:----:|\n"
"| Ada | 30 | NYC |"
)
out = convert_table_to_bullets(text)
assert "**Ada**" in out
assert "• Name: Ada" not in out
assert "• Age: 30" in out
assert "• City: NYC" in out
assert "**Ada**\n• Age: 30\n• City: NYC" in out
def test_row_label_column(self):
text = (
"| | Score | Rank |\n"
"|--------|-------|------|\n"
"| Alice | 150 | 1 |\n"
"| Bob | 120 | 2 |"
)
out = convert_table_to_bullets(text)
assert "**Alice**" in out
assert "• Score: 150" in out
assert "• Rank: 1" in out
assert "**Alice**\n• Score: 150\n• Rank: 1" in out
def test_bare_pipe_table(self):
text = "head1 | head2\n--- | ---\na | b\nc | d"
out = convert_table_to_bullets(text)
assert "**a**" in out
assert "• head1: a" not in out
assert "• head2: b" in out
def test_two_consecutive_tables(self):
text = (
"| A | B |\n"
"|---|---|\n"
"| 1 | 2 |\n"
"\n"
"| X | Y |\n"
"|---|---|\n"
"| 9 | 8 |"
)
out = convert_table_to_bullets(text)
assert out.count("**1**") == 1
assert out.count("**9**") == 1
assert "• B: 2" in out
assert "• Y: 8" in out
def test_surrounding_prose_preserved(self):
text = (
"Scores:\n\n"
"| Player | Score |\n"
"|--------|-------|\n"
"| Alice | 150 |\n"
"\nEnd."
)
out = convert_table_to_bullets(text)
assert out.startswith("Scores:")
assert out.endswith("End.")
def test_table_inside_code_fence_untouched(self):
text = "```\n| a | b |\n|---|---|\n| 1 | 2 |\n```"
assert convert_table_to_bullets(text) == text
def test_plain_text_with_pipes_untouched(self):
text = "Use the | pipe operator to chain."
assert convert_table_to_bullets(text) == text
def test_horizontal_rule_not_matched(self):
text = "Section A\n\n---\n\nSection B"
assert convert_table_to_bullets(text) == text
def test_no_pipe_short_circuits(self):
text = "Plain **bold** text."
assert convert_table_to_bullets(text) == text
def test_row_groups_separated_by_blank_line(self):
text = (
"| A | B |\n"
"|---|---|\n"
"| x | 1 |\n"
"| y | 2 |"
)
out = convert_table_to_bullets(text)
assert "• B: 1\n\n**y**" in out
assert "\n\n• " not in out