Skip to content

Add tests for HTML table conversion#24

Merged
leynos merged 5 commits intomainfrom
codex/add-unit-tests-for-convert_html_tables
Jun 14, 2025
Merged

Add tests for HTML table conversion#24
leynos merged 5 commits intomainfrom
codex/add-unit-tests-for-convert_html_tables

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jun 14, 2025

Summary

  • export convert_html_tables
  • test HTML table conversion directly
  • check conversion in plain text and code fences

Testing

  • cargo clippy -- -D warnings
  • cargo test

https://chatgpt.com/codex/tasks/task_e_684cf2fff2a8832286cff24c92bc74f2

Summary by Sourcery

Export the HTML table conversion function and add comprehensive tests to validate its behavior across basic, attribute-rich, colspan, headerless, empty, unclosed, and fenced code scenarios.

New Features:

  • Export the convert_html_tables function for external use.

Tests:

  • Add fixtures for HTML tables with attributes, colspan, no header, empty, and unclosed scenarios.
  • Add unit tests for basic conversion, attribute handling, colspan, headerless tables, empty tables, and unclosed tables.
  • Add parameterized test to verify conversion inside and outside markdown code fences, preserving code fences.

Summary by CodeRabbit

  • New Features

    • The function for converting HTML tables to Markdown is now directly accessible from the library’s main interface.
  • Tests

    • Added tests to verify correct conversion of HTML tables to Markdown, including handling of tables within text and code blocks.

Re-export convert_html_tables so integration tests can call it. Added basic tests exercising HTML conversion and ensuring code fences are ignored.
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jun 14, 2025

Reviewer's Guide

This PR makes the HTML-to-Markdown table converter available publicly and bolsters the test suite with fixtures and integration tests—covering basic, attribute-rich, colspan, header-less, empty and unclosed tables, as well as behavior inside and outside fenced code blocks.

File-Level Changes

Change Details Files
Export HTML table conversion function
  • Made convert_html_tables public in the library API
src/lib.rs
Add HTML table fixtures for edge-case scenarios
  • Created fixtures for colspan tables
  • Created fixtures for tables without headers
  • Created fixtures for empty and unclosed tables
tests/integration.rs
Enhance test suite with various table conversion scenarios
  • Basic conversion test for a simple table
  • Tests for tables with attributes and colspan
  • Tests for header-less, empty, and unclosed tables
tests/integration.rs
Add parameterized tests for code-fenced contexts
  • Use rstest to run conversion inside and outside /~~~ fences
  • Cover both plain and language-annotated fences
tests/integration.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 14, 2025

Warning

Rate limit exceeded

@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 48 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 1a337de and 0977f6c.

📒 Files selected for processing (1)
  • tests/integration.rs (3 hunks)

Walkthrough

This update publicly re-exports the convert_html_tables function from the crate root and introduces two integration tests. The tests verify the function's ability to convert HTML tables to Markdown, both in basic scenarios and when HTML tables are embedded in text or code blocks.

Changes

File(s) Change Summary
src/lib.rs Added pub use html::convert_html_tables; to re-export the function at the crate root.
tests/integration.rs Imported convert_html_tables and added two integration tests for its HTML-to-Markdown conversion.

Sequence Diagram(s)

sequenceDiagram
    participant TestSuite
    participant convert_html_tables
    participant MarkdownOutput

    TestSuite->>convert_html_tables: Provide input (Vec<String>)
    convert_html_tables-->>MarkdownOutput: Process and convert HTML tables
    convert_html_tables-->>TestSuite: Return converted Markdown lines
Loading

Possibly related PRs

Poem

A table of HTML, once so prim,
Now Markdown rows, neat and trim.
With tests to check each subtle case,
And public use, it finds its place.
The rabbit hops with pride anew—
Conversions clear, and code that grew!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @leynos - I've reviewed your changes - here's some feedback:

  • The rstest test_convert_html_table_basic(html_table: Vec<String>) references a fixture html_table that isn’t defined—either provide the input directly or add the fixture definition.
  • I don’t see convert_html_tables being publicly exported in lib.rs, so the integration tests won’t compile—please add the necessary pub use or pub fn export.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The rstest `test_convert_html_table_basic(html_table: Vec<String>)` references a fixture `html_table` that isn’t defined—either provide the input directly or add the fixture definition.
- I don’t see `convert_html_tables` being publicly exported in `lib.rs`, so the integration tests won’t compile—please add the necessary `pub use` or `pub fn` export.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/lib.rs (1)

7-8: Public re-export looks good, but document it for discoverability

Re-exporting convert_html_tables at the crate root is a sensible ergonomic win.
Consider adding a short mention in the module-level docs (//! …) so downstream users spot the new API without diving into the code.

tests/integration.rs (2)

348-359: Prefer String literals for consistency

Most other tests use String values for expected, keeping element types identical to the function return type (Vec<String>).
Switching here avoids the implicit &strString comparison and makes the intent explicit.

-    let expected = vec!["| A | B |", "| --- | --- |", "| 1 | 2 |"];
+    let expected = vec![
+        "| A | B |".to_string(),
+        "| --- | --- |".to_string(),
+        "| 1 | 2 |".to_string(),
+    ];

360-384: Consider covering more fence flavours

This test is great for back-tick fences.
For full coverage add a tilde-based fence variant (~~~) – the helper already supports it and it will hard-fail if future edits accidentally break one flavour.

If you want, I can draft the additional test.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 191c72f and fe7e1e7.

📒 Files selected for processing (2)
  • src/lib.rs (1 hunks)
  • tests/integration.rs (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/lib.rs (1)
src/html.rs (1)
  • convert_html_tables (190-233)
🔇 Additional comments (1)
tests/integration.rs (1)

2-2: Import line is fine

Nothing to add – the newly re-exported item is imported correctly.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 14, 2025

@sourcery-ai review

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @leynos - I've reviewed your changes - here's some feedback:

  • Add tests for tables with HTML attributes (e.g., <table class="..."> or <th colspan="2">) to ensure those attributes are handled or stripped correctly.
  • Add tests for edge cases like empty or malformed tables (e.g., missing header rows or unmatched tags) to validate how convert_html_tables handles them.
  • Add a test for fenced code blocks with language specifiers (e.g., ```rust) to verify that tables inside such blocks are still preserved.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Add tests for tables with HTML attributes (e.g., `<table class="...">` or `<th colspan="2">`) to ensure those attributes are handled or stripped correctly.
- Add tests for edge cases like empty or malformed tables (e.g., missing header rows or unmatched tags) to validate how convert_html_tables handles them.
- Add a test for fenced code blocks with language specifiers (e.g., ```rust) to verify that tables inside such blocks are still preserved.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 14, 2025

@sourcery-ai review

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 14, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 14, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @leynos - I've reviewed your changes - here's some feedback:

  • Add a test using the existing html_table_uppercase fixture to ensure convert_html_tables handles uppercase tags case-insensitively.
  • Reduce duplication in test fixtures by introducing a small helper or macro to build Vec from &str slices.
  • Consider normalizing column counts in colspan scenarios (e.g., duplicating cells for colspan spans) or adding a test to document the current uneven-row behavior.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Add a test using the existing html_table_uppercase fixture to ensure convert_html_tables handles uppercase tags case-insensitively.
- Reduce duplication in test fixtures by introducing a small helper or macro to build Vec<String> from &str slices.
- Consider normalizing column counts in colspan scenarios (e.g., duplicating cells for colspan spans) or adding a test to document the current uneven-row behavior.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 14, 2025

@coderabbitai please create the following github issues:

Add a test using the existing html_table_uppercase fixture to ensure convert_html_tables handles uppercase tags case-insensitively.

Reduce duplication in test fixtures by introducing a small helper or macro to build Vec from &str slices.

Consider normalizing column counts in colspan scenarios (e.g., duplicating cells for colspan spans) or adding a test to document the current uneven-row behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 14, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@leynos I'll create those GitHub issues for you to track these improvements.


🏁 Script executed:

#!/bin/bash
# Create the first GitHub issue about case-insensitive HTML tag handling
gh issue create \
  --title "Add test for case-insensitive HTML tag handling" \
  --body "## Description
Add a test using the existing html_table_uppercase fixture to ensure convert_html_tables handles uppercase tags case-insensitively.

## Context
This improvement was suggested during PR review to ensure robust handling of HTML tables regardless of tag case.

## Acceptance Criteria
- [ ] Add test using html_table_uppercase fixture
- [ ] Verify convert_html_tables processes uppercase HTML tags correctly
- [ ] Ensure case-insensitive handling is documented through tests

## References
- PR: https://github.com/leynos/mdtablefix/pull/24
- Comment: https://github.com/leynos/mdtablefix/pull/24#issuecomment-$(gh api repos/leynos/mdtablefix/pulls/24/comments | jq -r '.[-1].id')" \
  --assignee leynos

# Create the second GitHub issue about reducing test fixture duplication
gh issue create \
  --title "Reduce duplication in test fixtures with helper function" \
  --body "## Description
Reduce duplication in test fixtures by introducing a small helper or macro to build Vec<String> from &str slices.

## Context
Current test fixtures have repetitive patterns when creating Vec<String> from string literals, which could be simplified with a helper function or macro.

## Acceptance Criteria
- [ ] Create helper function or macro for Vec<String> creation from &str slices
- [ ] Refactor existing test fixtures to use the helper
- [ ] Ensure all tests continue to pass after refactoring
- [ ] Document the helper for future test development

## References
- PR: https://github.com/leynos/mdtablefix/pull/24
- Comment: https://github.com/leynos/mdtablefix/pull/24#issuecomment-$(gh api repos/leynos/mdtablefix/pulls/24/comments | jq -r '.[-1].id')" \
  --assignee leynos

# Create the third GitHub issue about colspan handling
gh issue create \
  --title "Improve colspan handling in HTML table conversion" \
  --body "## Description
Consider normalizing column counts in colspan scenarios (e.g., duplicating cells for colspan spans) or adding a test to document the current uneven-row behavior.

## Context
HTML tables with colspan attributes may result in uneven rows in the converted Markdown, which could be improved or at least documented through tests.

## Acceptance Criteria
- [ ] Analyze current behavior with colspan attributes
- [ ] Either implement column count normalization OR add comprehensive tests documenting current behavior
- [ ] If implementing normalization: duplicate cells for colspan spans to maintain consistent column counts
- [ ] If documenting: add tests that clearly show expected behavior for various colspan scenarios

## References
- PR: https://github.com/leynos/mdtablefix/pull/24
- Comment: https://github.com/leynos/mdtablefix/pull/24#issuecomment-$(gh api repos/leynos/mdtablefix/pulls/24/comments | jq -r '.[-1].id')" \
  --assignee leynos

echo "Created 3 GitHub issues for the requested improvements"

Length of output: 2999


Perfect! I've successfully created three GitHub issues for you:

  1. Issue Add test for case-insensitive HTML tag handling #25: Add test for case-insensitive HTML tag handling
  2. Issue Reduce duplication in test fixtures with helper function #26: Reduce duplication in test fixtures with helper function
  3. Issue Improve colspan handling in HTML table conversion #27: Improve colspan handling in HTML table conversion

Each issue includes:

  • Clear descriptions of the requested improvements
  • Context explaining why the changes are needed
  • Acceptance criteria to guide implementation
  • References back to this PR (Add tests for HTML table conversion #24)
  • Assignment to you (@leynos)

The issues are now ready for you to prioritize and work on at your convenience!

🐰
╭─────╮
│ ✓ ✓ ✓ │
╰─────╯
rabbit feeling accomplished after organizing the backlog

@leynos leynos merged commit ae6290b into main Jun 14, 2025
1 check passed
@leynos leynos deleted the codex/add-unit-tests-for-convert_html_tables branch June 14, 2025 15:40
This was referenced Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant