From 88a0f4aebc3d9c42c813371af815a120a142b540 Mon Sep 17 00:00:00 2001 From: Leynos Date: Sat, 14 Jun 2025 05:03:26 +0100 Subject: [PATCH 1/5] Expose HTML converter Re-export convert_html_tables so integration tests can call it. Added basic tests exercising HTML conversion and ensuring code fences are ignored. --- src/lib.rs | 2 ++ tests/integration.rs | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 0acee547..95598896 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,8 @@ mod html; +pub use html::convert_html_tables; + use regex::Regex; use std::fs; use std::path::Path; diff --git a/tests/integration.rs b/tests/integration.rs index cacc2efc..a7772369 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -1,5 +1,5 @@ use assert_cmd::Command; -use mdtablefix::{process_stream, reflow_table}; +use mdtablefix::{convert_html_tables, process_stream, reflow_table}; use rstest::{fixture, rstest}; use std::fs::File; use std::io::Write; @@ -344,3 +344,35 @@ fn test_non_table_lines_unchanged() { ]; assert_eq!(output, expected); } + +#[rstest] +fn test_convert_html_table_basic(html_table: Vec) { + let expected = vec!["| A | B |", "| --- | --- |", "| 1 | 2 |"]; + assert_eq!(convert_html_tables(&html_table), expected); +} + +#[test] +fn test_convert_html_table_in_text_and_code() { + let lines = vec![ + "Intro".to_string(), + "".to_string(), + "".to_string(), + "".to_string(), + "
AB
12
".to_string(), + "```".to_string(), + "
x
".to_string(), + "```".to_string(), + "Outro".to_string(), + ]; + let expected = vec![ + "Intro".to_string(), + "| A | B |".to_string(), + "| --- | --- |".to_string(), + "| 1 | 2 |".to_string(), + "```".to_string(), + "
x
".to_string(), + "```".to_string(), + "Outro".to_string(), + ]; + assert_eq!(convert_html_tables(&lines), expected); +} From fe7e1e7c57b00779f5270f4ac26c47dbbfc09acc Mon Sep 17 00:00:00 2001 From: Leynos Date: Sat, 14 Jun 2025 12:55:19 +0100 Subject: [PATCH 2/5] Replace fixture in table test --- tests/integration.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index a7772369..e5f57e64 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -345,8 +345,14 @@ fn test_non_table_lines_unchanged() { assert_eq!(output, expected); } -#[rstest] -fn test_convert_html_table_basic(html_table: Vec) { +#[test] +fn test_convert_html_table_basic() { + let html_table = vec![ + "".to_string(), + "".to_string(), + "".to_string(), + "
AB
12
".to_string(), + ]; let expected = vec!["| A | B |", "| --- | --- |", "| 1 | 2 |"]; assert_eq!(convert_html_tables(&html_table), expected); } From 2dbc33cab0d0e717d5552febe678c58ed237ab19 Mon Sep 17 00:00:00 2001 From: Leynos Date: Sat, 14 Jun 2025 15:27:51 +0100 Subject: [PATCH 3/5] Document HTML conversion API --- src/lib.rs | 2 ++ tests/integration.rs | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 95598896..d8200344 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ //! Library for fixing markdown tables. //! //! Functions here reflow tables that were broken during formatting. +//! The [`convert_html_tables`] helper is re-exported at the crate root so +//! callers can convert simple HTML tables before reflowing. mod html; diff --git a/tests/integration.rs b/tests/integration.rs index e5f57e64..844bd56a 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -353,7 +353,11 @@ fn test_convert_html_table_basic() { "12".to_string(), "".to_string(), ]; - let expected = vec!["| A | B |", "| --- | --- |", "| 1 | 2 |"]; + let expected = vec![ + "| A | B |".to_string(), + "| --- | --- |".to_string(), + "| 1 | 2 |".to_string(), + ]; assert_eq!(convert_html_tables(&html_table), expected); } @@ -382,3 +386,29 @@ fn test_convert_html_table_in_text_and_code() { ]; assert_eq!(convert_html_tables(&lines), expected); } + +#[test] +fn test_convert_html_table_in_text_and_code_tilde() { + let lines = vec![ + "Intro".to_string(), + "".to_string(), + "".to_string(), + "".to_string(), + "
AB
12
".to_string(), + "~~~".to_string(), + "
x
".to_string(), + "~~~".to_string(), + "Outro".to_string(), + ]; + let expected = vec![ + "Intro".to_string(), + "| A | B |".to_string(), + "| --- | --- |".to_string(), + "| 1 | 2 |".to_string(), + "~~~".to_string(), + "
x
".to_string(), + "~~~".to_string(), + "Outro".to_string(), + ]; + assert_eq!(convert_html_tables(&lines), expected); +} From 1a337de2f2cbec93d00e4d19b2c29e53eaab1486 Mon Sep 17 00:00:00 2001 From: Leynos Date: Sat, 14 Jun 2025 15:27:58 +0100 Subject: [PATCH 4/5] Parameterize HTML fence test --- tests/integration.rs | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index 844bd56a..c47e78a4 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -361,43 +361,19 @@ fn test_convert_html_table_basic() { assert_eq!(convert_html_tables(&html_table), expected); } -#[test] -fn test_convert_html_table_in_text_and_code() { - let lines = vec![ - "Intro".to_string(), - "".to_string(), - "".to_string(), - "".to_string(), - "
AB
12
".to_string(), - "```".to_string(), - "
x
".to_string(), - "```".to_string(), - "Outro".to_string(), - ]; - let expected = vec![ - "Intro".to_string(), - "| A | B |".to_string(), - "| --- | --- |".to_string(), - "| 1 | 2 |".to_string(), - "```".to_string(), - "
x
".to_string(), - "```".to_string(), - "Outro".to_string(), - ]; - assert_eq!(convert_html_tables(&lines), expected); -} - -#[test] -fn test_convert_html_table_in_text_and_code_tilde() { +#[rstest] +#[case("```")] +#[case("~~~")] +fn test_convert_html_table_in_text_and_code(#[case] fence: &str) { let lines = vec![ "Intro".to_string(), "".to_string(), "".to_string(), "".to_string(), "
AB
12
".to_string(), - "~~~".to_string(), + fence.to_string(), "
x
".to_string(), - "~~~".to_string(), + fence.to_string(), "Outro".to_string(), ]; let expected = vec![ @@ -405,9 +381,9 @@ fn test_convert_html_table_in_text_and_code_tilde() { "| A | B |".to_string(), "| --- | --- |".to_string(), "| 1 | 2 |".to_string(), - "~~~".to_string(), + fence.to_string(), "
x
".to_string(), - "~~~".to_string(), + fence.to_string(), "Outro".to_string(), ]; assert_eq!(convert_html_tables(&lines), expected); From 0977f6ce8623a7f80f833e647d0f2102c2b88e47 Mon Sep 17 00:00:00 2001 From: Leynos Date: Sat, 14 Jun 2025 16:06:24 +0100 Subject: [PATCH 5/5] Add HTML edge case tests --- tests/integration.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/integration.rs b/tests/integration.rs index c47e78a4..5d3f471d 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -83,6 +83,36 @@ fn html_table_with_attrs() -> Vec { ] } +#[fixture] +fn html_table_with_colspan() -> Vec { + vec![ + "".to_string(), + "".to_string(), + "".to_string(), + "
A
12
".to_string(), + ] +} + +#[fixture] +fn html_table_no_header() -> Vec { + vec![ + "".to_string(), + "".to_string(), + "".to_string(), + "
AB
12
".to_string(), + ] +} + +#[fixture] +fn html_table_empty() -> Vec { + vec!["
".to_string()] +} + +#[fixture] +fn html_table_unclosed() -> Vec { + vec!["".to_string(), "".to_string()] +} + #[fixture] fn html_table_uppercase() -> Vec { vec![ @@ -364,6 +394,7 @@ fn test_convert_html_table_basic() { #[rstest] #[case("```")] #[case("~~~")] +#[case("```rust")] fn test_convert_html_table_in_text_and_code(#[case] fence: &str) { let lines = vec![ "Intro".to_string(), @@ -388,3 +419,32 @@ fn test_convert_html_table_in_text_and_code(#[case] fence: &str) { ]; assert_eq!(convert_html_tables(&lines), expected); } + +#[test] +fn test_convert_html_table_with_attrs_basic() { + let expected = vec!["| A | B |", "| --- | --- |", "| 1 | 2 |"]; + assert_eq!(convert_html_tables(&html_table_with_attrs()), expected); +} + +#[test] +fn test_convert_html_table_with_colspan() { + let expected = vec!["| A |", "| --- |", "| 1 | 2 |"]; + assert_eq!(convert_html_tables(&html_table_with_colspan()), expected); +} + +#[test] +fn test_convert_html_table_no_header() { + let expected = vec!["| A | B |", "| 1 | 2 |"]; + assert_eq!(convert_html_tables(&html_table_no_header()), expected); +} + +#[test] +fn test_convert_html_table_empty() { + assert!(convert_html_tables(&html_table_empty()).is_empty()); +} + +#[test] +fn test_convert_html_table_unclosed_returns_original() { + let html = html_table_unclosed(); + assert_eq!(convert_html_tables(&html), html); +}
1